Reputation: 11469
Not having luck when dropping a constraint...I am logged in as 'sa' which should have enough permissions to execute it but I still get:
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.
And here is the query:
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]
Now I am able to access the table.. the table exists and the Foreign key as well.. what could I be missing?
Upvotes: 1
Views: 7985
Reputation: 1457
It's the brackets. when you do [dbo.products]
that makes it think the whole object is named "dbo.products" What you want is [dbo].[Products]
so that it recognizes "dbo" as the schema and "Products" as the table name.
Upvotes: 6
Reputation: 35531
Fix the statement to read like this:
ALTER TABLE [dbo].[Products] DROP CONSTRAINT [dbo].[FK_Product_SMC]
Upvotes: 2