我有一个表格,其中包含两个时间戳字段 -
<div class="row justify-content-center">
<h1>New User</h1>
</div>
<div class='row justify-content-center'>
<div class='col-6'>
<form [formGroup]='regForm'
(ngSubmit)="onSubmit(regForm.value)"
[class.error]="!regForm.valid && regForm.touched"
>
<div class='form-group'
[class.error]="!regForm.get('name').valid && regForm.get('name').touched">
<label>Name</label>
<input type="text" class='form-control' [formControl]="regForm.controls['name']">
<div *ngIf="regForm.controls['name'].hasError('required')" class="invalid-feedback">Name is required</div>
</div>
<div class='form-group'>
<label>Email</label>
<input type="email" class='form-control'>
</div>
<div class='form-group'>
<label>Password</label>
<input type="password" class='form-control'>
</div>
<div class='form-group'>
<label>Confirmation</label>
<input type="password" class='form-control'>
</div>
<button type="submit" class='btn btn-default'>Submit</button>
</form>
</div>
</div>
我使用
插入了两行CREATE TABLE `test`
(`id` INT NOT NULL AUTO_INCREMENT ,
`first_date` TIMESTAMP NULL ,
`second_date` TIMESTAMP on update CURRENT_TIMESTAMP() NULL ,
PRIMARY KEY (`id`)) ENGINE = InnoDB;
现在,我需要将第二个日期值复制到第一个日期列,但是当我尝试更新查询时,日期值都会更新到今天的日期。
INSERT INTO `test` (`id`, `first_date`, `second_date`)
VALUES (NULL, NULL, '2017-10-18 17:02:14'), (NULL, NULL, '2017-10-18 17:02:14');
不知何故,second_date的update test set first_date = second_date where id=<row_id>
id | first_date | second_date
----------------------------------------------
3 | 2017-11-17 16:09:03 | 2017-11-17 16:09:29 --> This value was
4 | NULL | 2017-10-18 17:02:14 "2017-10-18 17:02:14"
5 | NULL | 2017-10-18 17:02:14 before the update query.
属性在这里造成了问题。如何从第二列复制值而不影响on update CURRENT_TIMESTAMP()
的现有值?
答案 0 :(得分:1)
以下查询应该可以帮助您从第二列复制值而不影响second_date的现有值:
UPDATE test SET first_date = second_date , second_date = second_date WHERE id=<row_id>