As far as I know, bulk insertion cannot insert an empty string, it can either save null or use the default value with the keepnulls option or without the keepnulls option. For your three sample records, after inserting the database, it should be like:
| id | name
| 1 | Null
| 1 | ""
| 1 | ''
The reason is that the bulk insert will process your first row, the second column value as null; for the other 2 rows will take the second value of the column as non-zero, and take it as is.
Instead of letting Bulk Insert insert an empty row value for you, you can let the table column have a default value as an empty row.
Example: <Preview> <code> CREATE TABLE BulkInsertTest (id int, name varchar (10) DEFAULT '')
Bulk Insert same CSV file into table
BULK INSERT Adventure.dbo.BulkInsertTest FROM '....\test.csv' WITH ( FIELDTERMINATOR ='\,', ROWTERMINATOR ='\n' ) SELECT * FROM BulkInsertTest
The result will look like this: (The first line in your CSV will get an empty line)
| id | name
| 1 |
| 1 | ""
| 1 | ''
source share