SqlServer查询某数据在某表某列中
create proc spFind_Column_In_DB
(
@type int,--类型:为文字类型、为数值类型
@str nvarchar(100)--需要搜索的名字
)
as
--创建临时表存放结果
create table #tbl(PK int identity primary key ,tbl sysname,col sysname)
declare @tbl nvarchar(300),@col sysname,@sql nvarchar(1000)
if @type=1
begin
declare curTable cursor fast_forward
for
select '['+SCHEMA_NAME(SCHEMA_ID)+'].['+o.name+']' tableName,'['+c.name+']' columnName from sys.columns c inner join sys.objects o on c.object_id=o.object_id
where o.type_desc='user_table' and user_type_id in (167,175,231,239,35,99)
end
else
begin
declare curTable cursor fast_forward
for
select '['+SCHEMA_NAME(SCHEMA_ID)+'].['+o.name+']' tableName,'['+c.name+']' columnName from sys.columns c inner join sys.objects o on c.object_id=o.object_id
where o.type_desc='user_table' and user_type_id in (56,48,52,59,60,62,106,108,122)
end
open curtable
fetch next from curtable into @tbl,@col
while @@FETCH_STATUS=0
begin
set @sql='if exists (select * from '+@tbl+' where '
if @type=1
begin
set @sql += @col + ' like ''%'+@str +'%'')'
end
else
begin
set @sql +=@col + ' in ('+@str+'))'
end
set @sql += ' INSERT #TBL(tbl,col) VALUES('''+@tbl+''','''+@col+''')'
--print @sql
exec (@sql)
fetch next from curtable into @tbl,@col
end
close curtable
deallocate curtable
select * from #tbl
exec spFind_Column_In_DB 1,'查询条件'
SqlServer查询某数据在某表某列中的更多相关文章
- MySQL将表a中查询的数据插入到表b中
MySQL将表a中查询的数据插入到表b中 假设表b存在 insert into b select * from a; 假设表b不存在 create table b as select * from a ...
- 【整理】SQLServer查询各种数据库对象(表,索引,视图,图表,存储过程等)
首先明确数据库对象的定义:数据库对象定义数据库内容的结构.它们包含在数据库项目中,数据库项目还可以包含数据生成计划和脚本. 常见的数据库对象包括:表,索引,视图,图表,缺省值,规则,触发器,存储过程, ...
- sqlserver:同一数据库内负责表结构。
select * into 新表 from 旧表 where 1=2; ## where 表示要携带的数据,随便写个恒不等式就可以只复制表结构不携带数据.
- sqlserver 查询重复数据
use StudentManageDB go ,,) ,,) ,,) select * from ScoreList order by StudentId --在知道那个字段重复的情况 --查询所有重 ...
- sqlserver 查询库中有多少张表
表数目:select count(1) from sysobjects where xtype='U' 视图数::select count(1) from sysobjects where xtype ...
- 【转】sqlserver查询数据库中有多少个表
sql server 数表: select count(1) from sysobjects where xtype='U' 数视图: select count(1) from sysobjects ...
- sqlserver查询数据库中有多少个表
sql server 数表: select count(1) from sysobjects where xtype='U' 数视图: select count(1) from sysobjects ...
- sqlserver查询数据库中有多少个表,多少视图,多少存储过程,或其他对象
sql server 数表: select count(1) from sysobjects where xtype='U' 数视图: select count(1) from sysobjects ...
- Sqlserver查询结果集插入新表
数据库“Test” 数据库“Test2” 表 “fromTable” 表 “toTable” 表 “newTable” 字段 “name”,“age”,“gender” 原因:公司有2个数据库,一个是 ...
随机推荐
- 查询本地电脑IP地址
使用Windows+R键打开"运行"窗口,然后输入CMD进入命令提示窗口 进入命令窗口之后,输入:ipconfig/all 回车即可看到整个电脑的详细的IP配置信息
- vue启动时候报错
使用vue时,在已经安装模块完毕的情况下,依旧会报错,如: Module build failed: Error: %1 is not a valid Win32 application. 这个时候只 ...
- 014_zk路径过滤分析
一.线上zk访问延迟特别高需要统计一段时间内的zk写入路径top10,实现如下: #!/usr/bin/env python # -*- coding:utf-8 -*- import re,trac ...
- 随心测试_软测基础_007<软测学习路线建议>
如果你对软测感兴趣,那么如何学习软件测试呢? 贴心小提示:以下内容,仅供参考,不挖坑 1:学习方式_职业教育选择观 ————SX的观点:成本 | 收益说,理性接受 软测产业服务链中,测试工程师重在于& ...
- Virtual DOM 系列二:核心API
为了更好的研究Virtual DOM,我选择了snabbdom来学习.相比Vue来说,snabbdom对于研究虚拟DOM更好,因为它里面没有其他干扰的东西,而且源码也比较少,因此研究起来更方便. 1. ...
- MySQL性能优化神器—explain
一.explain是什么? 简单来讲就是官方给的一个优化工具,直接在你的SQL语句前加上explain,执行整条语句,之后你就可以根据执行结果优化你的SQL啦,废话不多说,直接刚实例 测试实例 1.创 ...
- React Native Flexbox & CSS3 Flexbox
React Native Flexbox & CSS3 Flexbox https://facebook.github.io/react-native/docs/flexbox/ https: ...
- react-native-echarts在打包时出现的坑
react-native-echarts目前是RN开发中使用echarts图表最好的插件了,用法与Echarts完全一致,默认提供了三个属性: option (object): The option ...
- [UVa-437] Color Length
无法用复杂状态进行转移时改变计算方式:巧妙的整体考虑:压缩空间优化时间 传送门:$>here<$ 题意 给出两个字符串a,b,可以将他们穿插起来(相对位置不变).要求最小化ΣL(c),其中 ...
- 在中断服务函数中使用FreeRTOS系统延时函数vTaskDelay导致看门狗复位的情况
@2019-04-09 [问题] 控制程序工作一段时间异常重启 [分析] 经定位分析重启原因为看门狗复位导致 [解决] 经排查发现在中断服务函数中使用了FreeRTOS的系统时延函数vTaskDela ...