sqlserver添加默认值
知识点:
sql添加字段默认值时:
1.如果有加 not null ,则已有记录该字段值更新为默认值
2.如果没有加 not null,则为null
代码:
IF EXISTS ( SELECT TOP 1 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE [TABLE_NAME] = 'ProductVituralQuantity' AND [COLUMN_NAME] = 'updatekucmsg' ) begin ALTER TABLE ProductVituralQuantity drop DF_ProductVituralQuantity_updatekucmsg ALTER TABLE ProductVituralQuantity alter column updatekucmsg nvarchar(max) NOT NULL ALTER TABLE ProductVituralQuantity add constraint DF_ProductVituralQuantity_updatekucmsg DEFAULT ((0)) for updatekucmsg END go