我先这样建了一张表:
create table teams(teamno integer not null primary key,
playerno integer null,
division char(6) not null);
然后在表中插入了数据:
insert into teams values(1,3,'first');
再这样复制一张表时出错:
create table teams_copy5
(teamno integer not null primary key,
playerno integer null,
division char(10) not null) as
(select *
from teams);出错提示是:
Field 'teamno' doesn't have a default value
当我把“teamno integer not null primary key,”又提示这个错误:
Field 'division' doesn't have a default value从错误字面上看是没有默认值,可我的teams表也是照着书上建的,并且也插入了一行数据,该如何设置默认值呢?折腾一个晚上了还没有结果,请高手不吝赐教
create table teams(teamno integer not null primary key,
playerno integer null,
division char(6) not null);
然后在表中插入了数据:
insert into teams values(1,3,'first');
再这样复制一张表时出错:
create table teams_copy5
(teamno integer not null primary key,
playerno integer null,
division char(10) not null) as
(select *
from teams);出错提示是:
Field 'teamno' doesn't have a default value
当我把“teamno integer not null primary key,”又提示这个错误:
Field 'division' doesn't have a default value从错误字面上看是没有默认值,可我的teams表也是照着书上建的,并且也插入了一行数据,该如何设置默认值呢?折腾一个晚上了还没有结果,请高手不吝赐教
要是设置默认值的话,就是修改列的属性了,
则用 alter table teams ALTER column division set default '默认值';
-> playerno integer null,
-> division char(6) not null);
Query OK, 0 rows affected (0.75 sec)mysql> insert into teams values(1,3,'first');
Query OK, 1 row affected (0.19 sec)mysql> create table teams_copy5
-> (teamno integer not null primary key,
-> playerno integer null,
-> division char(10) not null) as
-> (select *
-> from teams);
Query OK, 1 row affected (0.22 sec)
Records: 1 Duplicates: 0 Warnings: 0mysql>
mysql>create database tennis4;
Query OK,1 row affected (0.01 sec)mysql>use tennis4;
Database changed
mysql>create table teams(teamno integer not null primary key,playerno integer null,division char(6) not null);
Query OK,o rows affected (0.25 sec)mysql>insert into teams values(1,3,'first');
Query OK,1 row affected (0.25 sec)mysql>create table teams_copy5(teamno integer not null primary key,playerno integer null,division char(10) not null) as (select * from teams);
ERROR 1364 (HY000):Field 'teamno' does't have a default value
select * from teams;
Database changed
mysql>select * from teams;
------------------------------
teamno | playerno | division |
------------------------------
1 | 3 | first |
------------------------------
1 row in set (0.23 sec)