(Mysql) Insert or Update in the database

Asked

Viewed 7,523 times

2

I need to perform one Insert in the database, if there is no Cpf of a person. if there is it has to do a Update. But all this through a single script on Mysql. I illustrated the example below as I am doing today:

1 If the entity Cpf (not the primary code) does not exist, then I need to execute according to SQL below:

insert into entidade (cpf, nome, email) values (11111111111, 'robson', 'email')

2 If the CPF exists, then I will only update the data as per SQL below:

update entidade set nome = 'robson', email = 'email' where cpf = 11111111111

There is the possibility that this is a single SQL ?

1 answer

6


Browser other questions tagged

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