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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Insert problem

Author  Topic 

MariaM
Starting Member

17 Posts

Posted - 2008-02-14 : 08:34:01
Hi !

I'm using the following statement to insert values into a table.

insert t_kon_koncern (PeOrgLopNr, ExpStKl_90, ImpStKl_90, ExpStKl_91, ImpStKl_91, ExpStKl_92, ImpStKl_92, ExpStKl_93, ImpStKl_93, ExpStKl_94, ImpStKl_94,
ExpStKl_95, ImpStKl_95, ExpStKl_96, ImpStKl_96, ExpStKl_97, ImpStKl_97, ExpStKl_98, ImpStKl_98, ExpStKl_99, ImpStKl_99, ExpStKl_00, ImpStKl_00,
Konc_86, Konc_87, Konc_88, Konc_89, Konc_90, Konc_91, Konc_92, Konc_93, Konc_94, Konc_95, Konc_96, Konc_97, Konc_98, Konc_99, Konc_00)
select * from [ffab].[dbo].[koncern8600]

The destination table contains more columns than the ones that are cosen, but the other table consists only of theese columns. The tables are situated in different databases. I get the following error message on a column in the destination table that are not chosen.

Server: Msg 515, Level 16, State 2, Line 1
Cannot insert the value NULL into column 'konc_05', table 'Ifdb2.dbo.t_kon_koncern'; column does not allow nulls. INSERT fails.
The statement has been terminated.

What have I missed ?

/M

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2008-02-14 : 08:46:59
'konc_05' is not in your insert statement and is trying to put a default of NULL. The table definition does not allow nulls.
Add 'konc_05'to your insert and set a value for it.

"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2008-02-14 : 08:48:19
Also using * is not a good idea, if the table definition for [ffab].[dbo].[koncern8600] changes, this insert will fail. You should specify all of the columns

"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page
   

- Advertisement -