1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| if exists (select * from sys.databases where name = ’数据库名’) drop database [数据库名]
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’IsProcedure’) = 1) drop procedure [存储过程名]
if object_id(’tempdb.. drop table 判断视图是否存在
IF EXISTS (SELECT * FROM sysviews WHERE object_id = ’[dbo].[视图名]’
IF EXISTS (SELECT * FROM sys.views WHERE object_id = ’[dbo].[视图名]’ IF EXISTS (SELECT * FROM sysviews WHERE object_id = ’[dbo].[视图名]’
IF EXISTS (SELECT * FROM sys.views WHERE object_id = ’[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].[函数名]
SELECT [name],[id],crdate FROM sysobjects where xtype=’U’
if exists(select * from syscolumns where id=object_id(’表名’) and name=’列名’) alter table 表名 drop column 列名
if columnproperty(object_id(’table’),’col’,’IsIdentity’)=1 print ’自增列’ else print ’不是自增列’
if exists(select * from sysindexes where id=object_id(’表名’) and name=’索引名’) print ’存在’ else print ’不存在
SELECT * FROM sys.sysobjects WHERE name=’对象名’
|