我知道約ON DUPLICATE USE KEY
條款。但我無法使用它,因爲我想在非唯一列上使用update
和insert
。更新列如果存在其他插入
我有table1
和table2
。我想在table1
上創建一個觸發器。
僞代碼:
IF id_code for corresponding id_name from table1 is present in table2
then update record in table 2
else record in table2.
對於防爆。
table1 has column1 id_code, column2 id_name
table2 has column1 id_code, column2 status
IF id_code for corresponding id_name from table1 is present in table2
UPDATE status column in table2.
ELSE insert id-code in table2
請參考這個http://stackoverflow.com/questions/4205181/insert-into-a-mysql-table-or-update-if-exists –
*「我想創建觸發器」* - 看一看在一些例子中:http://dev.mysql.com/doc/refman/5.7/en/trigger-syntax.html – axiac
創建一個觸發器,然後使用插入...在重複密鑰更新...內。 – Shadow