sql 基本操作

sql 基本操作

数据库表的操作
SQL code
 
     
-- ----------------------------列操作----------------------------------- -- 添加列 ALTER TABLE t ADD Mycolumn int identity ( 1 , 1 ) ||not null default ( 0 ) -- 删除列 alter table t drop column Mycolumn -- 修改列 alter table t alter column Mycolumn varchar ( 20 ) not null -- 将表中的数据改为为小数 update t set groups = cast (groups as DECIMAL ( 10 , 3 )) -- 将表字段的类型更改小数 alter table t alter column Yourcolumn DECIMAL ( 10 , 3 )) -- ----------------------------约束操作---------------------------------- -- 加约束(默认值) Alter table t Add constraint C_Mycolumn default ( 30 ) for Mycolumn -- 加约束(check条件) alter table dbo.t add constraint ck_t check ( ' 字段 ' <> ' 字段 ' ) alter table t with nocheck add constraint t_sex check ( [ name ] in (N ' ' ,N ' ' )) -- 加约束(主键) alter table t add constraint t_id primary key (id) -- 删除约束 alter table t drop constraint [ DF_t_Mycolumn ] -- 加列加约束(默认值) alter table t add Mycolumn int CONSTRAINT [ DF_t_Mycolumn ] not null default ( 0 )

转载于:https://www.cnblogs.com/zhangzheny/archive/2008/01/14/1037736.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值