如何用日期列创建表?
要创建仅包含日期列的表,可以使用DATE类型。让我们首先创建一个表-
mysql> create table DemoTable(
StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
StudentName varchar(20),
StudentAdmissionDate DATE
);
使用插入命令在表中插入记录-
mysql> insert into DemoTable(StudentName,StudentAdmissionDate) values('Chris',now());mysql> insert into DemoTable(StudentName,StudentAdmissionDate) values('Robert',curdate());
mysql> insert into DemoTable(StudentName,StudentAdmissionDate) values('David','2019-05-21');
使用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)
以上是 如何用日期列创建表? 的全部内容, 来源链接: utcz.com/z/321819.html