临时表删除行

4

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


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
4个回答

11
您可以从临时表中删除数据。只是您的语法似乎有误。
请尝试以下语法:

--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 

代码运行正确,但我不明白为什么我的示例无法工作。 - Rafał Developer
这是一个语法问题。很高兴它能帮到你! - Semih Yagcioglu

2
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 

1
DELETE T (SELECT * FROM @tbl2) T WHERE T.Id = 1

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;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接