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
 General SQL Server Forums
 New to SQL Server Programming
 plz solve this one

Author  Topic 

raky
Aged Yak Warrior

767 Posts

Posted - 2008-01-01 : 01:49:03
Hi! i need to know which tables in my database are not used by any stored procedure in my database.i need ur help.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-01-01 : 02:36:07
One method is to make use of third party SP sp_grep which is available for free download. when a string (table name) is passed as a param to this SP it will return all user SP names which contains this string. You may insert the result of this sp into a temporary table along with table name for each table in INFORMATION_SCHEMA.Tables view and check for those which doesnt have any records in temp table.

Go to Top of Page

ranganath
Posting Yak Master

209 Posts

Posted - 2008-01-01 : 23:52:42
Hi,

Try This One

SELECT DISTINCT OBJECT_NAME(ID)AS 'TABLENAME' FROM SYS.SYSOBJECTS WHERE TYPE = 'U'
AND OBJECT_NAME(ID) NOT IN (
SELECT DISTINCT SO.NAME
FROM SYS.SYSCOMMENTS SC
INNER JOIN SYS.SYSOBJECTS SO ON SC.TEXT LIKE '%' + SO.NAME + '%'
WHERE SO.XTYPE = 'U'
AND SC.ID IN ( SELECT ID FROM SYS.SYSOBJECTS WHERE XTYPE = 'P')
)
Go to Top of Page
   

- Advertisement -