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个数据库,一个是 ...
随机推荐
- Android高版本联网失败报错:Cleartext HTTP traffic to xxx not permitted解决方法
前言:为保证用户数据和设备的安全,Google针对下一代 Android 系统(Android P) 的应用程序,将要求默认使用加密连接,这意味着 Android P 将禁止 App 使用所有未加密的 ...
- 【转】Android Hook框架Xposed详解
1 Introduction 1.1 概述 Xposed 是 GitHUB 上 rovo89 大大设计的一个针对 Android 平台的动态劫持项目,通过替换 /system/bin/app_pro ...
- Reason的介绍和搭建Reason开发环境
Reason介绍 Reason是在Ocaml语言的基础上修改而来,专门提供给前端开发者使用. Reason是函数式编程语言,使用Bucklescript编译器编译成javascript语言. 在我看来 ...
- 一、PHP概述 - PHP零基础快速入门
1) PHP 可以用来做什么? 我简单举几个例子: 网站建设: 微信公众号,微信小程序,小游戏的后端接口: 小工具类. 别着急,可能会觉得不知所云.简单来讲,PHP 可以编写计算机程序.程序的作用,简 ...
- 如何在sqlite3连接中创建并调用自定义函数
#!/user/bin/env python # @Time :2018/6/8 14:44 # @Author :PGIDYSQ #@File :CreateFunTest.py '''如何在sql ...
- storybook实践
很久之前就听说过storybook,一直想实践一下
- mysql-笔记-函数
如果不指定:sql-mode=ignore_space ,函数名与后面的括号之前不能有空格
- Debian社区群龙无首
导读 前两天有过消息 Debian 包维护者 Michael Stapelberg 因对 Debian 社区的现状不满而宣布退出 Debian 的维护,该消息引发了人们对于 Debian 的担忧.11 ...
- 存储类&作用域&生命周期&链接属性
链接属性 (1)大家知道程序从源代码到最终可执行程序,经历的过程:编译.链接. (2)编译阶段就是把源代码搞成.o目标文件,目标文件里面有很多符号和代码段.数据段.bss段等分段.符号就是编程中的变量 ...
- [2019.04.16] 由Python写成的自动解压脚本
很久很久以前(二十七天吧……大概)被要求写一个脚本来检索并解压磁盘上所有的以特定格式命名的tar文件,于是乎学习和摸鱼就一起开始了. 这次要写的脚本,针对的是这样的文件结构: 文件结构如上图所示 可以 ...