이 주제에 관한 일부 스레드를 읽고 너무 많이 시도했지만 코드가 작동하지 않습니다. 데이터 세트가 내 테이블에 이미있는 경우 두 번 삽입하지 않으려합니다.존재하지 않는 경우에만 mysql 삽입이 작동하지 않습니다.
일부 예제 데이터가있는 "WORD"테이블입니다 (id는 자동 증가).
id | customer_id | category_id | word | comment
1 3 5 life null
2 5 5 motor tbd
3 null 2 Day week
나는 customer_id, category_id, word 만 확인하고 싶습니다. 새 행이 정확히 동일한 customer_id, category_id 및 word를 갖고 있다면 삽입하고 싶지 않습니다. 댓글과 ID는 중요하지 않습니다.
내 코드 :.이 삽입
insert into word (customer_id, category_id, word)
select * from (select null, 2, 'Day') as tmp
where not exists (select * from word where customer_id=null and category_id=2 and word='Day')
limit 1
:( 그는 그것을 삽입되어 내가 널 (null)와 행 (ID = 3)이 있지만/2/일 새로운 삽입 한 코멘트 널 (null)을 가지고, 인접 해 께서 주석 주하지만,이 문제가되지 않습니다.
어디 내 실수?
이 답변을 확인하십시오. http://stackoverflow.com/questions/38399718/can-i-add-a-check-constraint-to-a-child-checking-the-value-of-its-parent- in-mysq/38400520 – Cherif