加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

在SQLServer里面判断各种存在的条件

发布时间:2020-12-12 14:48:08 所属栏目:MsSql教程 来源:网络整理
导读:--判断数据库是否存在? if ? exists(select ? * ? from ? master..sysdatabases ? where ? name=N '库名 ')? ? ? print ? 'exists '? else? ? ? print ? 'not ? exists '? ---------------? -- ? 判断要创建的表名是否存在? if ? exists ? (select ? * ? fro
--判断数据库是否存在? if ? exists(select ? * ? from ? master..sysdatabases ? where ? name=N '库名 ')? ? ? print ? 'exists '? else? ? ? print ? 'not ? exists '? ---------------? -- ? 判断要创建的表名是否存在? if ? exists ? (select ? * ? from ? dbo.sysobjects ? where ? id ? = ? object_id(N '[dbo].[表名] ') ? and ? OBJECTPROPERTY(id,? N 'IsUserTable ') ? = ? 1)? -- ? 删除表? drop ? table ? [dbo].[表名]? GO? ---------------? --判断要创建临时表是否存在? If ? Object_Id( 'Tempdb.dbo.#Test ') ? Is ? Not ? Null? ? ? ? ? Begin? ? ? ? ? ? ? print ? '存在 '? ? ? ? ? End? Else? ? ? ? ? Begin? ? ? ? ? ? ? print ? '不存在 '? ? ? ? ? End? ---------------? -- ? 判断要创建的存储过程名是否存在? if ? exists ? (select ? * ? from ? dbo.sysobjects ? where ? id ? = ? object_id(N '[dbo].[存储过程名] ') ? and ? OBJECTPROPERTY(id,? N 'IsProcedure ') ? = ? 1)? -- ? 删除存储过程? drop ? procedure ? [dbo].[存储过程名]? GO? ---------------? -- ? 判断要创建的视图名是否存在? if ? exists ? (select ? * ? from ? dbo.sysobjects ? where ? id ? = ? object_id(N '[dbo].[视图名] ') ? and ? OBJECTPROPERTY(id,? N 'IsView ') ? = ? 1)? -- ? 删除视图? drop ? view ? [dbo].[视图名]? GO? ---------------? -- ? 判断要创建的函数名是否存在? if ? exists ? (select ? * ? from ? dbo.sysobjects ? where ? id ? = ? object_id(N '[dbo].[函数名] ') ? and ? xtype ? in ? (N 'FN ',? N 'IF ',? N 'TF '))? -- ? 删除函数? drop ? function ? [dbo].[函数名]? GO

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读