Tuesday, March 27, 2012

delete all sql database user objects

Good afternoon,

I have a little trouble with sql server 2005 express database:

customer need install new web application to hosting, but at hosting is currently exist other web application and it's using DB what I must use. DB contains a big number of tables, views, functions, etc.

I need delete all user objects from this DB, it must be as new created one.

Is any query whitch can do this?

PS: I know, best way for this is delete DB and create new one, but i haven't permissions for these.

Thank's for reply.

so u want to drop all objects created by u...u can generate delete scripts(for all user objects in that DB) for all the objects using the management studio...select all the items u need to delete and run the script...|||Hi,

use this script to first drop the constraints of the tables then afterwards drop the tables. If you have any further schemabound objects like views, procedures or functions you will also have to drop them in the right order.

Select

'ALTER TABLE ' + TABLE_SCHEMA + '.' + TABLE_NAME +

' DROP CONSTRAINT ' + Constraint_Schema + '.' + Constraint_Name

from INFORMATION_SCHEMA.CONSTRAINT_TABLE_USAGE

WHERE OBJECTPROPERTY(OBJECT_ID(Constraint_Schema + '.' + Constraint_Name), 'IsMSShipped') = 0

Select

'DROP TABLE ' + TABLE_SCHEMA + '.' + TABLE_NAME

from INFORMATION_SCHEMA.TABLES

WHERE OBJECTPROPERTY(OBJECT_ID(TABLE_SCHEMA + '.' + TABLE_NAME), 'IsMSShipped') = 0

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de

sql

No comments:

Post a Comment