Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Stored procedure inserting in multiple tables orphans records. How to handle

$
0
0

I have stored procedure that inserts information into a login table and a announcer table. I have realized that when insertion into the announcer fails, a record was inserted into the login table, leaving orphans records into the login table.

    create procedure [publico].[cadastrar_login_Loja] @email char(40), @senha char(10),   @CNPJ char(10),  @Endereco char(40),  @bairro char(40),  @Estado tinyint, @cidade tinyint,  @cep char(20) ,  @RazaoSocial char(50), @NomeFantasia char(50), @Telefone1
char(15), @Telefone2 char(15), @celular1 char(15), @Celular2 char(15), @Website char(50), @dir char(4)

      as    

      begin   
    
      
      insert into producao.LoginsLojas ( NomeUsuario,Senha) values (@email, @senha);



      insert into producao.Lojas(  cnpj, endereco, bairro, estado, Cidade,  cep, razaosocial, nomefantasia, telefone1, telefone2, celular1, celular2, website, email, dir)

      values (  @cnpj, @endereco, @bairro, @estado, @cidade,  @cep, @razaosocial, @nomefantasia, @telefone,@telefone2, @celular1, @celular2, @website,@email, @dir)
      end

as you can see, the sp just perform two inserts. How do I handle that? I have studied this scenario before, but I can't remember!

Thanks!       


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>