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
 how to delete all userdefined objects in database

Author  Topic 

mr_dayal
Starting Member

37 Posts

Posted - 2008-10-18 : 04:53:04
I am using a database (server instance) I have some table ,views in my database . I want to clear all the user defined objects of this database ,but don't want to drop this database.
I tried "sp_msforeach table" command but " it is not possible because there are some primary,Forign keys in my database.
Is there any way to delete all the object including user,tables,views,procedures etc without droping the whole databse.



Mr Dayal

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-18 : 07:38:42
you need to first drop the foreign key relationships of tables before droping it. Make use of INFORMATION_SCHEMA.CONSTRAINT_TABLE_USAGE to get the constraints in table and drop them first. then use sp_depends to find out dependent tables & procedure and drop them and finally drop the main tables.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-10-18 : 08:14:40
If your goal is to drop all user defined objects, why dont you just drop and recreate the database?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2008-10-18 : 14:22:05
Prior to dropping the database , ensure you generate CREATE scripts for all objects plus database, incase you need to troubleshoot

Jack Vamvas
--------------------
Search IT jobs from multiple sources- http://www.ITjobfeed.com
Go to Top of Page
   

- Advertisement -