代码
--
查询数据库中是否存在某个表
if exists ( select * from sysobjects where name = ' 表名 ' )
-- 查询数据库中是否存在某个触发器
if exists ( select * from sysobjects where name = ' 触发器名 ' AND type = ' TR ' )
-- 查询数据库中是否存在某个外键
if exists ( select * from sysobjects where id = object_id (N ' 外键名 ' ) AND objectProperty (id, N ' IsForeignKey ' ) = 1 )
-- 查询表中是否存在某一列
if exists ( select 1 from syscolumns where id = object_id ( ' 表名 ' ) and name = ' 列名 ' )
if exists ( select * from sysobjects where name = ' 表名 ' )
-- 查询数据库中是否存在某个触发器
if exists ( select * from sysobjects where name = ' 触发器名 ' AND type = ' TR ' )
-- 查询数据库中是否存在某个外键
if exists ( select * from sysobjects where id = object_id (N ' 外键名 ' ) AND objectProperty (id, N ' IsForeignKey ' ) = 1 )
-- 查询表中是否存在某一列
if exists ( select 1 from syscolumns where id = object_id ( ' 表名 ' ) and name = ' 列名 ' )