I'm using Microsoft SQL Server 2005, and am relatively new to SQL in general.
There is a relationship between two tables, "Resources" and "Group_Resources", in the database "Information". Resources has a foreign key, "id", in Group_Resources, named "resource_id". There is a foreign key constraint, "fk_gr_res_resources", between the two.
I'm established as the database owner, and have full read/write/create/delete permissions.
I want to delete the foreign key constraint, so I executed the following query:
ALTER TABLE [Information].[group_resources] DROP CONSTRAINT fk_gr_res_resources
and received the following error:
'fk_gr_res_resources' is not a constraint. Could not drop constraint. See previous errors.
I'm confused, because it is a constraint, and there are no spelling errors. Am I going about deleting this improperly? Am I deleting the constraint from the incorrect table?
1条答案
按热度按时间yx2lnoni1#
You are getting this error:
Because the FK constraint does not exist!
Are you sure that
Information
is the right schema name and notdbo
?1. This SQL will prove that the FK does not exist:
2. Oops, I was wrong in my original answer, here is the correct syntax for SQL Server:
3. Example for your database:
4. Try running this:
5. Then try this and see if you still get that error:
The other syntax was for MySQL, sorry: