sql 删除数据库中所有表或表数据

-------------------------------删除数据库中所有表
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
 
-------------------------------删除数据库中所有表的数据
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 'truncate table ' + name
exec(@sql) 
end

猜你喜欢

转载自blog.csdn.net/weixin_45467975/article/details/129731183