1. 程式人生 > >Oracle數據表創建、查詢、約束等操作

Oracle數據表創建、查詢、約束等操作

oracle 創建表 gpo var stun enable enc 創建 主鍵

1、創建表、刪除表、復制表

create table stuInfo ——創建學員信息表

stuNo char(6) not null

stuName varchar(2) not nul,

stuAge number(3,0) not null

新建一張表復制學員信息表則是:create table stuInfo2 as select * from stuInfo;

刪除表:1、drop table 表 2、truncate 表;

2對表結構的查詢:desc 表名;

3、改表名:alter table old表名 rename to new表名;

增加列:alter table 表 add(列名 類型,列名 類型);

修改列:alter table 表 modify (列名 類型,列名 類型);

刪除一列:alter table 表 drop column 列名; 刪除多列:alter table 表 drop(列1,列2);

4、向表中添加約束,emp表的deptno作為外鍵引用dept表的deptno

alter table emp add constraint pk_test foreign KEY(deptno) references dept(deptno);

5、向表中添加主鍵約束

alter table emp add constraint pk_emp_deptno primary key(deptno);

6、刪除約束:

alter table emp drop constraint pk_emp_deptno;

7、禁用和啟用約束:

alter table 表 Dsable||Enable constraint 約束名;

Oracle數據表創建、查詢、約束等操作