Advertisement

Advertisement

How to remove Foreign Key Constraint in SQL

How to remove Foreign Key Constraint in SQL

SELECT 

    OBJECT_NAME(fk.constraint_object_id) AS ConstraintName,

    fk.constraint_column_id AS ColumnId,

    col.name AS ColumnName

FROM 

    sys.foreign_key_columns fk

INNER JOIN 

    sys.columns col ON fk.parent_object_id = col.object_id AND fk.parent_column_id = col.column_id

WHERE 

    OBJECT_NAME(fk.parent_object_id) = 'Orders';

Ya CONSTRAINT folder me ja k CONSTRAINT  key copy paste kare 


ALTER TABLE  Tbl_Name

DROP CONSTRAINT [ForeignKeyConstraintName];  -- Yahan [ForeignKeyConstraintName] ko actual constraint naam se replace karein


How to remove Foreign Key Constraint in SQL How to remove Foreign Key Constraint in SQL Reviewed by Rikesh on December 03, 2024 Rating: 5

No comments:

Powered by Blogger.