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

4 回答 4

10

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

尝试这个:

--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 
于 2013-05-09T08:47:54.670 回答
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 
于 2016-04-08T02:19:18.990 回答
1
DELETE T (SELECT * FROM @tbl2) T WHERE T.Id = 1
于 2021-08-19T15:14:09.200 回答
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;
于 2019-10-29T04:49:12.793 回答