Tuesday, March 27, 2012

delete all tables

Hi folk,

whats the SQL syntax of deleting all user tables of a specific database on a Microsoft SQL server?

thanks in advance,

mulata

use yourTable;
go
EXEC sp_MSforeachtable @.command1 = "DROP TABLE ?"

--"sp_MSforeachtable" is one of the undocumented SQL Server system stored procedures.

|||

hm sorry I don"t understand your solution.

Is there a way that you do that in a "one line SQL statement" ,

something like: "drop table (select * from usertables) "

thanks

|||I agree with limon's solution, which is really straight and easy to use. It will go through each user table in current database and perform same action on each of them.?Since?DROP TABLE command can only be followed bytablename, I don't think you can drop all tables within one single statement except using such stored procedure.

No comments:

Post a Comment