目录
1、添加主键
有主键名:
alter table test(test表名) add constraint pk_test(pk_test为主键名) primary key(主键1,主键2,...)
无主键名:
alter table test(test为表名) add primary key(主键1,主键2,...)
2、删除主键
有主键名:
alter table test(test为表名) drop constraint pk_test(pk_test为主键名)
无主键名:
--找到主键名
select * from user_cons_columns o where o.table_name = 'test' and o.position is not null;
--删除主键
alter table test(test为表名) drop constraint 主键名;
3、添加列
alter table test(test为表名) add 字段名 字段类型(类型长度);
--举例
alter table test add name varchar2(10);
--添加字段注释
comment on column 表名.字段名 is '注释';
--举例
comment on column test.name is '姓名';
4、修改列
--修改列名
alter table test(test为表名) rename column 旧字段名 to 新字段名
--修改字段类型/字段长度
alter table test(test为表名) modify 字段名称 字段类型(字段长度);
5、删除列
alter table test(test为表名) drop column 字段名;
6、修改表名
alter table 旧表名 rename to 新表名
--添加表注释
commment on table test(test为表名) is '注释';
如有错误,评论区请指正