Solved

Identifying FKs with On Delete Cascade from a query.

Posted on 2007-03-27
2
813 Views
Last Modified: 2008-03-03
I would like to identify whether a foreign key has the delete cascade option set by querying SQL Server system tables.
I need a query which shows the FKs on a database and whenther the delete cascade option set.

0
Comment
Question by:JR2003
2 Comments
 
LVL 21

Accepted Solution

by:
ziolko earned 500 total points
ID: 18798735
try this:

sp_MStablerefs N'dbo.Table1', N'actualtables', N'both', null

ziolko.
0
 
LVL 18

Author Comment

by:JR2003
ID: 18798790
Thanks that works. I also found the ObjectProperties function gives the result I want.

select so.name,
       objectproperty(so.id, 'CnstIsDeleteCascade') AS DeleteCascade
  from sysforeignkeys fk
 inner join sysobjects so
         on fk.constid = so.id
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
migration MS SQL database to Oracle 30 62
VBScript Write Column Headers 3 38
Inserting oldest record into new table. 5 25
insert wont work in SQL 14 22
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question