日期:2014-05-19  浏览次数:20392 次

sqlserver2000如何删除所有的用户表
在一个数据库里,我想要删除所有用户的表,我只知道用Select   Name   from   sysobjects   where   xtype= 'u '   and   status> =0可以查看所有的用户表,但不知道删除这些表SQL语句该怎么写(是一句SQL句执行),我是初学者,请大家帮下,谢谢

------解决方案--------------------
DECLARE @command nvarchar(2000),@whereand nvarchar(2000)
SELECT @command=N 'drop table ? ',@whereand= ' '
EXEC sp_MSforeachtable @command1=@command,@whereand=@whereand
------解决方案--------------------
参考这个,这是查看数据库中用户表的占用空间的,
用游标实现的,应该也可以通过动态语句实现用户表的删除
declare @tablename varchar(100)
declare @sql varchar(8000)
declare spaceusecursor cursor
for
select name from sysobjects where xtype= 'u '


open spaceusecursor

fetch next from spaceusecursor into @tablename

while @@fetch_status=0
begin
set @sql= ' exec sp_spaceused '+@tablename + ' '
print @sql
exec(@sql)
fetch next from spaceusecursor into @tablename

end

close spaceusecursor
deallocate spaceusecursor
------解决方案--------------------
sp_msforeachtable 'drop table ? '
------解决方案--------------------
sp_msforeachtable 今天又学了一课,


没人公布的系统存储过程sp_MSforeachtable和sp_MSforeachdb,
用于遍历某个数据库的每个表和遍历DBMS管理下的每个数据库。
------解决方案--------------------
DECLARE @command nvarchar(2000),@whereand nvarchar(2000)
SELECT @command=N 'drop table ? ',@whereand= ' '
EXEC sp_MSforeachtable @command1=@command,@whereand=@whereand