4
I need to include a record in a table, however before inclusion to avoid duplicity it is necessary to do a check.
As I have a column ID
with as property AUTO INCREMENT
, I can’t use the INSERT IGNORE INTO
.
Table
CREATE TABLE relacao (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_1 varchar(24) NOT NULL,
user_2 varchar(24) NOT NULL
)
Example
INSERT INTO relacao(user_1, user_2) values("Pedro", "Laura")
INSERT INTO relacao(user_1, user_2) values("Pedro", "Laura") /* não deixar inserir*/
How would the query
to check whether or not the record exists before insertion?
You will insert the data directly into mysql, or you will use some script for this?
– Leo Letto
@Leoletto Preferably the check is directly in Mysql. Example: If it doesn’t exist: insert, else: do nothing.
– viana