Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Insert into from another table - NULL IDs!!!

Author  Topic 

Chopsmum
Starting Member

38 Posts

Posted - 2006-05-31 : 01:42:38
Hi friends,
I am trying to add records from one table into another.

SQL
use riqdb2
INSERT INTO tblItemGrades
(chrvItemGradeStaticComment,decItemGrade)
SELECT chrvItem2StaticComment,decItem2Grade
FROM tblItems2
GO

Error msg
/*------------------------
use riqdb2
INSERT tblItemGrades
(chrvItemGradeStaticComment,decItemGrade)
SELECT chrvItem2StaticComment,decItem2Grade
FROM tblItems2
GO
------------------------*/
Msg 515, Level 16, State 2, Line 2
Cannot insert the value NULL into column 'ItemGradesID', table 'RIQDB2.dbo.tblItemGrades'; column does not allow nulls. INSERT fails.
The statement has been terminated.

Please advise how to insert new records - Is it because I havent set up Identity (1,1)????

Thanks
Cm

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-05-31 : 01:49:14
What you want to insert into Column ItemGradesID ???


If Debugging is the process of removing Bugs then i Guess programming should be process of Adding them.
Go to Top of Page

Chopsmum
Starting Member

38 Posts

Posted - 2006-05-31 : 01:52:20
I do not want to insert into ItemGradesID, its the primary key. It is mentioned in the error msg
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-05-31 : 01:53:18
If it is primary key, you should supply unique value to that column and you cant skip it

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2006-05-31 : 01:54:43
you're probably confused about identity columns and primary key...

you need to supply a value to the primary key column, unless it's an autogenerating one



--------------------
keeping it simple...
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-05-31 : 01:54:59
or why are you not making it an identity column?

If Debugging is the process of removing Bugs then i Guess programming should be process of Adding them.
Go to Top of Page

Chopsmum
Starting Member

38 Posts

Posted - 2006-05-31 : 01:56:13
how do I make it autogenerating????

thanks
Go to Top of Page

Chopsmum
Starting Member

38 Posts

Posted - 2006-05-31 : 01:58:03
I have just manually added values to the primary key so that it continues from ItemGradesID=1...to 55. Enough for my test insert. Still same error msg
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-05-31 : 02:00:19
Just open the table in the EM and select the column and in the property section you will
see Indenity, make the flag true and save the table

If Debugging is the process of removing Bugs then i Guess programming should be process of Adding them.
Go to Top of Page

Chopsmum
Starting Member

38 Posts

Posted - 2006-05-31 : 02:04:01
I think I know what the problem is. You cant add records to a new table when the ID conflicts. I have to either insert records as a value set or alternatively change the IDs of the original table so that the records can be added without conflict.

Thanks anyway guys. Its never straight forward is it!!!

Cm
Go to Top of Page
   

- Advertisement -