CREATE TABLE companys ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, company varchar(5), company_name VARCHAR(50), company_icon VARCHAR(50), crcompanyeated DATETIME DEFAULT NULL, modified DATETIME DEFAULT NULL, );
プログラムで、現在時刻をとってきて設定は面倒ですよね。
SQL文で下記でシステム日時設定できます。単純に now() でできます。
insert into companys (company,company_name,company_icon,crcompanyeated,modified) values ('10000','suda company','suda.png',now(),now()); insert into companys (company,company_name,company_icon,crcompanyeated,modified) values ('10001','suda1 company','suda1.png','2009-10-04 15:25:07','2017-01-07');
結果は
mysql> select * from companys; +----+---------+---------------+--------------+---------------------+---------------------+ | id | company | company_name | company_icon | crcompanyeated | modified | +----+---------+---------------+--------------+---------------------+---------------------+ | 6 | 10000 | suda company | suda.png | 2017-01-08 19:27:22 | 2017-01-08 19:27:22 | | 7 | 10001 | suda1 company | suda1.png | 2009-10-04 15:25:07 | 2017-01-07 00:00:00 | +----+---------+---------------+--------------+---------------------+---------------------+ 3 rows in set (0.00 sec)
となります。
[amazonjs asin=”4295000191″ locale=”JP” title=”やさしく学べるMySQL運用・管理入門【5.7対応】”]