create table t_gasfee
(
id int primary key identity(1,1),
mouth smallint not null check(mouth>=1 and mouth<=12),
price int not null check(price>=0),
state varchar(1) not null default('0')  ,
gassid int  not null 
)
我使用:
insert into t_gasfee values(1,12,'111')
怎么就报错:列名或所提供值的数目与表定义不匹配,default究竟怎么使用呀?

解决方案 »

  1.   

    insert into t_gasfee values(1,12,0,'111')
      

  2.   

    如果Insert Into T Value(a,b,c,……)就必须给mouth,price ,state ,gassid 四个字段都赋值,
    改为insert into t_gasfee(mouth,price,gassid) Values(1,12,0,'111')的话state才会取默认值。
      

  3.   

    建议最好使用insert into t_gasfee

        col1
       ,col2
       ,col3

    select col1Value,col2Value,col3Value插入时指定列名,并且指定对应的值
      

  4.   

    不是default字段的问题,当要插入的列少于表真正的列时,要写出具体的列名,如下
    insert into t_gasfee(price,month,state) values(1,12,'111
      

  5.   

    insert into t_gasfee([mouth],price,gassid) values(1,12,'111')指定列名