문제

I have field that it's not a key (it's text) and I want to insert row into table but only if there is no such field.

Is the way to do this on one query without need to call select first to check if there is row with this filed in table?

도움이 되었습니까?

해결책

two variants:

  1. You can add unique key to the TEXT field, you only should specify key length for the index.
  2. Create a BEFORE INSERT trigger, but in this case you have to call SELECT statement in the trigger.

다른 팁

You can use INSERT IGNORE INTO ..., it will turn all INSERT errors into warnings

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top