Skip to content

Import a CSV

Import a CSV

To import a CSV file into a SQL database, you can use the following steps: 

  1. Create a table in your SQL database that matches the structure of your CSV file. The table columns should have identical names and data types to the CSV file’s corresponding columns. 
  2. Open your SQL client or command-line interface and connect to your database.
  3. Use the LOAD DATA INFILE command to import the CSV file into the table. The syntax of this command depends on the specific SQL database you are using.  

Here is an example command for MySQL:

LOAD DATA INFILE '/path/to/file.csv' 
INTO TABLE table_name

In this example, replace /path/to/file.csv with the actual file path of your CSV file, and table_name with the name of your SQL table.

FIELDS TERMINATED BY ‘,’ specifies that commas separate the columns in the CSV file. Change it if your CSV file has a different delimiter, such as a semicolon.

ENCLOSED BY ‘”‘ clause specifies that each field in the CSV file is enclosed in double quotes. If your CSV file uses a different character, change it accordingly.

LINES TERMINATED BY ‘\n’ clause specifies that a new line character terminates each row in the CSV file. If your CSV file uses a different line terminator, such as a carriage return, you should change this too.

IGNORE 1 ROWS ignores the first row of the CSV, assuming it contains column headers.

Upload a File with Coginiti Data Insert

If you need to work on an Excel or CSV file that has popped up on your desk, you can insert it into your database automatically (without coding) using Coginiti’s Data Insert tool.

Plus, if you need to repeat that job, you can create a template, so you don’t need to redo all the settings every time you insert an identical file. Also, you can update and share it with teammates who need to do the same work.