创建具有默认值 0000-00-00 的 MySQL datetime 列?
要设置默认值,可以在 MySQL 中使用 DEFAULT 关键字。让我们首先创建一个表 -
mysql> create table DemoTable -> ( -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> EmployeeName varchar(20), -> EmployeeJoiningDate datetime default '0000-00-00 00:00:00' -> )ENGINE=MyISAM,AUTO_INCREMENT=100; Query OK, 0 rows affected (0.21 sec)
使用 insert 命令在表中插入一些记录 -
mysql> insert into DemoTable(EmployeeName) values('Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(EmployeeName) values('David'); Query OK, 1 row affected (0.04 sec) mysql> insert into DemoTable(EmployeeName) values('Mike'); Query OK, 1 row affected (0.03 sec) mysql> insert into DemoTable(EmployeeName) values('Sam'); Query OK, 1 row affected (0.06 sec)
使用 select 语句从表中显示所有记录 -
mysql> select *from DemoTable;
这将产生以下输出 -
+------------+--------------+---------------------+ | EmployeeId | EmployeeName | EmployeeJoiningDate | +------------+--------------+---------------------+ | 100 | Chris | 0000-00-00 00:00:00 | | 101 | David | 0000-00-00 00:00:00 | | 102 | Mike | 0000-00-00 00:00:00 | | 103 | Sam | 0000-00-00 00:00:00 | +------------+--------------+---------------------+ 4 rows in set (0.00 sec)
广告