CREATE TABLE [dbo].[emp]( [id] [int] IDENTITY(1,1) NOT NULL, [name] [varchar](50) NOT NULL ) ON [PRIMARY] GO
CREATE TABLE [dbo].[emp1]( [id] [int] IDENTITY(1,1) NOT NULL, [name] [varchar](50) NOT NULL ) ON [PRIMARY] GO
insert into emp (name) values ('a') insert into emp (name) values ('b') insert into emp (name) values ('c')
BEGIN TRAN select COUNT(*) from emp declare @NumRow int= 0 select @NumRow = count(id) from emp insert into emp1 (name) select name from emp IF (@@ROWCOUNT = @NumRow AND @@ROWCOUNT > 0 ) BEGIN COMMIT TRAN print 'Inserting Records..' delete from emp END ELSE BEGIN ROLLBACK TRAN print 'error occured while inserting record' END
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)