Skip to Content
0
Former Member
Nov 16, 2016 at 10:07 AM

Table variables don't work with deletes ?

720 Views Last edit Nov 16, 2016 at 10:23 AM 2 rev

Yet another problem table variables.

I'm using Sybase 16, SP02, PL04.

Try this...

12 rows in a @table, I delete 4 row and an extra 8 rows lost.

Is this feature reliable ?

declare @test table (id int not NULL, colid int not NULL)
insert into @test values ( 1, 1 )
insert into @test values ( 2, 1 )
insert into @test values ( 3, 1 )
insert into @test values ( 4, 1 )
insert into @test values ( 1, 2 )
insert into @test values ( 2, 2 )
insert into @test values ( 3, 2 )
insert into @test values ( 4, 2 )
insert into @test values ( 1, 3 )
insert into @test values ( 2, 3 )
insert into @test values ( 3, 3 )
insert into @test values ( 4, 3 )
insert into @test values ( 1, 4 )
insert into @test values ( 2, 4 )
insert into @test values ( 3, 4 )
insert into @test values ( 4, 4 )
select colid, count(1) from @test group by colid order by colid
delete @test where colid = 2
select "deleted ", @@rowcount
select colid, count(1) from @test group by colid order by colid