Bulk Insert - SQL Server vs MySQL

Continuing my series on how same things can be done differently in SQL Server and MySQL, in this post, we will see how bulk insert can be done in SQL Server vs MySQL.

We often need to import data from a text file to the server. Consider that the file D:\test.txt has data for three columns and  you want to import this data into a table

In SQL Server we can use the BULK INSERT command
sqlserver-bulkinsert

In MySQL we can user Load Data Command

load data local infile 'D:/test.txt' into table test
fields     escaped by '\\'
    terminated by '\,'
    lines terminated by '\n'


Here both of them consider comma as a field separator and new line as the line separator

Note : By Default SQL Server looks for the existence of the file in Server's directory. In MySQL, we need to specify keyword local to instruct that file is available in the local system


About The Author

Madhivanan,an MSc computer Science graduate from Chennai-India, works as a works as a Lead Subject Matter Expert at a company that simplifies BIG data. He started his career as a developer working with Visual Basic 6.0, SQL Server 2000 and Crystal Report 8. As years went by, he started working more on writing queries in SQL Server. He now has good level of knowledge in SQLServer, Oracle, MySQL and PostgreSQL as well. He is also one of the leading posters at www.sqlteam.com and a moderator at www.sql-server-performance.com. His T-sql blog is at http://beyondrelational.com/blogs/madhivanan

No comments: