SQL Server中判断数据库是否存在:
法(一):

    select * From master.dbo.sysdatabases where name='数据库名'

  法(二):
if db_id('数据库名') is not null

      drop database 。。。
   go

    create 。。。

SQL Server中判断表对象是否存在:
select count(*) from sysobjects where id = object_id('数据库名.Owner.表名')

  if exists

     (select count(*) from sysobjects where id = object_id('数据库名.Owner.表名'))
print '存在'
else
print '不存在'

SQL Server中判断表中字段是否存在:
if exists

      (select * from syscolumns where name='colname1' and id=object_id('数据库名.Owner.表名'))
print '存在'
else
print '不存在'
(代表表tablename1中存在colname1字段 )
例:
  select * from syscolumns where name='Test' and id=object_id('dbo.test')

SQL Server中判断存储过程或视图是否存在:

  if object_id('视图或存储过程名')  is not null
     drop proc/view 。。。
go

   create proc/view  。。。

  或

  if Exists(select * from sysobjects where name='视图或存储过程名'  AND  type  =  'P/V')
     drop proc/view  。。。
go

  create proc/view  。。。

本文转自贺满博客园博客,原文链接:http://www.cnblogs.com/puresoul/archive/2010/03/21/1691004.html,如需转载请自行联系原作者。

Sql Server中判断表或者数据库是否存在相关推荐

  1. SQL Server中的表变量

    In this article, we will explore the table variable in SQL Server with various examples and we will ...

  2. 如何列出引用SQL Server中给定表的所有外键?

    我需要在SQL Server数据库中删除一个高度引用的表. 我如何获取要删除表需要删除的所有外键约束的列表? (与在Management Studio的GUI中单击相比,SQL的答案更好.) #1楼 ...

  3. SQL Server中公用表表达式 CTE 递归的生成帮助数据,以及递归的典型应用

    原文: SQL Server中公用表表达式 CTE 递归的生成帮助数据,以及递归的典型应用 本文出处:http://www.cnblogs.com/wy123/p/5960825.html 我们在做开 ...

  4. SQL Server 中4个系统数据库,Master、Model、Msdb、Tempdb

    SQL Server 中4个系统数据库,Master.Model.Msdb.Tempdb master   数据库       master   数据库记录   SQL   Server   系统的所 ...

  5. SQL Server 中4个系统数据库详细介绍

    SQL Server 中4个系统数据库,Master.Model.Msdb.Tempdb. (1)Master数据库是SQL Server系统最重要的数据库,它记录了SQL Server系统的所有系统 ...

  6. sql中替换逗号为换行符_使用T-SQL将逗号或其他定界符转换为SQL Server中的表或列表

    sql中替换逗号为换行符 Database developers often need to convert a comma-separated value or other delimited it ...

  7. 如何在SQL Server中比较表

    介绍 (Introduction) If you've been developing in SQL Server for any length of time, you've no doubt hi ...

  8. 在SQL server中设置表的自动编号功能

    我们都知道很多的数据库软件都为表提供了自动编号的功能,这对于进行有些表的功能是十分有用 的,可以减少很多不必要工作,由于SQL server是我最近才使用的所以,在这个过程中遇到了一些问题,但是经过查 ...

  9. Sql Server中判断日志是否为一个星期

    1.引出问题 SQL Server中默认将星期天做为一个星期的第一天,如果你查询以下语句: select Datediff(week,'2010/12/12','2010/12/13') 2010/1 ...

最新文章

  1. android释放acitity内存,Android 内存泄漏分析与解决方法
  2. p2v、v2v 转换-windows篇
  3. Python游戏开发pygame模块,Python实现吃豆人,儿时的回忆
  4. HDU - 6082 度度熊与邪恶大魔王(背包变式)
  5. centos 对某ip开放 防火墙端口_CentOS防火墙iptables限制端口和来源IP地址访问的配置...
  6. pfa是什么意思_PFA的完整形式是什么?
  7. python-双层嵌套循环-打印小星星
  8. CF #371 (Div. 2) C、map标记
  9. 音视频开发基础(二)常用的直播协议
  10. Android Thread 官方说明
  11. ROS1节点,消息,话题,服务的介绍
  12. react-native 解决“Could not get BatchedBridge...” 的问题
  13. WIN32汇编 状态栏的使用
  14. SQL prompt无法激活跳转到127.0.0.1:22223的解决方案
  15. 【SENCHA TOUCH】Sencha Touch ExtJs 给 Button 添加图片(二)
  16. 小白量化《穿云箭集群量化》(3)量化策略编写(2)
  17. android xutils3 jar,Android全能开源项目xUtils3开发教程、简单封装
  18. 入侵修改服务器内容,怎么入侵服务器修改数据库
  19. 视频教程-微信公众平台开发入门-微信开发
  20. chrome浏览器表单自动填充默认样式-autofill设置

热门文章

  1. Zabbix4.2对IIS监控摸索记录
  2. ClassNotFoundException和NoClassDefFoundError的区别
  3. C#连接Oracle数据库的方法(Oracle.DataAccess.Client也叫ODP.net)
  4. CSS:超出部分省略号
  5. Android View体系(十)自定义组合控件
  6. MongoDB探索之路(二)——系统设计之CRUD
  7. Modelsim初级使用教程
  8. 解决更新到os x10.11后openssl头文件无法找到的问题
  9. MySQL语法大全_自己整理的学习笔记
  10. ADO.Net的小知识(连接数据库)二