• 判断是否存在


    
    
    1 判断数据库是否存在
    
    if exists (select * from sys.databases where name = '数据库名')  
      drop database [数据库名]  
    if exists (select * from sys.databases where name = '数据库名')
      drop database [数据库名]
    2 判断表是否存在
    if exists (select * from sysobjects where id = object_id(N'[表名]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)  
      drop table [表名]  
    if exists (select * from sysobjects where id = object_id(N'[表名]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
      drop table [表名]
    3 判断存储过程是否存在
    if exists (select * from sysobjects where id = object_id(N'[存储过程名]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)  
      drop procedure [存储过程名]  
    if exists (select * from sysobjects where id = object_id(N'[存储过程名]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
      drop procedure [存储过程名]
    4 判断临时表是否存在
    if object_id('tempdb..#临时表名') is not null    
      drop table #临时表名  
    if object_id('tempdb..#临时表名') is not null  
      drop table #临时表名 
    5 判断视图是否存在
    --SQL Server 2000   
    IF EXISTS (SELECT * FROM sysviews WHERE object_id = '[dbo].[视图名]'  
    --SQL Server 2005   
    IF EXISTS (SELECT * FROM sys.views WHERE object_id = '[dbo].[视图名]'  
    --SQL Server 2000
    IF EXISTS (SELECT * FROM sysviews WHERE object_id = '[dbo].[视图名]'
    --SQL Server 2005
    IF EXISTS (SELECT * FROM sys.views WHERE object_id = '[dbo].[视图名]'
    6 判断函数是否存在
    --  判断要创建的函数名是否存在    
      if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[函数名]') and xtype in (N'FN', N'IF', N'TF'))    
      drop function [dbo].[函数名]    
    --  判断要创建的函数名是否存在  
      if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[函数名]') and xtype in (N'FN', N'IF', N'TF'))  
      drop function [dbo].[函数名]  
    
    
    
    IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[vMD_ProjectAdd]'))
    DROP VIEW [dbo].[vMD_ProjectAdd]
    GO
  • 相关阅读:
    HDFS文件操作(基本文件命令)
    <a> 标签
    css text-overflow
    zepto.js 打包自定义模块
    CSS3 box-sizing
    CSS3 Filter
    JQ 导出 Excel
    outline css2
    iphone 操作手势种类
    动手写一个简单的Web框架(模板渲染)
  • 原文地址:https://www.cnblogs.com/ggxiaomo/p/12291357.html
Copyright © 2020-2023  润新知