为什么我不能使用DROP CONSTRAINT命令删除约束?

时间:2013-07-06 11:02:50

标签: sql sql-server sql-server-2008

我在C#中有以下代码:

context.Database.ExecuteSqlCommand(webpages_UsersInRolesScripts.dropConstraints);

public const string dropConstraints =
    @"
    USE [DBA];
    SET ANSI_NULLS ON
    DROP CONSTRAINT [webpages_Roles_UserProfiles_Target];
    DROP CONSTRAINT [webpages_Roles_UserProfiles_Source];
    ";

这给我一条错误信息:

Message=Incorrect syntax near the keyword 'CONSTRAINT'.

1 个答案:

答案 0 :(得分:3)

我认为您需要发出如下声明:

ALTER TABLE table_identifier DROP CONSTRAINT constraint_identifier;