目录
其他:........................................................................................................................ 8
约束:
alter table test modify aaa not null; 为test表aaa字段创建非空约束。注意:如果表已经有数据,并且该列有 NULL 值,非空的约束我们是无法添加的。
alter table test modify aaa null;删除非空约束
alter table test modify aaa default ‘贵阳’; 修改表test列aaa的默认值为贵阳
alter table test alter aaa drop default; 删掉默认设置
alter table test add constraint qwe unique (aaa);为test表aaa字段创建唯一约束qwe。
alter table test add constraint qwe primary key (aaa);
alter table test add constraint qwe primary key (aaa,bbb); 同时添加2个主键,一个一个添加的时候会报错。
alter table test add constraint qwe check(aaa>3);
alter table test add constraint qwe foreign key (aaa) references test2(eee); 外键约束,一个表可以有多个外键,外键是另外一张表的主键,同时外键列的内容必须包含在另外一张表主键列的内容中。我们也可以在创建表时指定。
alter table test disable constraint qwe; 禁用约束qwe
alter table test enable constraint qwe; 启用约束qwe
select * from dba_constraints;
alter table test drop constraint qwe;
当drop或delete某张表失败提示锁超时时,select * from v$lock 查看被锁事务的TRX_ID,再select * from v$sessions,根据TRX_ID查找该事务对应的SESS_ID,最后 sp_colse_session(找到的SESS_ID)关闭对应的会话。
视图:
create view test as select……创建视图
create or replace view test as ……修改视图
索引:
create unique index qwe on test(aaa);创建唯一索引
create bitmap index qwe on test(aaa);创建位图索引
create cluster indx qwe on test(aaa);创建聚集索引
位图索引与聚集索引不能在一张表上
select * from dba_indexes where table_name like ‘TEST’;查询表test的索引,注意是index后面加es,而不是加s
drop index qwe;
表空间及数据文件:
在 DM 数据库中,表空间由一个或者多个数据文件组成。DM 数据库中的所有对象在逻辑上都存放在表空间中,而物理上都存储在所属表空间的数据文件中。
create tablespace test datafile '/home/dmdba/dmdbms/data/DAMENG/test.dbf' size 1024 autoextend on next 4 maxsize unlimited;
alter tablespace test resize datafile '/home/dmdba/dmdbms/data/DAMENG/test.dbf' to 1025;
alter tablespace test add datafile '/home/dmdba/dmdbms/data/DAMENG/test.dbf' size 1024;