create table t_class(
id int not null primary key,
name varchar(250)
);create table t_stu (
id int not null primary key,
name varchar(250),
cid int not null,
foreign key(cid) references t_class(id)
); 表结构。
t_class表结构
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| id | int(11) | NO | PRI | | |
| name | varchar(250) | YES | | NULL | |
+-------+--------------+------+-----+---------+-------+
============================================================
t_stu表结构
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| id | int(11) | NO | PRI | | |
| name | varchar(250) | YES | | NULL | |
cid | int(11) |MUL | | | |
+-------+--------------+------+-----+---------+-------+为什么关系没有创建起来,我在插入insert into t_stu(name,cid) values("admin",1); 竟然没有报错。
why?
id int not null primary key,
name varchar(250)
);create table t_stu (
id int not null primary key,
name varchar(250),
cid int not null,
foreign key(cid) references t_class(id)
); 表结构。
t_class表结构
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| id | int(11) | NO | PRI | | |
| name | varchar(250) | YES | | NULL | |
+-------+--------------+------+-----+---------+-------+
============================================================
t_stu表结构
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| id | int(11) | NO | PRI | | |
| name | varchar(250) | YES | | NULL | |
cid | int(11) |MUL | | | |
+-------+--------------+------+-----+---------+-------+为什么关系没有创建起来,我在插入insert into t_stu(name,cid) values("admin",1); 竟然没有报错。
why?
why? "
对您的问题不理解
我这个建的不是主外键约束吗? 在t_class 表里面id 字段如果没有值,在我插入t_stu表中的cid不就是会报错吗?我这样理解错了吗?
'截至2010-03-30 13:12:09 用户结帖率0.00% 当您的问题得到解答后请及时结贴.
http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html