QQ网名大全

怎么样知道自己的数据库名字??

--用查询分析器,执行下面的语句,可以列出服务器上所有用户数据库+表+存储过程+触发器:

declare @sql varchar(8000)
declare @dbname varchar(250)

declare #aa cursor for
select name from master..sysdatabases where name not in('master','tempdb','model','msdb')
open #aa
fetch next from #aa into @dbname
while @@fetch_status=0
begin
set @sql='select re=''数据库名='+@dbname+''''
+' union all select ''--表名:'''
+' union all select name from ['+@dbname+']..sysobjects where xtype=''U'''
+' union all select ''--存储过程:'''
+' union all select name from ['+@dbname+']..sysobjects where xtype=''P'''
+' union all select ''--触发器:'''
+' union all select name from ['+@dbname+']..sysobjects where xtype=''T'''
print @sql
exec(@sql)
fetch next from #aa into @dbname
end
close #aa
deallocate #aa
佚名
2024-06-07 13:22:26
最佳回答
类似问题(10)