如何创建一个带有日期列的表格?
要创建一个只包含日期列的表格,您可以使用DATE类型。让我们首先创建一个表格 –
mysql> create table DemoTable
(
StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
StudentName varchar(20),
StudentAdmissionDate DATE
);
Query OK, 0 rows affected (0.47 sec)
使用INSERT命令向表中插入记录−
mysql> insert into DemoTable(StudentName,StudentAdmissionDate) values('Chris',now());
Query OK, 1 row affected, 1 warning (0.12 sec)
mysql> insert into DemoTable(StudentName,StudentAdmissionDate) values('Robert',curdate());
Query OK, 1 row affected (0.20 sec)
mysql> insert into DemoTable(StudentName,StudentAdmissionDate) values('David','2019-05-21');
Query OK, 1 row affected (0.16 sec)
使用SELECT语句显示表中的所有记录。
mysql> select * from DemoTable;
这将产生以下输出 −
+-----------+-------------+----------------------+
| StudentId | StudentName | StudentAdmissionDate |
+-----------+-------------+----------------------+
| 1 | Chris | 2019-04-27 |
| 2 | Robert | 2019-04-27 |
| 3 | David | 2019-05-21 |
+-----------+-------------+----------------------+
3 rows in set (0.00 sec)