Solved

Alter Table fails to add FK Constraint to table.

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

821 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