Sql Server中如何判斷表中某欄位是否存在

2022-09-14 06:15:13 字數 682 閱讀 4610

--比如說要判斷表a中的字段c是否存在兩個方法:    

一,

if exists (

select 1from sysobjects t1

inner join syscolumns t2 on t1.id=t2.id

where t1.name='a' and t2.name='c')

print '存在'else

print '不存在'二, 短小精悍,可謂精典

if col_length('a', 'c') is not null

print n'存在'else

print n'不存在'方法一:

select * from syscolumns where id=object_id('表名') and name='列名'說明:存在則返回此列的一條說明記錄,不存在返回空;

方法二:

select count(*) from sysobjects a,syscolumns b where a.id=b.id and b.name='flag1' and a.type='u' and a.name='t_pro_productclass'說明:存在返回1,不存在則返回0

SQL Server 中如何判斷表是否存在

sql server資料庫中表等物件都儲存在sysobjects資料表中,臨時表被儲存於tempdb資料庫中 1.判斷普通表是否存在,可以使用object id函式,它可以根據物件名稱返回物件的id if select object id tablename is notnull select tr...

Sql Server中如何判斷表中某列是否存在

比如說要判斷表a中的字段c是否存在兩個方法 一,if exists select 1 from sysobjects t1 inner join syscolumns t2 on t1.id t2.id where t1.name a and t2.name c print 存在 else prin...

Sqlserver中判斷表是否存在

在sqlserver 應該說在目前所有資料庫產品 中建立乙個資源如表,檢視,儲存過程中都要判斷與建立的資源是否已經存在 在sqlserver中一般可通過查詢sys.objects系統表來得知結果,不過可以有更方便的方法 如下 if object id tb table is not null pri...