我把mysql的主键设置为自动增长了
create table test
(
     id int auto_increment not null,
     name varchar(100) null,
     primary key(id)
)
我插入一条数据
insert into test values('yangxun')
这样不行
非要给id传一个值 insert into test values(1,'yangxun');
id是自动增长为什么还非的要赋值!

解决方案 »

  1.   

    insert into test(name) values('yangxun');
    == 思想重于技巧 ==
      

  2.   

    SQL语法就是这样,否则SQL怎么知道你的是给哪一列的?
    == 思想重于技巧 ==
      

  3.   

    也可以 insert into test values(null,'yangxun'); 不用理会第一列的值就行了。
      

  4.   

    指名要插入的字段就行
    insert into test(name) values('yangxun'); 
      

  5.   


    除了这个答案以外,
    也可以这样写SQL codeinsertintotest values(NULL,'yangxun');
    SQL codeinsertintotest values(LAST_INSERT_ID(),'yangxun');
      

  6.   

    插入时用null或default代替就可以
      

  7.   

    试试这样行不行,行的话告诉我一下。
    create table test 

        id int auto_increment not null, 
        name varchar(100) null, 
        primary key(id) 
    )ENGINE=MyISAM;