issues in inserting data(no constraint supplied)

  • hi,

    I am creating a table and inserting data into it but it does not allow me to add values...please check code:-

    CREATE TABLE ID1(

    ID INT PRIMARY KEY,

    NAME VARCHAR(20))

    this worked:-

    insert into ID1 values(7,'a')

    but this didnt worked:

    insert into ID1 values(8)

    I did not supply any not null constraint on the name column so it should take null values if i dont supply data but this is giving me error ;

    Msg 213, Level 16, State 1, Line 1

    Column name or number of supplied values does not match table definition.

    please help

  • Either you provide a value for each column or you need to identify the column(s) you'd like to insert the values.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • so it means either i have to use "default" or identity?but if it dont need default or identity so wat else i can do?..please keep suggesting,,,i m trying hard to learn the basics and need lots of help from you ppl

  • since SQL Server doesn't know if you'd like insert the value into the ID or name column, you need to specify it:

    insert into ID1(ID) values(8)

    And no, SQL Server will not "guess" that it's your intention to insert the value into the ID column...



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • thanks a lot ..this example was great help...:-)

  • You might want to check out the INSERT statement in BOL - specifically look at the "(column_list)" section.

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

Viewing 6 posts - 1 through 5 (of 5 total)

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