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

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 Drop script

Author  Topic 

niranjankumark
Posting Yak Master

164 Posts

Posted - 2008-05-10 : 03:12:17
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...

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-10 : 03:52:06
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
   

- Advertisement -