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

推荐订阅源

D
Darknet – Hacking Tools, Hacker News & Cyber Security
Jina AI
Jina AI
博客园_首页
J
Java Code Geeks
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
Hugging Face - Blog
Hugging Face - Blog
S
SegmentFault 最新的问题
MyScale Blog
MyScale Blog
P
Proofpoint News Feed
L
Lohrmann on Cybersecurity
Forbes - Security
Forbes - Security
大猫的无限游戏
大猫的无限游戏
Vercel News
Vercel News
Y
Y Combinator Blog
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
N
News | PayPal Newsroom
S
Security Archives - TechRepublic
量子位
Cisco Talos Blog
Cisco Talos Blog
V
V2EX
C
Cisco Blogs
The Cloudflare Blog
Stack Overflow Blog
Stack Overflow Blog
L
LangChain Blog
Scott Helme
Scott Helme
S
Securelist
Security Latest
Security Latest
爱范儿
爱范儿
TaoSecurity Blog
TaoSecurity Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
I
Intezer
L
LINUX DO - 最新话题
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
Check Point Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
美团技术团队
Know Your Adversary
Know Your Adversary
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
PCI Perspectives
PCI Perspectives
月光博客
月光博客
T
Tailwind CSS Blog
Cloudbric
Cloudbric
小众软件
小众软件
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
K
Kaspersky official blog
D
DataBreaches.Net
博客园 - 【当耐特】
有赞技术团队
有赞技术团队

博客园 - 顽石

How to run explorer.exe as another user 【转载】如何修改MSDE的登录方式及sa密码 【转载】windows 2008 r2 AD密码策略 无法启动wicrosoft office outlook ,无法打开outlook窗口 问题的解决 C#获取路径 Refactoring--1 [转载]程序员能力矩阵 你属于哪一层? 如何用visual studio 2005 编写C语言程序 EXCHANGE2007安装及备份还原操作手册 [转载]PowerShell 经典脚本贮藏室 【转载】全程图解--教你如何做RAID磁盘阵列 - 顽石 【转载】易学易用的Windows PowerShell 【转载】不一样的命令行 – Windows PowerShell简介 【转载】RAID扫盲 安装SQL SERVER 2005 SP3 问题及解决方案 在尝试安装 SQL Server 2005 Service Pack 或 SQL Server 2005 修补程序包时出现错误消息:“Error 29528. The setup has encountered an unexpected error while Setting Internal Properties”(错误 29528。安装程序在设置内部属性时遇到错误) [转载]IIS出现“另一个程序正在使用此文件,进程无法访问。”解决办法 Announcing SharePoint Server 2010 Preliminary System Requirements [转载]在Vista上安装MOSS2007
【转载】Sql中判断"数据库"、"表"、"临时表"、"存储过程"和列"是否存在
顽石 · 2010-06-03 · via 博客园 - 顽石

转载自:http://www.cnblogs.com/icebutterfly/archive/2010/05/27/1745686.html

--判断数据库是否存在
IF EXISTS (SELECT * FROM MASTER..sysdatabases WHERE NAME = '库名')
    PRINT 'exists '
else
    PRINT 'not exists'

--   判断要创建的表名是否存在
IF EXISTS (Select * From sysObjects Where Name ='表名' And Type In ('S','U'))
PRINT 'exists'
ELSE
PRINT 'not exists'
GO

--判断要创建临时表是否存在
If   Object_Id( 'Tempdb.dbo.#Test')   Is   Not   NULL--#Test 为临时表名
        Begin
            print   '存在 '
        End
Else
        Begin
            print   '不存在 '
        End

---------------
--   判断要创建的存储过程名是否存在
IF EXISTS (Select * From sysObjects Where Name ='存储过程名' And Type In ('S','P'))
PRINT 'exists'
ELSE
PRINT 'not exists'
GO
--   判断列名是否存在
IF  EXISTS (SELECT   O.NAME AS 表名,C.NAME AS 列名
FROM SYSOBJECTS O INNER JOIN SYSCOLUMNS C ON O.ID=C.ID
WHERE O.NAME= '表名' AND C.NAME   = '列名')
SELECT 'EXISTS'
ELSE
SELECT 'NOT EXISTS'

