declare @temp table
(
[id] int IDENTITY(1,1),
[Name] varchar(10)
)
declare @tempId int,@tempName varchar(10)
insert into @temp values('a')
insert into @temp values('b')
insert into @temp values('c')
insert into @temp values('d')
insert into @temp values('e')
WHILE EXISTS(select [id] from @temp)
begin
select top 1 @tempId = [id],@tempName=[Name] from @temp
delete from @temp where [id] = @tempId
print 'Name:----'+@tempName
end
本文介绍了一个使用T-SQL创建和操作临时表的例子。通过声明一个包含身份字段的临时表,并进行插入、选择及删除操作来展示如何管理和遍历临时表中的数据。
421

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



