Skip to main content

Posts

Showing posts with the label azuer sql

Drop foreign key relationships

This SQL query retrieves all foreign key constraints that reference the table in the current SQL Server database.     SELECT * FROM sys . foreign_keys WHERE referenced_object_id = object_id ( ' <TABLE_NAME> ' )      This SQL query finds all foreign key constraints that reference the   table and generates SQL statements to drop them. SELECT 'ALTER TABLE [' + OBJECT_SCHEMA_NAME ( parent_object_id ) + '].[' + OBJECT_NAME ( parent_object_id ) + '] DROP CONSTRAINT [' + name + ']' FROM sys . foreign_keys WHERE referenced_object_id = object_id ( '<TABLE_NAME>' )