📜  用于从列中删除默认值的 sql 脚本 - SQL 代码示例

📅  最后修改于: 2022-03-11 15:04:51.442000             🧑  作者: Mango

代码示例1
DECLARE @tableName VARCHAR(MAX) = ''
DECLARE @columnName VARCHAR(MAX) = ''
DECLARE @ConstraintName nvarchar(200)
SELECT @ConstraintName = Name 
FROM SYS.DEFAULT_CONSTRAINTS
WHERE PARENT_OBJECT_ID = OBJECT_ID(@tableName) 
AND PARENT_COLUMN_ID = (
    SELECT column_id FROM sys.columns
    WHERE NAME = @columnName AND object_id = OBJECT_ID(@tableName))
IF @ConstraintName IS NOT NULL
    EXEC('ALTER TABLE '+@tableName+' DROP CONSTRAINT ' + @ConstraintName)
    
-- Just replace  and