sql清空临时表

来源:百度知道 编辑:UC知道 时间:2024/05/16 08:42:02
declare @tempTable table
(
idintidentity(1,1),
namevarchar(20)
)
这样的临时表, 要求清空数据并且标识列重新置为1,怎么处理?

你这不是临时表
create table #tempTable (id int identity(1,1),name varchar(20))

insert into #temptable(name)values('1')
insert into #temptable(name)values('1')
insert into #temptable(name)values('1')
select * from #temptable--看这里id是从1开始的

delete #temptable
DBCC CHECKIDENT (#temptable, RESEED, 0)--关键

insert into #temptable(name)values('2')
insert into #temptable(name)values('3')
insert into #temptable(name)values('3')
select * from #temptable--id重新从1开始

这是表变量,如果变量未失效的话,可以使用

truhncate table @tempTable

使标识列重置为1