如何创建带有日期列的表格?
mysqlmysqli database
要创建仅带有日期列的表格,可以使用 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)