爲了更清楚:觸發一個行的一列的更新如果選擇部分匹配該行的列中的一
表thetable(id int, username varchar(30), password varchar(30), last_successful_login timestamp, last_unsuccessful_login timestamp, another_variable varchar(30))
具有下列行:(1,「TGH」,「傳」,0,0, 「其他」)
1)錯誤的用戶/密碼對,但與用戶名行
我想select id from thetable where username="tgh" and password="wrongpass" and another_variable="another";
更新所有的last_unsuccessful_login
列ŧ他排列着username="tgh"
和another_variable="another"
(這是唯一的,不能有兩行(「tgh」,「另一個」))。可以有(「tgh」,「another2」)。)到CURRENT_TIMESTAMP
。
所以行的例子是(1, "tgh", "pass", 0, CURRENT_TIMESTAMP, "another")
,的後「選擇」查詢沒有完全比賽。根據選擇的結果,我試圖避免在表格上僅運行username="tgh"
和another_variable="another"
的額外更新,即update thetable set last_unsuccessful_login=CURRENT_TIMESTAMP where username="tgh" and another_variable="another";
。
2)正確的用戶/密碼對
而且,如果所有的三個username
和password
和another_variable
比賽,這次我想設置的last_successful_login
到CURRENT_TIMESTAMP
。
這將使行的例子中`(1, 「TGH」, 「通」,CURRENT_TIMESTAMP,0, 「另一個」)
什麼是最有效的方式做到這一點?
什麼是你的表格結構? ('SHOW CREATE TABLE thetable'的結果)你想要什麼樣的觸發器:INSERT,UPDATE或DELETE? – Jocelyn 2012-08-14 22:23:00
我想我已經在問題中明確了所有問題,包括你問的問題。 – Etherealone 2012-08-14 23:55:02
你沒有。我不發表評論的樂趣。你的問題沒有說明你的表結構是什麼。而要理解你想做什麼幾乎是不可能的。另外,你的問題並沒有清楚地顯示你所嘗試過的。您有權拒絕更新您的問題。但是,不要驚訝沒有人可以幫助你或想幫助你。 – Jocelyn 2012-08-15 08:01:43