

drop table Employee
drop table Employee2

create table Employee
( 
	pkId int primary key identity(1,1) ,
	empName varchar(50)
)


create table Employee2
( 
	pkId int primary key identity(1,1) ,
	empName varchar(50)
)

insert into Employee
select 'John'
union
select 'Steve'

select * from Employee

insert into Employee2
select 'Mary'




select * from Employee
select * from Employee2


--Incomplete Transaction
--Run a transaction and update the table without committing the transaction, which will
--cause this process maintain a lock on Employee
Begin tran
update Employee set empName = 'John Smith'
where pkId = 1


Begin tran
update Employee2 set empName = 'Geno Smith'
--where pkId = 1


--Wrap a statement in a transction an use logic to determine wether to commit or not

Begin tran
update Employee set empName = 'John Smith2'
where pkId = 1



IF @@ROWCOUNT = '1'
Begin
	print 'Committed transaction'
	Commit tran
End
ELSE
Begin
	rollback tran
	print 'RolledBack transaction'
End

