Posts Tagged ‘ disable referential integrity ’

SQL to find out and disable child tables referencing parent table in SQL Server

You can use this query to find out child tables referencing parent Table.

--replace 't_User'with your table name
--query to find out which table have references
select 'foreign key name',
  OBJECT_NAME(parent_obj) 'table',
  OBJECT_NAME(sf.fkeyid) 'referencing table', 'referencing column',
  OBJECT_NAME(sf.rkeyid) 'referenced table', 'referenced column'
from sysobjects so
inner join sysforeignkeys sf on = sf.constid
inner join syscolumns sc1 on sf.fkeyid = and sf.fkey = sc1.colid
inner join syscolumns sc2 on sf.rkeyid = and sf.fkey = sc2.colid
where so.xtype in ('F','PK')
and OBJECT_NAME(sf.rkeyid) = 't_User'

Continue reading