临时表删除行

时间:2013-05-09 08:41:29

标签: sql tsql

为什么我无法从临时表中删除行?

DECLARE @tbl2 TABLE
    (
    Id int,
    ImieNazwisko varchar(200),
    Pesel varchar(200),
    Kod varchar(200)
    )

DELETE FROM @tbl2 tblT WHERE tblT
SELECT * FROM @tbl2

这也不起作用:

DELETE FROM @tbl2 WHERE @tbl2.Id

3 个答案:

答案 0 :(得分:7)

您可以从临时表中删除。这只是你的语法似乎错了。

试试这个:

--drop table #temptable 
create table #temptable (Id int)
insert into #temptable 
select 1 union
select 2 union 
select 3 

delete from #temptable 
where Id =2

select Id from #temptable 

答案 1 :(得分:1)

DECLARE @tbl2 TABLE
    (
    Id int,
    ImieNazwisko varchar(200),
    Pesel varchar(200),
    Kod varchar(200)
    )

DELETE FROM @tbl2 tblT WHERE tblT.ID  = 1  --- for single row delete 
SELECT * FROM @tbl2

- 根据您的情况,您要删除表格中的所有数据,我认为它应该是

delete from @tbl2 -- only 

答案 2 :(得分:0)

drop table if exists Locations;
Create temporary table Locations
SELECT au_lname, au_fname, 
CASE 
WHEN state = "CA" or state = "AZ" THEN "west side"
WHEN state = "UT" or state = "MI" or state = "TN" THEN "mid US"
ELSE "east side"
END AS LocationInTheUS 
FROM authors
order by LocationInTheUS desc;
delete from Locations where au_lname = " ";
select * from Locations;