Sql Server 语句集合

 

-- 判断数据库表是否存在
select count(*) from sysobjects where id=OBJECT_ID('tableName');
-- 返回 1存在,0不存在

-- 判断表字段是否存在
select count(*) from syscolumns where id=OBJECT_ID('tableName') and name='colName';
-- 返回1 存在,0不存在

-- 判断字段索引是否存在
select count(*) from sys.indexes where name='indexName';
-- 返回1存在,0不存在
相关文章
相关标签/搜索