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 with default values and Select statement

Author  Topic 

eric_ht
Starting Member

37 Posts

Posted - 2006-12-01 : 09:18:19
I have a table I want to insert records into that has around 100 columns. Data is only required in 5 columns for the record to be inserted. But the other columns throw errors saying NULL value is not allowed. Can I not specify the 5 columns I want to insert and tell the rest to use Default Values? Or is default values NULL which would still cause an error. This insert is also based on a select. Below is a sample:

Insert into MY_FILE (column_1, column_2, column_3, column_4, column_5)
select distinct
OTHER_FILE.field1,
OTHER_FILE.field2,
OTHER_FILE.field3,
OTHER_FILE.field4,
OTHER_FILE.field5,
from OTHER_FILE

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-12-01 : 09:27:34
You have to look at the table definition for My_File..It seems that for rest of the columns NOT NULL constraint is imposed but not default value. You need to create defaults and attach them to other columns for remove the error in your insert.

Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page
   

- Advertisement -