删除约束时没有运气...我以“sa”身份登录,应该有足够的权限来执行它但我仍然得到:
Msg 4902, Level 16, State 1, Line 6
Cannot find the object "dbo.Products" because it does not exist or you do not have permissions.
以下是查询:
USE [PRSS10_DATABASE]
IF EXISTS (SELECT *
FROM sys.foreign_keys
WHERE object_id = OBJECT_ID(N'dbo.FK_Product_SMC')
AND parent_object_id = OBJECT_ID(N'dbo.Products')
)
ALTER TABLE [dbo.Products] DROP CONSTRAINT [FK_Product_SMC]
现在我可以访问该表..该表存在,外键也是..我可以丢失什么?
答案 0 :(得分:6)
它是括号。当你执行[dbo.products]
时,会认为整个对象被命名为" dbo.products" 你想要的是[dbo].[Products]
,以便它识别 " dbo" 作为架构和"产品" 作为表名称。
答案 1 :(得分:2)
修正语句如下:
ALTER TABLE [dbo].[Products] DROP CONSTRAINT [dbo].[FK_Product_SMC]