'*************************************************************************
'**函 数 名:s_ListSQLSrv_DB
'**功能描述:在立即窗口打印出所有的 SQL Server 组及各组的 SQL Server
'** 及各级的数据库
'**输 入:无
'**输 出:无
'**调用模块:引用: Microsoft SQLDMO Object Library
'**作 者:邹建
'**日 期:2003年11月26日
'*************************************************************************
Sub s_ListSQLSrv_DB()
Dim iSql As SQLDMO.Application
Dim iSqlS As SQLDMO.SQLServer
Dim iI&, iJ&, iL&
Set iSql = New SQLDMO.Application
Set iSqlS = New SQLDMO.SQLServer
iSqlS.LoginSecure = True '对于win98/me,取消此句
With iSql.ServerGroups
For iI = 1 To .Count
Debug.Print .Item(iI).Name
With .Item(iI).RegisteredServers
For iJ = 1 To .Count
Debug.Print vbTab & .Item(iJ).Name
iSqlS.Connect .Item(iJ).Name '对于win98/me,加上:,用户名,密码
With iSqlS.Databases
For iL = 1 To .Count
Debug.Print vbTab & vbTab & .Item(iL).Name
Next
End With
iSqlS.Disconnect
Next
End With
Next
End With
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