How to import CSV file into MS SQL Server using BULK INSERT statement

preview_player
Показать описание
In this tutorial, we are going to learn how to use BULK INSERT statement to import CSV file into Microsoft #SQL #Server database.

Instead of manually CSV fie or Text file using Import Data File wizard, we can easily write a T-SQL statement to do that. BULK INSERT loads data from a data file into a table.

► Buy Me a Coffee? Your support is much appreciated!
-------------------------------------------------------------------------------------
☕ Venmo: @Jie-Jenn

► Support my channel so I can continue making free contents
---------------------------------------------------------------------------------------------------------------

#SQLServer #BULKINSERT #TSQL
Рекомендации по теме
Комментарии
Автор

It's literally incredible! Thanks Jenn. Guys I came across a problem with system error 32 because I didn't close excel during the final command on SQL server. So, if you face the same problem, just close ms excel first.

mezbahenterprise
Автор

This works well, i had a couple of issues with my imported data.

1) Date Format in the CSV File had to change from dd/mm/yyyy to yyyy/mm/dd
2) Time Format had to be applied to where the were columns that had Time
3) Some lines at the bottom of data sheet had unwanted information so had to clear that as well

Other than that, i just repeated the steps and imported 1, 264, 763 rows
Thank You

anthonynorman
Автор

Thank you so much. With love from Vietnam

nguyenngocminh
Автор

hell yeah that was useful. im trying to import a dumb csv now. lol

phpmysql
Автор

I get incorrect Syntax "Incorrect syntax near 'FORMAT'". Any idea why?

trinhk
Автор

I am getting incorrect syntax near FORMAT in SSMS v18.9.1

archiesshedge
Автор

Thank you, super awesome tutorial!! Do you know if there is any way to use a sequence to generate a primary key with this method, instead of inserting the ID inside the CSV?

Adam_Pagan
Автор

Hi
Thanks for uploading useful information.
I am getting error saying, incorrect syntax near format.

Could you please advise, what can be reason behind the error?

swapnilwankhede
Автор

Can we use this with 1.7 mil rows in CSV file ? Thank. I used import flat file but it is error when importing.

misukoma
Автор

Hi, how do I import a big data, if I have 300, 000 rows and some columns have a NULL values? Thanks!!

adrianrhdz
Автор

Thanks dude, Could you please tell me how to add a csv file into an existing table

sreejithkayes
Автор

can I use the "bulk insert" function to import files with billions of records, file size 272 GB ?

GennaroViolante
Автор

Hi Jie, can you help advise on how to use a *relative* path for the file name to import instead of the absolute one? Is it possible?

python
Автор

how would you remove doblue quotes from a column?

patrickmcauliffe
Автор

Thanks for the video. Do you know what command would I use to append data to the table? I tried Append and it did not work.

itsdaj
Автор

I want to import 15 million records fastly can I do with this method.

niteshsingh
Автор

Thanks a lot man, but now what do you do when you need to import like 100 to 1000 text files? Will you need a 1000 CREAT statements for each text file you will be importing?

smisoshezi
Автор

Hi, maybe you can help me. I get the error message.
Cannot bulk load because the file could not be opened. Operating system error code 5(Access is denied.).

zazzy
Автор

how to load a flat file if the files are enclosed by single or double quotes. For eg:
Id | Name | sal
1 | 'Ram' | 20000
2 | ' krishna' | 10000

When I load the data with the single quotes then in sql table name column values are storing with single quotes for eg:
1, ' Ram', 20000
2, ' KRISHNA', 2000

THE result should be without quotes.
Please suggest

saikrishnareddy
Автор

What happens when the csv has more columns than you want to import?

fowad