select d.name,a.name ,b.name ,a.length, a.isnullable from syscolumns a, systypes b,sysobjects d where a.xtype=b.xusertype and a.id=d.id and d.xtype='U'

解决方案 »

  1.   

    select 'tt',name from tt..sysobjects where xtype='U'
    union all
    select 'bb',name from bb..sysobjects where xtype='U'
      

  2.   

    select 'tt' as DBName,name as TBName from tt..sysobjects where xtype='U'
    union all
    select 'bb',name from bb..sysobjects where xtype='U'
      

  3.   

    if Exists(Select * from tempdb..sysobjects where Name Like '##tmp%')
       Drop table ##tmp
    Create table ##tmp(database_name varChar(20),table_name varChar(20))
    Declare @database_name varchar(20),@table_name varChar(20)
    Declare Cu_A Cursor For Select data_name=Cast(name as varChar(20)) 
                  from master..sysdataBases where status=16 --status=16为用户数据库
    Open Cu_A
    Fetch Cu_A Into @database_name
    while @@Fetch_Status=0
    begin
      Exec('Use '+@database_name)
      Declare Cu_B Cursor For Select Table_name=Cast(name as VarChar(20)) 
               From sysobjects where xtype='U' and Status>0
      Open Cu_B
      Fetch Cu_B Into @table_name
      while @@Fetch_Status=0
      begin
         Insert Into ##tmp values(@database_name,@table_name)
         Fetch Cu_B Into @table_name
      end
      Close Cu_B
      deallocate Cu_B
      Fetch Cu_A Into @database_name
    end
    Close Cu_A
    Deallocate Cu_A
    Select * from ##tmp
      

  4.   

    更正一下:
    select 'tt' as DBName,name as TBName from tt..sysobjects where xtype='U'
    union all
    select 'bb',name from bb..sysobjects where xtype='U'
      

  5.   

    这个更好,你的数据库中有多少个数据库,就帮你显示多少个:
    declare @sql varchar(8000)
    declare @dbname varchar(100)select @sql=''
    declare #aa cursor for select name from master.dbo.sysdatabases where name not in('master','model','msdb','tempdb') --如果 Northwind 和 pubs 数据库不需要显示,则需要加入到条件中

    open #aa
    fetch next from #aa into @dbname
    while @@fetch_status=0
    begin
    select @sql=@sql+' union all select '''+@dbname+''' as 数据库名,name as 表名 from ['
    +@dbname+'].dbo.sysobjects where xtype=''U'''+char(13)
    fetch next from #aa into @dbname
    end
    close #aa
    deallocate #aa
    select @sql=right(@sql,len(@sql)-11)
    if @sql<>''
        exec( @sql)
    else
        print '未有用户数据库'