把mysql主键设置为自动增长,但是它的主键为什么每次都和它的一个外键一样呢?郁闷,请高手指教

解决方案 »

  1.   

    列子:
    create table a (id int not null AUTO_INCREMENT, name char(10) not null, primary key(id) );
    create table b (mid int not null references a , sex char(10) not null);insert into a values(NULL, 'aaa');
    insert into a values(NULL, 'bbb');
    insert into a values(NULL, 'ccc');insert into b values(1, 'man');
    insert into b values(2, 'man');
    insert into b values(last_insert_id(), 'man');