有,从系统表里找,在syscolumns里有所有的字段,以及其对应的表id。最好用存储过程来写。

解决方案 »

  1.   

    可惜我机器上没有安装ms sql,公司里好象也没有。不过思路是这样的:先找出所有有name字段的表,然后再一个表一个表地查询。
      

  2.   

    如果你用的是ADO哪么:ADOConnection1.GetTableNames可以得到所有的表名。
    进一步可得到字段名,再进行查找。
      

  3.   

    系统表sysobject 中存放着表名
    syscolumns 中存放着字段名
    试试吧
      

  4.   

    用SQL SERVER的系统表。
    SQL SERVER本身维护了几个系统视图,反映了这些情况。先找到有那些表,然后建立一个游标,在游标中对每个表定义一个SQL语句,动态执行,返回符合你条件的表明。
    应该不是很难,希望你能解决!
      

  5.   

    create table #TableList(
      name  varchar(200)
    )declare @name varchar(200)
    declare @i int
    declare cur scroll cursor for select name from sysobjects where id in (select id from syscolumns where name = 'name')open cur
    fetch first from cur into @name
    set @i=0
    while @i<@@cursor_rows
    begin
      execute('insert into #TableList select '''+@name+''' from '+@name+' where name=''李四''')
      fetch next from cur into @name
      set @i = @i+1
    end
    close cur
    deallocate curselect * from #TableList
      

  6.   

    谢谢小公子,真的非常感谢,你的方法是对的,过两天我一定给分,现在想再提一个更难的要求,怎样能把数据库中具有‘李四’这个人名的数据表找出来呢?即不一定在Name字段,有可能在其他的字段中,我的要求是不是很怪。
      

  7.   

    你再把name也象表名一样动态变化的就可以了,不过这样是很费时间的哦。
      

  8.   

    原理是一样的,你一样可以从SQL SERVER中得到某表的所有字段。
    你的要求的确很怪,如果你的数据库大点...
      

  9.   

    drop table #tablelist
    create table #TableList(
      name  char(200),
    )declare @name varchar(200)
    declare @col varchar(200)
    declare @sWhere varchar(1000)
    declare @i int
    declare @j int
    declare @iMax int
    declare @jMax intdeclare curTab scroll cursor for select name from sysobjects where xtype='u'
    select @iMax=count(*) from sysobjects where xtype='u'open curTab
    fetch first from curTab into @name
    set @i=1
    while @i<@iMax
    begin
      select @jMax=count(*) from syscolumns where (xtype=175 or xtype=167) and (id in (select id from sysobjects where name=@name))
      if @jMax=0 
      begin
        set @i=@i+1
        continue 
      end
      declare curCol scroll cursor for select name from syscolumns where (xtype=175 or xtype=167) and (id in (select id from sysobjects where name=@name))
      open curCol
      fetch first from curCol into @col
      set @sWhere=' where '+@col+'=''李四'''
      set @j=2
      while @j<@jMax
      begin
        fetch next from curCol into @col
        set @sWhere=@sWhere+' or '+@col+'=''李四'''
        set @j=@j+1
      end;
      close curCol
      deallocate curCol
      execute('insert into #TableList select '''+@name+''' from '+@name+@sWhere)
      fetch next from curTab into @name
      set @i = @i+1
    end
    close curTab
    deallocate curTabselect * from #TableList 
    note:
      only used by CHAR or VARCHAR field
      

  10.   

    weenyboy(小公子),你真棒!希望常常有机会向你讨教,分数全给你。
      

  11.   

    谢谢weenyboy(小公子)精彩的回答,希望有机会能常常向你请教,分数全给你。