惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Check Point Blog
GbyAI
GbyAI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
U
Unit 42
美团技术团队
NISL@THU
NISL@THU
C
Cisco Blogs
SecWiki News
SecWiki News
N
Netflix TechBlog - Medium
Forbes - Security
Forbes - Security
Cloudbric
Cloudbric
雷峰网
雷峰网
T
Tailwind CSS Blog
博客园 - 司徒正美
The Register - Security
The Register - Security
L
LangChain Blog
S
Security Affairs
Hacker News - Newest:
Hacker News - Newest: "LLM"
B
Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
Threat Research - Cisco Blogs
I
InfoQ
S
Schneier on Security
L
Lohrmann on Cybersecurity
量子位
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Martin Fowler
Martin Fowler
Schneier on Security
Schneier on Security
F
Fortinet All Blogs
TaoSecurity Blog
TaoSecurity Blog
K
Kaspersky official blog
Google DeepMind News
Google DeepMind News
Cisco Talos Blog
Cisco Talos Blog
PCI Perspectives
PCI Perspectives
Attack and Defense Labs
Attack and Defense Labs
WordPress大学
WordPress大学
Microsoft Azure Blog
Microsoft Azure Blog
H
Help Net Security
Project Zero
Project Zero
The GitHub Blog
The GitHub Blog
D
Docker
N
News | PayPal Newsroom
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
H
Hacker News: Front Page
云风的 BLOG
云风的 BLOG
Microsoft Security Blog
Microsoft Security Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 聂微东
Webroot Blog
Webroot Blog
MongoDB | Blog
MongoDB | Blog

博客园 - 俩醒叁醉

ASP.NET MVC 4 WebAPI. Support Areas in HttpControllerSelector SQL2000安装问题(转) sql server 2008安装需要一直重启。但重启后又没有达到效果。 为数据库中所有的用户数据表生成分页存储过程 SQL 2005 字段备注获取 __doPostBack方法解析 如何在三个月掌握三年的经验(转载&&笔记) jQuery Ajax的使用 JQuery资源网站 Cookie跨域、虚拟目录 深入分析跨域cookie的问题 CnBlogsDotText使用实例 轻松搭建博客平台-开源ASP.NET 博客Subtext 的安装 表达式目录树(源MSDN) Web 2.0 编程思想:16条法则 Control Adapter URL Routing MVC Controllers和Forms验证 CSharp——Lambda 表达式
以下代码提供查询数据库中是否存在某个值
俩醒叁醉 · 2009-03-15 · via 博客园 - 俩醒叁醉

----找到用户表的所有字段
--  SELECT  name,object_name(id) from dbo.syscolumns 
--  where OBJECTPROPERTY(id, 'IsTable') =1 and OBJECTPROPERTY(id, 'IsSystemTable') =0
-- select name,id,xtype from dbo.sysobjects where xtype='U'
/*
常用数据类型
('uniqueidentifier','tinyint','smallint','int','smalldatetime','real'
,'money','datetime','float','bit','decimal','numeric','smallmoney','bigint',
'varbinary','varchar','binary','char','nchar','nvarchar')
常用数据类型ID
(36,48,52,56,58,59,60,61,62,104,106,108,122,127,165,167,173,175,239,231)
特殊类型
(34,35,99,189,231,98)
('image','text','ntext','timestamp','sysname','sql_variant')
*/

/*
----------------------------------------------------------------------------------------------
以下代码提供查询数据库中是否存在某个值
其中:字段类型为以下中的一个('uniqueidentifier','tinyint','smallint','int','smalldatetime','real'
,'money','datetime','float','bit','decimal','numeric','smallmoney','bigint',
'varbinary','varchar','binary','char','nchar','nvarchar')
由于cast方法接受最长(nvarchar(128)),所以对某些长字段会出问题.
----------------------------------------------------------------------------------------------
*/

declare @value nvarchar(250)
declare @columnName nvarchar(255)
declare @tableName nvarchar(255)
declare @sql nvarchar(4000)
declare @findCount int
declare @printMessage nvarchar(255)

declare myCursor cursor for
SELECT  name,object_name(id) from dbo.syscolumns 
where OBJECTPROPERTY(id, 'IsTable') =1 and OBJECTPROPERTY(id, 'IsSystemTable') =0
         and xtype in (36,48,52,56,58,59,60,61,62,104,106,108,122,127,165,167,173,175,239,231)
set @value='--´  --待查询的值(转换为nvarchar类型)
open myCursor
fetch next from myCursor into @columnName, @tableName

while @@fetch_status=0
begin
    set @findCount=0
set @sql=' select @Count = count(*) from '+@tableName
+' where charindex('''+@value+''',cast('+@columnName+' as nvarchar(125)))>0'
    exec sp_executesql @sql, N'@Count int output', @findCount output 
    set @printMessage ='表名'+@tableName+'-列名º'+@columnName
    if (@findCount >0)
begin
          set @sql =Replace(@sql,' @Count = count(*) ',' * ')
          print @printMessage
          exec sp_executesql @sql
end
    set @findCount =0
fetch next from myCursor into @columnName, @tableName
end
close myCursor
deallocate myCursor