May 21, 2011 at 1:23 pm
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
May 21, 2011 at 2:05 pm
Either you provide a value for each column or you need to identify the column(s) you'd like to insert the values.
May 21, 2011 at 2:15 pm
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
May 21, 2011 at 2:22 pm
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...
May 21, 2011 at 2:28 pm
thanks a lot ..this example was great help...:-)
May 21, 2011 at 2:38 pm
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
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply