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 2005 Forums
 Transact-SQL (2005)
 Bulk Insert and Default Values

Author  Topic 

lotek
Starting Member

42 Posts

Posted - 2008-02-04 : 13:46:36
I am experiencing an issue with bulk insert and default values.

Say that i have a table with three columns: col1, col2, col3. My format file species col1 and col2 but not col3. Col3 is an int and has a default value of '9'. When i insert a record manually it picks up the default value fine, but when i bulk insert all of the records have a default value of 0. Any thoughts?

BULK INSERT Database..table FROM 'file' WITH
(
FORMATFILE='c:\format.fmt',
CODEPAGE='RAW',
ROWS_PER_BATCH=19065,
MAXERRORS=10,
TABLOCK
)

Thanks,
Matt

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-02-04 : 23:00:24
How's your data file look like?
Go to Top of Page

lotek
Starting Member

42 Posts

Posted - 2008-02-05 : 10:47:35
quote:
Originally posted by rmiao

How's your data file look like?



string|string|s|59|aa|aaaaa|N|N|N|N|N|Y|Y

8.0
13
1 SQLCHAR 0 4 "|" 1 col1 SQL_Latin1_General_CP1_CI_AS
2 SQLCHAR 0 25 "|" 2 col2 SQL_Latin1_General_CP1_CI_AS
3 SQLCHAR 0 1 "|" 3 col3 SQL_Latin1_General_CP1_CI_AS
4 SQLCHAR 0 2 "|" 4 col4 SQL_Latin1_General_CP1_CI_AS
5 SQLCHAR 0 4 "|" 5 col5 SQL_Latin1_General_CP1_CI_AS
6 SQLCHAR 0 6 "|" 6 col6 SQL_Latin1_General_CP1_CI_AS
7 SQLCHAR 0 1 "|" 7 col7 SQL_Latin1_General_CP1_CI_AS
8 SQLCHAR 0 1 "|" 8 col8 SQL_Latin1_General_CP1_CI_AS
9 SQLCHAR 0 1 "|" 9 col9 SQL_Latin1_General_CP1_CI_AS
10 SQLCHAR 0 1 "|" 10 col10 SQL_Latin1_General_CP1_CI_AS
11 SQLCHAR 0 1 "|" 11 col11 SQL_Latin1_General_CP1_CI_AS
12 SQLCHAR 0 1 "|" 12 col12 SQL_Latin1_General_CP1_CI_AS
13 SQLCHAR 0 1 "\r\n" 13 col13 SQL_Latin1_General_CP1_CI_AS

BULK INSERT db..table FROM 'file' WITH
(
FORMATFILE='fmt.fmt',
CODEPAGE='RAW',
ROWS_PER_BATCH=141,
MAXERRORS=10,
TABLOCK
)
GO

Col14 is an int with a default value, but it always gets set to zero.
Go to Top of Page
   

- Advertisement -