mysql的外键问题
这是我的sql语句,不知道我这样创建外键对吗?(可以在数据库里执行。)
create table test
(id int primary key,
username varchar(20) not null,
unique(username));
create table test1
(id int,
username varchar(20),
pid int,
primary key(id,username));
alter table test1 add constraint foreign key(username)
references test(username) on delete cascade
on update cascade;
可是插入数据的时候只能把数据插入test表,而test1表始终插入不了。
mysql> insert into test
-> values(1,'snow');
Query OK, 1 row affected (0.02 sec)
mysql> inser into test1
-> values(1,'snow',1);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'inser
into test1
values(1,'snow',1)' at line 1
请问:这是什么问题?(我数据库基础很差!)