--表变量定义自动增加字段,定义主键
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 )
本文演示了如何使用T-SQL定义包含自动增长字段的表变量,并将其作为主键的一部分。此外,还介绍了如何通过子查询检查表中数据的存在性。
3913

被折叠的 条评论
为什么被折叠?



