How to read multiple CSV/Excel files in R and write in SQL?

Suppose, you have multiple CSV/Excel files, assume 100,200 in a folder or may be in a different folder. You want to write all those files to MS SQL through R. If you will do it one by one then it will be time consuming and it will not be the efficient way. Here, I will tell you how you can do it in the most efficient way. Lets get started:

To process all the CSV/Excel files whether it is present in the same folder or within the folders, its is a simple 3 step process:

Step 1

Set the path of location where all the files are present and make connection with database.

Step 2

List down whether you are able to see the all the files using recursive=True

Step 3

The main logic is in this step. Creating a loop which wound from 1 till the number files we have in the designated folder. Then, it will import file in R one by one, and then write in MS SQL, and it will get appended in the same table until the loop gets over.

I hope this was helpful. Please share your valuable feedback.

Keep reading and learning!

Leave a Reply