要删除所有的用户表:
declare @sql varchar(8000)
SELECT @sql='drop table ' + name FROM sysobjects
WHERE (type = 'U')
ORDER BY 'drop table ' + name
exec(@sql)
如果要删除所有用户表中的内容,可以执行以下语句:
declare @sql varchar(8000)
SELECT @sql='truncate table ' + name FROM sysobjects
WHERE (type = 'U')
ORDER BY 'truncate table ' + name
exec(@sql)
慎用!
如下也行:
use 数据库名(是要删除表的所在的那个数据库的名称)
GO
declare @sql varchar(8000)
while (select count(*) from sysobjects where type='U')>0
begin SELECT @sql='drop table ' + name FROM sysobjects
WHERE (type = 'U')
ORDER BY 'drop table ' + name
exec(@sql)
end