我使用以下命令:刪除外鍵使用變量名
DECLARE @ConstraintName varchar(255);
SELECT @ConstraintName = CONSTRAINT_NAME
FROM
INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE
WHERE
TABLE_NAME = 'TheTable'
AND COLUMN_NAME = 'TheColumn';
alter table TheTable drop constraint @ConstraintName;
但是,它有@ConstraintName附近的語法不正確。這可能是一件小事,但我無法弄清楚。我應該改變什麼,這樣約束會被刪除?
SQLFiddle:http://sqlfiddle.com/#!2/6709e/3
Isn「t it SELECT INTO @ConstraintName ... ??? –
@AnthonyRaymond給了我'關鍵字'INTO'附近的語法不正確。 – Joetjah