Count inserted or deleted rows from a table

This code is safe to run on MSSQL query Manager; this is a quick overview of @@rowcount built in function

Declare @temp table (id int identity(1,1),descr varchar(10))
Insert into @temp 
Select 'Nothing registered for this insert'

Insert into @temp 
select @@ROWCOUNT as rowsinserted
select * from @temp
select @@ROWCOUNT as rowsselected

Delete from @temp where id in (1,2)
select @@ROWCOUNT as rowsdeleted

delete from @temp where id=3
select @@ROWCOUNT as rowsdeleted,
@@ERROR as error, 
@@IDENTITY as [last inserted ID]

select * from @temp

Related Posts

Comments are closed.