SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 Drop script
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

164 Posts

Posted - 05/10/2008 :  03:12:17  Show Profile  Reply with Quote
In my datbase i have selected unused 300 tables and it should be dropped.
but it may have constraints. so need script with cascade for drop and also
i need to find parent child relation based on that it should get listed and finally deleted.
if any one has those two kind of scripts pls send me...

Very Important crosS Applying yaK Herder

52325 Posts

Posted - 05/10/2008 :  03:52:06  Show Profile  Reply with Quote
This lists all the tables which references the unsused tables.
SELECT OBJECT_NAME(f.constid) AS 'ForeignKey', OBJECT_NAME(f.fkeyid) AS
'FKTable', c1.[name] AS 'FKColumnName', OBJECT_NAME(f.rkeyid) AS 'PKTable',
c2.[name] AS 'PKColumnName'
FROM sysforeignkeys f
INNER JOIN syscolumns c1
ON f.fkeyid = c1.[id]
AND f.fkey = c1.colid
INNER JOIN syscolumns c2
ON f.rkeyid = c2.[id]
AND f.rkey = c2.colid
WHERE OBJECT_NAME(f.rkeyid) IN (YourunusedTableList)
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000