Solved

Alter Table fails to add FK Constraint to table.

Posted on 2008-06-20
5
1,760 Views
Last Modified: 2008-06-23
I'm logged in to SSMS via SQL Authentication. I can create tables, and create FK constraints at the time of table creation, but not via the Alter command on existing table. What do I need to do to make sure I have enough permission or is there a setting I need to change somewhere?
ALTER Table COMPANY 
ADD CONSTRAINT fk_Comp_Div FOREIGN KEY (DIV_ID) REFERENCES DIVISION (DIV_ID)

Open in new window

0
Comment
Question by:DustinSpears
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 21834096
you need the "ALTER TABLE" permission
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 21834163
you may want to consider adding NOCHECK To your constraint:

ALTER Table COMPANY WITH NOCHECK
ADD CONSTRAINT fk_Comp_Div FOREIGN KEY (DIV_ID) REFERENCES DIVISION (DIV_ID)
0
 

Author Comment

by:DustinSpears
ID: 21834195
When I go to the properties of my database, then "permissions" and look at the available permissions listed there for my login, I do not see an "Alter Table", I see an "alter" and alot of other alter etc., but not that one. Any idea why? And the Nocheck did not help, thanks though.
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 21834274
make sure you execute the statement in the context of the database that the table resides....your error message tells me that you executed it in another db by mistake.
0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
ID: 21834374
grant alter on <your table> to [<your database user>]
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question