sql server判断数据库、表、列、视图是否存在
1 判断数据库是否存在 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 [表名] 3 判断存储过程是否存在 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 #临时表名 5 判断视图是否存在 --判断是否存在'MyView52'这个试图 IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'MyView52') PRINT '存在' else PRINT '不存在