먼저 테이블을 생성하겠습니다 -
mysql> create table DemoTable -> ( -> PunchOut timestamp, -> PunchStatus tinyint(1) -> ); Query OK, 0 rows affected (0.51 sec)
삽입 명령을 사용하여 테이블에 일부 레코드 삽입 -
mysql> insert into DemoTable values('2019-01-31 6:30:10',1); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('2019-02-06 4:10:13',0); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('2018-12-16 03:00:30',0); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('2016-11-25 02:10:00',1); Query OK, 1 row affected (0.22 sec)
select statemen을 사용하여 테이블의 모든 레코드 표시 -
mysql> select *from DemoTable;
출력
+---------------------+-------------+ | PunchOut | PunchStatus | +---------------------+-------------+ | 2019-01-31 06:30:10 | 1 | | 2019-02-06 04:10:13 | 0 | | 2018-12-16 03:00:30 | 0 | | 2016-11-25 02:10:00 | 1 | +---------------------+-------------+ 4 rows in set (0.00 sec)
다음은 MySQL 테이블의 타임스탬프 필드를 업데이트하는 쿼리입니다. 현재 날짜를 PunchStatus 0 −
로 필드에 설정했습니다.참고 − 현재 날짜와 시간은 2019-06-30 13:43:45
mysql> update DemoTable set PunchOut=now() where PunchStatus=0; Query OK, 2 rows affected (0.19 sec) Rows matched: 2 Changed: 2 Warnings: 0
다시 한번 테이블 기록을 확인해보자 -
mysql> select *from DemoTable;
출력
+---------------------+-------------+ | PunchOut | PunchStatus | +---------------------+-------------+ | 2019-01-31 06:30:10 | 1 | | 2019-06-30 13:43:45 | 0 | | 2019-06-30 13:43:45 | 0 | | 2016-11-25 02:10:00 | 1 | +---------------------+-------------+ 4 rows in set (0.00 sec)