Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to drop Foreign Key

Author  Topic 

Htwe Htwe
Starting Member

9 Posts

Posted - 2013-07-26 : 13:07:02
I want to delete a table.This table is created with foreign key.

How to remove foreign key.

May I Know about it.

Thanks in advance

Htwe Htwe

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-07-26 : 13:16:38
If you are dropping the table that is referring to a column in another table, you don't have to do anything special - just drop the table and the key also will get dropped.

If you are dropping the table that is being referenced, then in SSMS, under object explorer, find the key (it will be under the keys section of the referring table) and delete it.

Via script you would do it like this:
ALTER TABLE YourReferencingTable DROP CONSTRAINT [YourForeignKeyName]
If you are not sure which tables reference the table you want to drop, look up using the query on this page: http://blog.sqlauthority.com/2006/11/01/sql-server-query-to-display-foreign-key-relationships-and-name-of-the-constraint-for-each-table-in-database/
[/code]
Go to Top of Page

Htwe Htwe
Starting Member

9 Posts

Posted - 2013-07-26 : 13:25:03
Thanks You Very Much


Thanks and Regards
Htwe Htwe
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-07-26 : 16:05:20
You are very welcome - glad to help
Go to Top of Page
   

- Advertisement -