Solved

Alter Table fails to add FK Constraint to table.

Posted on 2008-06-20
5
1,758 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
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

820 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