关于default 的问题( 在线等)
Q1、
mysql> create table reservation(
-> ordernum int not null auto_increment,
-> fid int references flight,
-> cid int references customer,
-> qty int,
-> orderdate date default now(),
-> cardnum char(20) references card,
-> primary key(ordernum)
-> );
ERROR 1067 (42000): Invalid default value for 'orderdate'
Q2、
mysql> create table flight(
-> fid int not null default '000000' auto_increme
-> fnumber char(20) not null,
-> fdate date,
-> ftime datetime,
-> price double default '0.00',
-> capacity int,
-> dest int references airport,
-> orig int references airport,
-> primary key(fid)
-> );
ERROR 1067 (42000): Invalid default value for 'fid'
------解决方案--------------------
orderdate date default now
这个恐怕不能如愿了。似乎mysql并不支持now()函数或者curdate()函数作为default的计算值。
其实你压根不用为此担心啊。
mysql> create table t3(id int, t date);
Query OK, 0 rows affected (0.11 sec)
mysql> insert into t3 values(1, now());
Query OK, 1 row affected (0.09 sec)
mysql> select * from t3;
+------+------------+
| id | t |
+------+------------+
| 1 | 2008-03-29 |
+------+------------+
1 row in set (0.01 sec)
无非是多写了一个字段插入now()