SQL Server : stored procedure transaction

前端 未结 4 1409
时光说笑
时光说笑 2020-12-28 15:45

Hello I got some stored procedures to create products and other stuff on my site. Now I have to run some of them in a transaction. Is that possible or do I have to make a st

4条回答
  •  萌比男神i
    2020-12-28 16:12

    Yes, a stored procedure can be run inside a transaction. Please find below a sample query.

    create table temp1
    (
        id int,
        name varchar(20)
    )
    
    create table temp2
    (
        id int,
        name varchar(20)
    )
    go
    
    create proc p1 as
    insert temp1 values (1, 'test1')
    
    
    create proc p2 as 
    insert temp2 values (1, 'test2')
    go  
    
    begin tran tx
    exec p1
    exec p2
    commit
    

提交回复
热议问题