Delete database all tables and all stored procedure SQL statements at once
Transferring database data today requires emptying the database's original tables and stored procedures.
To delete all tables:
If table failure is deleted because of a foreign KEY constraint, all constraints are removed first:
--/1th Step ********** Delete all table foreign KEY constraints *************************/DECLARE C1 Cursor for Select 'ALTER TABLE ['+ object_name (parent_obj) +'] Drop constraint ['+name+']; ' fromsysobjectswhereXtype ='F'Open c1declare @c1 varchar (8000) FETCH Next fromC1 into @c1 while(@ @fetch_status =0) begin EXEC (@c1) fetch next fromC1 into @c1endclose c1deallocate C1--/2nd Step ********** Delete all tables *************************/Use database declare @tname varchar (8000)Set@tname ="'Select@[email protected] + Name +',' fromsysobjectswhereXtype='U'Select@tname ='drop table'+ Left (@tname, Len (@tname)-1) EXEC (@tname)----empty stored procedure use [database name]declare @tname varchar (8000)Set@tname ="'Select@[email protected] + Name +',' fromsysobjectswhereXtype='P'Select@tname ='Drop PROCEDURE'+ Left (@tname, Len (@tname)-1) EXEC (@tname)
Transferred from: http://www.cnblogs.com/a-zx/articles/2405121.html
Delete database all tables and all stored procedure SQL statements at once