- 數(shù)據(jù)庫
法(一):
select * From master.dbo.sysdatabases where name='數(shù)據(jù)庫名'
法(二):
if db_id('數(shù)據(jù)庫名') is not null
drop database 弥姻。候址。盖矫。
go
create 。务蝠。拍谐。
- 表對象
select count(*) from sysobjects where id = object_id('數(shù)據(jù)庫名.dbo.表名')
if exists (select count(*) from sysobjects where id = object_id('數(shù)據(jù)庫名.dbo.表名'))
print '存在'
else
print '不存在'
- 表中字段
if exists(select * from syscolumns where name='colname1' and id=object_id('數(shù)據(jù)庫名.dbo.表名'))
print '存在'
else
print '不存在'
(代表表tablename1中存在colname1字段 )
例:select * from syscolumns where name='Test' and id=object_id('dbo.test')
- 存儲過程或視圖
if object_id('視圖或存儲過程名') is not null
drop proc/view 。馏段。轩拨。
go
create proc/view 。院喜。亡蓉。
或
if Exists(select * from sysobjects where name='視圖或存儲過程名' AND type = 'P/V')
drop proc/view 。喷舀。砍濒。
go
create proc/view 。硫麻。爸邢。