Error in insert query

  • create table class

    (classid int primary key identity,

    classname varchar(30) not null unique,

    studid int foreign key references student(studid))

    -------- insert query

    insert into class

    (classid,classname,studid)

    values

    ('secondstd',2)

    ----- query error

    Msg 109, Level 15, State 1, Line 1

    There are more columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement.

  • Your statement says that you want to enter data into 3 columns, but you are only providing data for 2 columns.

    Because you are using an IDENTITY, then you don't need to mention this.

    So...

    insert into class

    (classname,studid)

    values ('secondstd',2)



    For better, quicker answers on T-SQL questions, read Jeff Moden's suggestions.[/url]

    "Million-to-one chances crop up nine times out of ten." ― Terry Pratchett, Mort

  • Thanks lot...

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply