- 數(shù)據(jù)庫(kù)
法(一):
select * From master.dbo.sysdatabases where name='數(shù)據(jù)庫(kù)名'
法(二):
if db_id('數(shù)據(jù)庫(kù)名') is not null
drop database 。。狐榔。
go
create 柳琢。牍帚。晶衷。
- 表對(duì)象
select count(*) from sysobjects where id = object_id('數(shù)據(jù)庫(kù)名.dbo.表名')
if exists (select count(*) from sysobjects where id = object_id('數(shù)據(jù)庫(kù)名.dbo.表名'))
print '存在'
else
print '不存在'
- 表中字段
if exists(select * from syscolumns where name='colname1' and id=object_id('數(shù)據(jù)庫(kù)名.dbo.表名'))
print '存在'
else
print '不存在'
(代表表tablename1中存在colname1字段 )
例:select * from syscolumns where name='Test' and id=object_id('dbo.test')
- 存儲(chǔ)過(guò)程或視圖
if object_id('視圖或存儲(chǔ)過(guò)程名') is not null
drop proc/view 嗽元。沧烈。掠兄。
go
create proc/view 。锌雀。蚂夕。
或
if Exists(select * from sysobjects where name='視圖或存儲(chǔ)過(guò)程名' AND type = 'P/V')
drop proc/view 。汤锨。双抽。
go
create proc/view 。闲礼。牍汹。