判断表名存在的一个函数

IF COL_LENGTH( '表名','列名') IS NULL
    PRINT 'not exists'
ELSE
PRINT 'exists'

注:a 是一个表,U代表是数据表类型

类似于U的类型代码,如下所示

对象类型:

AF = 聚合函数 (CLR)

C = CHECK 约束

D = DEFAULT(约束或独立)

F = FOREIGN KEY 约束

PK = PRIMARY KEY 约束

P = SQL 存储过程

PC = 程序集 (CLR) 存储过程

FN = SQL 标量函数

FS = 程序集 (CLR) 标量函数

FT = 程序集 (CLR) 表值函数

R = 规则(旧式,独立)

RF = 复制筛选过程

SN = 同义词

SQ = <strong class="kgb" onmouseover="isShowAds = false;isShowAds2 = false;isShowGg = true;InTextAds_GgLayer="_u670D_u52A1";KeyGate_ads.ShowGgAds(this,"_u670D_u52A1",event)" style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; font-weight: normal; border-left-width: 0px; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; cursor: hand; color: #0000ff; padding-top: 0px; border-right-width: 0px; text-decoration: underline" onclick="javascript:window.open("http://www.google.com/aclk?sa=L&ai=Bh2rlOAWHR56sBozu6AOroqCAC5_q_jCXvsOWA_iU2JQFwKkHEAIYAiCvmqoJKAM4AVDrnYft_f____8BYJ3h24HQBaoBCjEwMDAwMTYwMDLIAQHIAo-anALZAwUzhILJ-9To&num=2&q=http://www2.tek.com/cnweb/products/oscilloscopes/%3FWT.srch%3D1%26WT.mc_id%3Dppc,ggl,scope_aw_ch_cn_scope,k171E,s,766361139%26&sig=AGiWqtxyWRPsXCeA4J63cbgSQs3krP7s8Q");GgKwClickStat("服务","www.tektronix.com.cn","afs","1000016002");" onmouseout="isShowGg = false;InTextAds_GgLayer="_u670D_u52A1"">服务队列

TA = 程序集 (CLR) DML <strong class="kgb" onmouseover="isShowAds = false;isShowAds2 = false;isShowGg = true;InTextAds_GgLayer="_u89E6_u53D1_u5668";KeyGate_ads.ShowGgAds(this,"_u89E6_u53D1_u5668",event)" style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; font-weight: normal; border-left-width: 0px; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; cursor: hand; color: #0000ff; padding-top: 0px; border-right-width: 0px; text-decoration: underline" onclick="javascript:window.open("http://www.google.com/aclk?sa=l&ai=BQIoCOAWHR56sBozu6AOroqCAC5iBlTOIz87RBPDWtnnAmgwQARgBIK-aqgkoAzABOAFQ7tXJy_7_____AWCd4duB0AWgAaqp9v4DqgEKMTAwMDAxNjAwMsgBAcgC6MOOAdkDBTOEgsn71OjgAxA&num=1&q=http://toolbar.google.com/T4/intl/zh-CN/%3Futm_campaign%3DzhCN%26utm_source%3DzhCN-ha-ww-google%26utm_medium%3Dha%26utm_term%3D%25E5%25B7%25A5%25E5%2585%25B7%26tbbrand%3DGZAZ&sig=AGiWqtzKjiNgl3U7aRUdC4tjyZq0F7XBBQ");GgKwClickStat("触发器","toolbar.google.com/zh-CN","afs","1000016002");" onmouseout="isShowGg = false;InTextAds_GgLayer="_u89E6_u53D1_u5668"">触发器

TR = SQL DML 触发器

IF = SQL 内联表值函数

TF = SQL 表值函数

U = 表(用户定义类型)

UQ = UNIQUE 约束

V = 视图

X = 扩展存储过程

IT = 内部表