Oracle数据表创建、查询、约束等操作

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 约束名;

 

posted @ 2018-04-05 16:55  菜头与白菜  阅读(308)  评论(0编辑  收藏  举报