Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL server book online

Status
Not open for further replies.

citic

Technical User
Sep 25, 2001
11
0
0
US
How can I find the example of using T-SQL to drop foreign key from the table. I can not find the answer from SQL Server book online. I know this can be done by using GUI tool. But I want to know more about using SQL code. Perhaps you think this question is stupid. If you don't want to help, that's OK. But don't delete my post. I believe there are some nice people in this fourm may like to help me. Thanks in advance.
 

Look in SQL BOL under the topic Alter Table. The basic syntax is...

ALTER TABLE table_name DROP CONTRAINT fk_name Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 

Small correction...

ALTER TABLE table_name DROP CONSTRAINT fk_name Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Terry:

Thank yo so much. I went to SQL BOL and Alter Table to read it all. Then I went a test server to type SQL code there. Here is the T-SQL code:

ALTER TABLE FACT_ORDERS
DROP CONSTRAINT FK_FACT_ORDE_CUSTO_3D5E1FD2 (or I type the fk_name as customer_wk)

It all didn't work. Here is the error message

Server: Msg 3728, Level 16, State 1, Line 1
'FK_FACT_ORDE_CUSTO_3D5E1FD2' is not a constraint.
Server: Msg 3727, Level 16, State 1, Line 1
Could not drop constraint. See previous errors.

Is this because I do not have the privilage on modify the database objects? or anything else? Thank you for your help.

 
Terry:

It works since I didn't put correct fk_name. Thank you so much for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top