SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to drop Foreign Key
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Htwe Htwe
Starting Member

9 Posts

Posted - 07/26/2013 :  13:07:02  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3323 Posts

Posted - 07/26/2013 :  13:16:38  Show Profile  Reply with Quote
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/

Edited by - James K on 07/26/2013 13:17:04
Go to Top of Page

Htwe Htwe
Starting Member

9 Posts

Posted - 07/26/2013 :  13:25:03  Show Profile  Reply with Quote
Thanks You Very Much


Thanks and Regards
Htwe Htwe
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3323 Posts

Posted - 07/26/2013 :  16:05:20  Show Profile  Reply with Quote
You are very welcome - glad to help
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000