If you have a .csv file and you want to convert it into an SQL insert Query (be MySql, SQLite, Oracle), this can be done in just a few simple steps using Notepad++ Find and Replace with some Regular Expressions.

- Open the CSV (Comma Separated Values) file in Notepad++
- Enclose each data values in CSV file with Single Quotes.
- Forming the Query Go to Find and Replace,
- Now lets complete the Sql script.
- Add Custom header and footer to Windows Notepad file
- Enabling Notepad++ Dark Theme
- Notepad++ is about to exit prompt message
- Go to Line Number option in Windows Notepad
- How to Convert CSV file to SQL Script using Notepad++
- How to un-hide tab bar in notepad++
- Notepad++ display files on tab bar as horizontal instead of vertical
- Compare two text files in Notepad++
- Column Mode Editing in Notepad++
- Convert SQL to CSV in Notepad++
- List of Programming Languages Supported by Notepad++
- Keyboard shortcut to close tab in Notepad++
- How to open a new tab in Notepad++
- How to Enable spellcheck Notepad++
- Prettify JSON in Notepad++
- Word count in Notepad++
- How to create MD5 digest in Notepad++
- Notepad++ delete lines above or below
- Unable to edit file in Notepad++
- Word wrap text in Notepad++
- Notepad++ Editor alternatives for Mac OS X
- Launch Notepad++ html document in any web browser
- Convert text to random case using Notepad++
- Show Notepad++ tabs in multiple lines instead of scroll on tab bar
- 97 Useful Notepad++ Keyboard Shortcuts
- Base 64 Encoding Decoding In Notepad++
- Where are Notepad++ temp unsaved files stored?
- How to add Date and Time to Windows Notepad File
- How to Apply Themes to Notepad++
- Multiple line editing in Notepad++
- Add comma or semicolon at end of each line Notepad++
- How to know Notepad++ is 32-bit or 64-bit Version
- Notepad++ do not show CRLF characters
- Notepad++ select all above or below lines
- Change default language highlighting in Notepad++
- How to check about details of Notepad++ text editor
- Setting up Cloud feature with Notepad++
- Add Blank Lines Between Each Lines in Notepad++
- How to zoom-in or zoom-out in Windows Notepad
- Replace tabs by spaces or comma Notepad++
- [Nopepad++] How to add text at end of each line
- Using Document Map in Notepad++
- Notepad++ insert a blank line above or below the current line example
- Portable Notepad++ for windows
- How to format or prettify XML in Notepad++
- How to Disable EditText Keyboard Android App - Android
- Using Document Map in Notepad++ - NotepadPlusPlus
- Word wrap text in Notepad++ - NotepadPlusPlus
- Android read text file from internal storage - Android
- SharePoint installation - Appfabric installation failed because installer MSI returned with error code:1603 - SharePoint
- Calculate Area of Trapezoid - C-Program
- How to Configure Eclipse keymap in IntelliJ IDE - Android-Studio
- Get Button Text onClick Android App - Android
- Pdf Text to Speech option in Mac OS X Preview App - Mac-OS-X
- Android Studio 1.3 beta now Available for Developers - Android-Studio
- Fixing Android unknown error 961 while downloading app - Android
- How to rename package name in Android Studio - Android-Studio
- Notepad++ Editor alternatives for Mac OS X - NotepadPlusPlus
- Share Story Feed on Facebook using URL - Facebook
- How to exclude results from SharePoint Search - SharePoint
Our Sample CSV Data :
1,data1,data-a,323
2,data2,data-b,324
3,data3,data-a,325
4,data4,data-b,326
5,data5,data-a,327
6,data6,data-b,328
Open Find and Replace by pressing "Ctrl + F", go to replace tab and,
Find : ,
Replace with : ','
Result :
1','data1','data-a','323
2','data2','data-b','324
3','data3','data-a','325
4','data4','data-b','326
5','data5','data-a','327
6','data6','data-b','328
Now data values are enclosed with Quotes, expect the row start and end. For this we need to use Regular Expression.
Find : ^
Replace : insert insert myTable values\('
^ is a regex character to add data at the start of each line in the file.
Keep in mind to select "Regular Expression" in Search Mode. \ (slash) is an escape character for braces in the regex.
Result :
insert insert myTable values('1','data1','data-a','323
insert insert myTable values('2','data2','data-b','324
insert insert myTable values('3','data3','data-a','325
insert insert myTable values('4','data4','data-b','326
insert insert myTable values('5','data5','data-a','327
insert insert myTable values('6','data6','data-b','328
Go to Find and Replace again and,
Find : $
Replace : '\);
Make sure that you select "Regular Expression" in Search Mode. \ (slash) is an escape character for braces in regex.
Result :
insert insert myTable values('1','data1','data-a','323');
insert insert myTable values('2','data2','data-b','324');
insert insert myTable values('3','data3','data-a','325');
insert insert myTable values('4','data4','data-b','326');
insert insert myTable values('5','data5','data-a','327');
insert insert myTable values('6','data6','data-b','328');
$ is a regex character to add data at the end of each line in file.
Thats it!! Our SQL Script is now ready!..
Note: Data may not be as simple as we have considered in our example. We may have Single Quotes (') in within itself, So in such cases, you need to first escape it by,
Find : '
Replace : ''
⚠️ Remember to move search mode in "Regular Expression" while using RegEx or else you may not get results.