表變量自動增加字段、主鍵的定義+exists使用例子

--表變量定義自動增加字段,定義主鍵

DECLARE @tmp2 table(id int IDENTITY(1,1),id2 int primary key(id))insert into @tmp2(id2) select top 100 id from book order by idselect * from @tmp2 order by id

--指定一個子查詢,測試行是否存在

select t.id from book t where exists(select 1 from @tmp2 where id2=t.id )

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章