我第一次用mysql,我在做一个这样的问题,关系的主键为id,还有两个属性,一个是customer_id,另一个是book_id,我想在插入的时候可以让id自动增加,所以我插入的时候只插入customer_id和book_id,id为空.这样可以吗?如果不可以的话,那又该怎么插入呢?请各位指教.回答好的,一定给分.谢谢!

解决方案 »

  1.   

    create table table1(id int not null identity(1,1),customer_id int,book_id int);
      

  2.   

    insert into table1(customer_id,boo_id) values(1,2);
    id 自动增加
      

  3.   

    id自动增加 
    id为空
    ------------
    没看懂
      

  4.   

    --这样?create table T(id int identity(1, 1), customer_id int, book_id int)
    insert T(customer_id, book_id) values(NULL, NULL)select * from T--result
    id          customer_id book_id     
    ----------- ----------- ----------- 
    1           NULL        NULL(1 row(s) affected)