SQL Server foreign key point record

Source: Internet
Author: User

When you need to crack the foreign key constraint, you need to know the foreign key name. Two attempts in SQL server 2005 can be used: a) sys. foreign_key_columns B) sys. foreign_keys

Query the foreign key in the current database using SQL and query it together with the reference table:

Select Central. name, Central. object_id, Central. parent_object_id, Central. type_desc,
Cns. referenced_object_id, obj. name
From sys. foreign_keys cns
Left join sys. all_objects obj
On cns. referenced_object_id = obj. object_id;

Check the primary table and sub-table together by the way:
Select Central. name, Central. object_id, Central. parent_object_id, par_obj.name as parent_object_name, Central. type_desc,
Cns. referenced_object_id, obj. name
From sys. foreign_keys cns
Left join sys. all_objects obj
On cns. referenced_object_id = obj. object_id
Left join sys. all_objects par_obj
On cns. parent_object_id = par_obj.object_id

Alter table capitalhistory
Drop constraint R_1;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.