如何使用SQL语句修改字段默认值

如题所述

alter table 表名 drop constraint 约束名字说明:删除表的字段的原有约束alter table 表名 add constraint 约束名字 DEFAULT 默认值 for 字段名称说明:添加一个表的字段的约束并指定默认值go例:alter table T_ping drop constraint DF_T_ping_p_calter table T_ping add constraint DF_T_ping_p_c DEFAULT ((2)) for p_cgoalter table with check T_ping add constraint DF_T_ping_p_c DEFAULT ((2)) for p_calter table with nocheck T_ping add constraint DF_T_ping_p_c DEFAULT ((2)) for p_c两者的区别是If you do not want to verify new CHECK or FOREIGN KEY constraints against existing data, use WITH NOCHECK. This is not recommended except in rare cases. The new constraint will be evaluated in all future updates.对于要建立约束的两个表,如果其中的一个已有数据,把在创建时检查现有数据选项设置为是将告诉SQL SERVER:当开始具体创建约束时,要对表中现有的数据进行检查。如果现有数据符合约束的定义,则约束被成功加入到表中源码天空
温馨提示:答案为网友推荐,仅供参考
相似回答