Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 Drop script
 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

52326 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  
 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.02 seconds. Powered By: Snitz Forums 2000