Oracle学习笔记(四)DCL和Transaction
1.delete和truncate的区别:
?
1.添加列 SQL> create table test( 2 tid int primary key, 3 tname varchar(23) 4 ); SQL> alter table test add tage int;表已更改。SQL> alter table test add tsex varchar(2) check (tsex in('男','女'));表已更改。SQL> desc test; 名称 是否为空? 类型 ----------------------------------------- -------- ------------------ TID NOT NULL NUMBER(38) TNAME VARCHAR2(23) TAGE NUMBER(38) TSEX VARCHAR2(2)2.修改列 SQL> alter table test modify tsex varchar(2) default '男' check (tsex in('男','女'));表已更改。SQL> insert into test(tid) values(23423);已创建 1 行。SQL> select * from test; TID TNAME TAGE TS---------- ----------------------- ---------- -- 23423 男3.删除列SQL> alter table test drop column tsex;表已更改。SQL> desc test; 名称 是否为空? 类型 ----------------------------------------- -------- ------------- TID NOT NULL NUMBER(38) TNAME VARCHAR2(23) TAGE NUMBER(38)4.添加NOT NULL约束,使用alter。。。。modified,不能使用alter....add constraint。 alter table student name not null;5.添加/删除约束 alter table student add/drop constraint student_pk primary key (sid);6.禁止/允许约束的使用 alter table student disable/enable constraint student_pk;7.修改表名 rename <table_old_name> to <table_new_name>; 8.修改索引名称 alter index <index_old_name> rename to <index_new_name>;?