大家好,我有一个带有时间戳列的产品库存表,因此对该行的任何更新都会更新时间戳,我对此设置感到满意,但有时我想在不更新时间戳的情况下更新行,那么如何编写更新特定列而不更新 lastUpdate 列的 mysql 语句?
这是我的声明:
update productsStock set productName="HP PRINTER 20000" where product_reference="001";
产品库存表说明
describe productsStock;
+--------------------+-----------------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+-----------------------+------+-----+-------------------+-----------------------------+
| productID | int(10) | NO | PRI | NULL | auto_increment |
| product_reference | varchar(255) | NO | PRI | NULL | |
| productName | varchar(255) | NO | UNI | NULL | |
| brand | varchar(45) | NO | | NULL | |
| model | varchar(100) | NO | PRI | NULL | |
| productDescription | varchar(255) | YES | | NULL | |
| physicalStock | int(10) unsigned | YES | | 0 | |
| price | decimal(7,2) unsigned | YES | | 0.00 | |
| location | varchar(45) | NO | | NULL | |
| lowStockAlert | int(10) unsigned | YES | | 0 | |
| lastUpdateBy | varchar(45) | NO | | NULL | |
| lastUpdate | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+--------------------+-----------------------+------+-----+-------------------+-----------------------------+
当您进行更新时,将 lastUpdate 列设置为等于自身,这样它就不会在当前时间戳中默认: