天天看點

SQL查詢某表是否存在及傳回新增資料的ID

    下面簡單介紹了SQL查詢某表是否存在以及傳回新增資料的ID值。

1.查詢表是否存在:

表名:“t_Demo”, type = 'u'  檢視是不是使用者表

select * from sysobjects where id = object_id('t_Demo') and type = 'u'
select * from sys.tables where name='t_Demo' and type = 'u'      

2.查詢字段是否存在:

表名:“t_Demo”, 字段名“DemoID”

select * from syscolumns where name='DemoID' and objectproperty(id,'IsUserTable')=1 andobject_name(id)='t_Demo'      
select max(NdsID) from tb_Nds