正在压缩数据库...请等待:严禁此时关闭计算机! Dim strSql As String Set conn = New ADODB.Connection 连接数据库 Set rs = conn.OpenSchema(adSchemaTables)Do While Not rs.EOF aa= rs!TABLE_NAME '这个开始获取这个表的字段 dim rrs as adodb.recordset dim strrSql as string set rrs= new adodb.recordset strrsql="查询表 where 字段=‘“& 单位 &”’" conn.execute strrSql '得到表我没做过,你需要网上找一下,把代码填进来就完整了 do while not rrs.eof dim rrrs as adodb.recordset set rrrs= new adodb.recordset dim strrrSql as string strrrSql="select * from "& aa &" where "& rrs.fields("上面得到的字段NAME") &"='"& ("美女") &"' " conn.execute strrrSql if rrrs.recordcount>0 then msgbox"有" else msgbox"没有" end if rrs.movenext looprs.MoveNext Loop rs.Close 大致的意思就是:先得到库中所有的表然后再获取表中的字段,查找有没有:“单位”这个字段然后在组织语句查询这个字段有没有匹配“美女”的 如果有msgbox"有" else msgbox "没有" 如此循环下去 直到查询结束
Set rs = conn.OpenSchema(adSchemaTables)
declare @tbname nvarchar(20) --存在字段“单位”的表名 declare @sql nvarchar(1000) declare @count int --单位字段含有“美女”条数declare cur1 cursor for select object_name(id) from syscolumns where name='单位' open cur1 fetch next from cur1 into @tbname while @@fetch_status=0 begin set @sql='select @count=count(单位) from ' + @tbname +' where 单位 like ''%美女%'' '
exec sp_executesql @sql, N'@count int output',@count output
if @count > 0 print @tbname +':'+ '有' else print @tbname +':'+ '没有' fetch next from cur1 into @tbname end close cur1 deallocate cur1
Dim strSql As String
Set conn = New ADODB.Connection
连接数据库
Set rs = conn.OpenSchema(adSchemaTables)Do While Not rs.EOF
aa= rs!TABLE_NAME '这个开始获取这个表的字段
dim rrs as adodb.recordset
dim strrSql as string
set rrs= new adodb.recordset
strrsql="查询表 where 字段=‘“& 单位 &”’"
conn.execute strrSql '得到表我没做过,你需要网上找一下,把代码填进来就完整了
do while not rrs.eof
dim rrrs as adodb.recordset
set rrrs= new adodb.recordset
dim strrrSql as string
strrrSql="select * from "& aa &" where "& rrs.fields("上面得到的字段NAME") &"='"& ("美女") &"' "
conn.execute strrrSql if rrrs.recordcount>0 then
msgbox"有"
else
msgbox"没有"
end if rrs.movenext
looprs.MoveNext
Loop
rs.Close
大致的意思就是:先得到库中所有的表然后再获取表中的字段,查找有没有:“单位”这个字段然后在组织语句查询这个字段有没有匹配“美女”的
如果有msgbox"有"
else
msgbox "没有"
如此循环下去 直到查询结束
declare @tbname nvarchar(20) --存在字段“单位”的表名
declare @sql nvarchar(1000)
declare @count int --单位字段含有“美女”条数declare cur1 cursor
for
select object_name(id) from syscolumns where name='单位'
open cur1
fetch next from cur1 into @tbname
while @@fetch_status=0
begin
set @sql='select @count=count(单位) from ' + @tbname +' where 单位 like ''%美女%'' '
exec sp_executesql @sql, N'@count int output',@count output
if @count > 0
print @tbname +':'+ '有'
else
print @tbname +':'+ '没有' fetch next from cur1 into @tbname
end
close cur1
deallocate cur1