Oracle DDL基本操作
2015-06-30 20:11
393 查看
和大家分享一下我在Oracle数据库定义语言的学习笔记
1、创建表空间语法
create tablespace test --表空间名称
datafile ‘D:\oradata\orcl\test.dbf’ --表空间对应的数据文件
size 32m --初始大小
autoextend on; --自动增长打开
2、删除表空间语法
drop tablespace test
including contents and datafiles;
including contents and datafiles
表示删除表空间的内容和对应的数据文件
3、为用户指定默认表空间语法:
create user 用户名 identified by 密码
default tablespace 表空间名;
4、创建表语法:
create table student(
sid number(4), --学号
sname varchar2(20), --姓名
sex char(2), --性别
birthday date, --生日
sal number(7,2) --奖学金
);
5、删除表语法:
drop table student;
6、修改表 alter table
增加一列
alter table 表名 add (列名 类型);
修改字段的长度
alter table 表名 modify (列名 类型);
删除一列
alter table 表名 drop column 列名;
修改表的名字
rename 旧表名 to 新表名;
查看表结构
desc 表名;(注意:此命令局限于命令窗口)
7、约束 constraint :保证数据的完整性,避免非法数据。
主键约束 primary key
外键约束 foreign key
检查约束 check
是否为空 null | not null
默认值 default
添加约束语法:
alter table 表名
add constraint 约束名 约束类型 约束条件;
8、删除约束语法:
alter table 表名
drop constraint 约束名;
9、主键约束
alter table 表名
add constraint 约束名 primary key(列名);
10、外键约束
alter table 表名
add constraint 约束名 foreign key(外键列)
references 主表名(主键列);
11、检查约束
alter table 表名
add constraint 约束名 check(检查条件);
12、删除约束
alter table 表名
drop constraint 约束名;
13、非空约束
alter table 表名
modify 列名 not null;
14、默认约束
alter table 表名
modify 列名 default 默认值;
15、复制表:利用现有表创建新表
CREATE TABLE <table_name>
as <SELECT 语句>; (注意:复制表不能复制表的约束)
1、创建表空间语法
create tablespace test --表空间名称
datafile ‘D:\oradata\orcl\test.dbf’ --表空间对应的数据文件
size 32m --初始大小
autoextend on; --自动增长打开
2、删除表空间语法
drop tablespace test
including contents and datafiles;
including contents and datafiles
表示删除表空间的内容和对应的数据文件
3、为用户指定默认表空间语法:
create user 用户名 identified by 密码
default tablespace 表空间名;
4、创建表语法:
create table student(
sid number(4), --学号
sname varchar2(20), --姓名
sex char(2), --性别
birthday date, --生日
sal number(7,2) --奖学金
);
5、删除表语法:
drop table student;
6、修改表 alter table
增加一列
alter table 表名 add (列名 类型);
修改字段的长度
alter table 表名 modify (列名 类型);
删除一列
alter table 表名 drop column 列名;
修改表的名字
rename 旧表名 to 新表名;
查看表结构
desc 表名;(注意:此命令局限于命令窗口)
7、约束 constraint :保证数据的完整性,避免非法数据。
主键约束 primary key
外键约束 foreign key
检查约束 check
是否为空 null | not null
默认值 default
添加约束语法:
alter table 表名
add constraint 约束名 约束类型 约束条件;
8、删除约束语法:
alter table 表名
drop constraint 约束名;
9、主键约束
alter table 表名
add constraint 约束名 primary key(列名);
10、外键约束
alter table 表名
add constraint 约束名 foreign key(外键列)
references 主表名(主键列);
11、检查约束
alter table 表名
add constraint 约束名 check(检查条件);
12、删除约束
alter table 表名
drop constraint 约束名;
13、非空约束
alter table 表名
modify 列名 not null;
14、默认约束
alter table 表名
modify 列名 default 默认值;
15、复制表:利用现有表创建新表
CREATE TABLE <table_name>
as <SELECT 语句>; (注意:复制表不能复制表的约束)
相关文章推荐
- Android之获取手机上的图片和视频缩略图thumbnails
- 基于 Red Hat 的发行版 Oracle Linux 正式发布Oracle Linux 7.1
- SQL中的三值逻辑
- 数据库链接字符串查询网站
- SQL Server 作业批量停止
- 结束SQL阻塞的进程
- 动态生成SQL Server视图作业
- Oracle Containers for J2EE远程安全漏洞(CVE-2014-0413)
- Oracle 10g R2不能使用EM的问题
- SQL Server 语句操纵数据库
- 表空间操作
- PreparedStatement中in子句的处理
- SQL(结构化查询语句)
- 你应该学习哪种编程语言?
- VMware下RedHat4.8_64位安装Oracle 10g RAC--简略脚本
- oracle sql日期比较