I can use two Insert into in the same command

Asked

Viewed 154 times

-1

i have the following line of code and wanted to know if it is possible to make two select within a single sql command

cmd = new MySqlCommand("insert into FUNCIONARIO(`CPF_FUNCIONARIO`, `NOME_FUNCIONARIO`, `RG_FUNCIONARIO `, `ENDEREÇO_FUNCIONARIO`, `NUMERO_FUNCIONARIO`, `BAIRRO_FUNCIONARIO`, `CEP_FUNCIONARIO`, `CIDADE_FUNCIONARIO`, `ADMISSÃO_FUNCIONARIO`, `DEMISSÃO_FUNCIONARIO`, `ID_CARGO`, `AUMENTO_FUNCIONARIO`) values(@CPF,@NOME,@RG,@ENDERECO,@NUMERO,@BAIRRO,@CEP,@CIDADE,@CARGO,@AUMENTO)  INSERT INTO `LOGIN`(`USUARIO_LOGIN`, `SENHA_LOGIN`, `CPF_FUNCIONARIO`) VALUES (@LOGIN,@SENHA,@CPF)", con);

1 answer

2


Yes, I do that a lot. besides separating values with "," you have to have exactly the same amount of parameters as all values sequences, e.g.:

insert into my_table (coluna1, coluna2,coluna3) 
            values   (@0,@1,@2),(@3,@4,@5),(@6,@7,@8)...;

If in some sequence of values you put two or a parameter will give error, it must always be 3 parameters because I set 3 columns.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.