📜  查询以生成查询以删除 ms sql server 中的主键或外键 - SQL 代码示例

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

代码示例1
DECLARE @sql NVARCHAR(MAX) = N'';

SELECT @sql += N'
ALTER TABLE ' + QUOTENAME(OBJECT_SCHEMA_NAME(parent_object_id))
    + '.' + QUOTENAME(OBJECT_NAME(parent_object_id)) + 
    ' DROP CONSTRAINT ' + QUOTENAME(name) + ';'
FROM sys.foreign_keys WHERE QUOTENAME(OBJECT_NAME(parent_object_id)) LIKE '%[tblAccount]%'

PRINT @sql;