MySQL 创建自增字段
1. 建表
1.1 表结构
建表自增字段:auto_increment
日期:date 类型
时间:timestamp,默认已当前时间,如果不指定
1.2 建表
mysql> create table capacity(id bigint primary key auto_increment,capacity bigint,date date,time timestamp);
Query OK, 0 rows affected (0.02 sec)
mysql> desc capacity;
+----------+------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+----------+------------+------+-----+-------------------+-----------------------------+
| id | bigint(20) | NO | PRI | NULL | auto_increment |
| capacity | bigint(20) | YES | | NULL | |
| date | date | YES | | NULL | |
| time | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+----------+------------+------+-----+-------------------+-----------------------------+
4 rows in set (0.00 sec)
2. 插入数据测试
mysql> insert into capacity(capacity, date) values(180, '2019-10-26'),
-> (190, '2019-10-27'),
-> (200, '2019-10-28'),
-> (210, '2019-10-29'),
-> (224, '2019-10-30');
Query OK, 5 rows affected (0.00 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql> select * from capacity;
+----+----------+------------+---------------------+
| id | capacity | date | time |
+----+----------+------------+---------------------+
| 1 | 180 | 2019-10-26 | 2019-10-30 09:34:48 |
| 2 | 190 | 2019-10-27 | 2019-10-30 09:34:48 |
| 3 | 200 | 2019-10-28 | 2019-10-30 09:34:48 |
| 4 | 210 | 2019-10-29 | 2019-10-30 09:34:48 |
| 5 | 224 | 2019-10-30 | 2019-10-30 09:34:48 |
+----+----------+------------+---------------------+
5 rows in set (0.00 sec)
reference
Copyright © 一条鱼 2019 赣ICP备19001536号-2 all right reserved,powered by Gitbook最后修订日期:
2020-02-29 15:30:96