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
 delete views which are not used

Author  Topic 

Sep410
Posting Yak Master

117 Posts

Posted - 2008-05-27 : 17:19:21
Hi
I need to edit a database. I have to delete all the views which are not used in any other views or stored procedures. Is there any kind of shortcut to help me figure out which view is not used in any other views or stored procedures?
Thanks

Sep410
Posting Yak Master

117 Posts

Posted - 2008-05-27 : 18:41:41
I found this:
SELECT table_name ,view_definition
FROM INFORMATION_SCHEMA.views
WHERE (view_definition LIKE '%NameOfYourView%')

It is not what I need but it is better than nothing and manually checking.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-05-27 : 18:43:34
Search syscomments instead.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Database maintenance routines:
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Go to Top of Page

Sep410
Posting Yak Master

117 Posts

Posted - 2008-05-27 : 18:53:55
Can you explain more?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-05-27 : 18:58:02
If you use INFORMATION_SCHEMA.VIEWS, you'll miss the stored procedures and functions. If you use INFORMATION_SCHEMA.ROUTINES, you'll miss the views. You could use both and get all 3, but then why not just use syscomments instead as it contains the code for all 3 types.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Database maintenance routines:
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Go to Top of Page
   

- Advertisement -