------------------添加字段(可以单个,也可以多个)
alter table 表名 add ( 列名 );
------------------修改字段
alter table 表名 modify( 列名 );
------------------删除字段
alter table 表名 drop column 列名 ;
------------------添加主键
alter table 表名 add constraint PK_约束名 primary key ( 列名 );
------------------添加外键
alter table 表名 add constraint FK_ 约束名 foreign key( 外键列名 )
references 外表名 (列名);
------------------删除外键
alter table 表名 drop constraint 约束名;
------------------添加唯一约束(可以单列,也可以多列)
alter table 表名 add constraint UNIQUE_约束名 unique ( 列名 );
------------------添加条件约束
alter table 表名 add constraint CHECK_约束名 check
( 列名 in('1','2'));
------------------删除约束
alter table 表名 drop constraint 约束名 ;
------------------启用/禁用约束
alter table 表名 enable/disable constraint 约束名 ;
------------------------查询
select
constraint_name,--约束名称
constraint_type,--约束类型
table_name,--约束所在的表
search_condition,--约束表达式
status--是否启用
from user_constraints--[all_constraints|dba_constraints]
where constraint_name=' 约束名 ';
------------------创建索引
create index 索引名称 on 表名(列名);
------------------得到指定表的索引创建语句
select 'create index INDEX_' || a.table_name || '_' || b.COLUMN_NAME ||
' on ' || a.table_name || ' (' || b.COLUMN_NAME || ');'
from user_indexes a, user_ind_columns b
where a.index_name = b.INDEX_NAME
and a.table_name = '表名';
------------------得到指定表的主键创建语句
select 'alter table ' || a.table_name || ' add constraint PK_' ||
a.table_name || '_' || a.column_name ||' primary key (' || a.column_name || ');'
from user_cons_columns a, user_constraints b
where a.constraint_name = b.constraint_name
and b.constraint_type = 'P'
and a.table_name = ' 表名';