sql 修改表小节

列名重命名:
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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值