SQLServer查询所有表所有字段包含xx的信息
2008-12-19 10:17:45 来源:WEB开发网核心提示:从系统表自动生成sql语句来运行得到结果select a.name as columnname,object_name(a.id)as tablename into t from syscolumns a,sysobjects b,systypes cwhere a.id=b.idand a.xtype=c.xtype
从系统表自动生成sql语句来运行得到结果
select a.name as columnname,object_name(a.id)as tablename into t from syscolumns a,
sysobjects b,
systypes c
where a.id=b.id
and a.xtype=c.xtype
and b.xtype='u'
and c.name in('varchar','nvarchar','char','nchar','text','ntext')
and object_name(a.id)<>'t'
go
create function udf_genSQL(@tableName varchar(1000),@keyword varchar(1000))
returns varchar(8000)
as
begin
declare @sql varchar(8000)
set @sql='select * from '+@tableName +' where 1=1 '
select @sql=@sql+' or '+
columnname +' like ''%'+@keyword+'%''' from t
where tablename=@tablename
return @sql
end
go
select dbo.udf_genSQL(tableName,'a') from t group by tablename
drop table t
drop function dbo.udf_genSQL
- ››sqlserver 每30分自动生成一次
- ››sqlserver安装和简单的使用
- ››SqlServer触发器、存储过程和函数
- ››SQLServer建立交叉表查询
- ››SqlServer强制断开数据库连接的方法
- ››查询Oracle正在执行和执行过的SQL语句
- ››SQLServer 2005 海量数据解决方案
- ››SQLServer 2008数据库查看死锁、堵塞的SQL语句
- ››SqlServer 插入多条数据
- ››SQLServer 2008 R2导出的SQL文件中没有数据
- ››SQLSERVER通过游标查询两个数据表共有字段名组合成...
- ››sqlserver2008实现拼音首字母和随机n位数的生成
赞助商链接