sql 修改表小节

来源:互联网 发布:淘宝上能买到真蜂蜜吗 编辑:程序博客网 时间:2024/05/17 06:36

列名重命名:
alter table L_TEST rename column ID(oldName) to userID(newName);

添加列:
alter table L_TEST
add (
columnName type
);

修改列:
alter table L_TEST
modify(
columnName type|default null
);


删除列:
alter table L_TEST
drop column (columnNames)
cascade constraints;

 

通过查询从一个表创建另一个表:
create table tablename as select <query>

只创建表,而不复制数据。
create table new_emp as
select * from emp where 1=2;

 

删除表的字段的原有约束

alter table 表名 drop constraint 约束名字

添加一个表的字段的约束并指定默认值

alter table 表名 add constraint 约束名字 DEFAULT 默认值 for 字段名称

创建约束之前检查已有数据 

alter table with check T_ping add constraint DF_T_ping_p_c DEFAULT ((2)) for p_c

直接创建不检查已有数据是否符合约束

alter table with nocheck T_ping add constraint DF_T_ping_p_c DEFAULT ((2)) for p_c

 

原创粉丝点击