Skip to content

Convert CSV to SQL Server

Drop your CSV file to get a SQL Server script with CREATE TABLE and INSERT statements. Each column gets a type, and every fix is listed with its row and column.

Your file
csvventas_2024.csvSample file, 357 B
Your database

5 rows converted, 8 fixes, none rejected

Show
The first rows of ventas_2024.csv, with each fix marked
Row
500412Peña MuñozMérida15/02/20241.234,50sí
600413José Ángel RuizLeón03/02/202499,90no
700414Zoë OrtízQuerétaro29/02/2024N/Así
800415Ñuño CastañedaOaxaca28/02/20247,25no
900416Iñaki OlaizolaMazatlán11/03/2024980,75sí
-- Written by IntoSQL for SQL Server.

SET NOCOUNT ON;
BEGIN TRANSACTION;

CREATE TABLE ventas_2024 (
    folio nvarchar(8) NOT NULL,
    cliente nvarchar(16) NOT NULL,
    ciudad nvarchar(16) NOT NULL,
    fecha date NOT NULL,
    importe decimal(6,2),
    pagado bit NOT NULL
);

INSERT INTO ventas_2024 (folio, cliente, ciudad, fecha, importe, pagado) VALUES
(N'00412', N'Peña Muñoz', N'Mérida', '2024-02-15', 1234.50, 1),
(N'00413', N'José Ángel Ruiz', N'León', '2024-02-03', 99.90, 0),
(N'00414', N'Zoë Ortíz', N'Querétaro', '2024-02-29', NULL, 1),
(N'00415', N'Ñuño Castañeda', N'Oaxaca', '2024-02-28', 7.25, 0),
(N'00416', N'Iñaki Olaizola', N'Mazatlán', '2024-03-11', 980.75, 1);

COMMIT TRANSACTION;

Fixes

  1. The file was written in windows‑1252; it was converted to UTF-8.
  2. The header is on row 4; the rows above it were left out.
  3. Row 10 ("TOTAL") is a total, so it was left out.
  4. Leading zeros kept in "Folio": 00412 stays 00412, stored as text.
  5. 15/02/2024 proves the dates in "Fecha" are day-first, so 03/02/2024 is read as 2024‑02‑03.
  6. Numbers in "Importe" use a decimal comma: 1.234,50 is read as 1234.50.
  7. N/A in "Importe" read as empty (1 of 5 values).
  8. "Pagado" holds yes and no words (sí, no), stored as boolean.

Your file is converted on this computer and never uploaded.

Other samples:

From CSV to SQL Server, column by column

The sample above, ventas_2024.csv, as IntoSQL writes it for SQL Server: what each column holds in the file, the type it gets and how its first value lands in the script.

In the fileFirst valueColumnSQL Server typeIn the script
Folio00412folionvarchar(8)N'00412'
ClientePeña Muñozclientenvarchar(16)N'Peña Muñoz'
CiudadMéridaciudadnvarchar(16)N'Mérida'
Fecha15/02/2024fechadate'2024-02-15'
Importe1.234,50importedecimal(6,2)1234.50
Pagadosípagadobit1

Load the script into SQL Server

The download is a plain .sql file. Run it with SQL Server's own tools.

From a terminal

sqlcmd -S localhost -d mydb -f 65001 -i ventas_2024.sql_server.sql

-f 65001 reads the file as UTF-8, so accents and ñ arrive as written.

From a database tool

In SQL Server Management Studio or Azure Data Studio, open the file and choose Execute.

What to know about CSV files and SQL Server

What IntoSQL reads in CSV files

  • The encoding is detected, Windows-1252 and UTF-16 included, so accents and ñ arrive intact.
  • The separator is detected: comma, semicolon, tab or vertical bar. With a semicolon, decimal commas like 1.234,50 are read as numbers.
  • Quoted values can hold separators and line breaks.

What to know about SQL Server

  • Text is nvarchar with N'...' values, so accents survive; text over 4000 characters becomes nvarchar(max).
  • Yes and no values become bit, and dates with an offset become datetimeoffset.
  • Long values are written in pieces, so sqlcmd and SQL Server Management Studio accept the script.

How each kind of value is stored in SQL Server

ValueSQL Server
Yes and nobit
Whole numbersint
Large whole numbersbigint
Decimalsdecimal(p,s)
Floating-point numbersfloat
Datesdate
Times of daytime
Dates with a timedatetime2
Dates with a time and offsetdatetimeoffset
Textnvarchar(n)nvarchar(max)

Questions about CSV to SQL Server

Not answered here? Write to us from the contact page and a person replies. Contact page

How do I convert CSV to SQL Server?

Drop your file on the converter at the top of this page. It finds the header, reads every value and writes the SQL Server script, listing each fix it made. Download the script and run it with sqlcmd.

What if my CSV uses semicolons or tabs?

The separator is detected: comma, semicolon, tab or vertical bar. You can also set it under More options. With a semicolon, decimal commas such as 1.234,50 are read as numbers.

Which SQL Server types does it use?

Yes and no values become bit, whole numbers int, decimals decimal(p,s), dates date, dates with a time datetime2 and text nvarchar(n). Sizes come from the longest value in each column.

Does it keep leading zeros in SQL Server?

Yes. A code such as 00412 stays text, so SQL Server stores it as nvarchar(8) and the script writes it as N'00412'.

Can it load the data into SQL Server without a script?

No. Download the script and run it with sqlcmd. Loading without a script works for PostgreSQL, MySQL, MariaDB and SQLite, from the desktop app or the command line.

How big can the CSV file be?

The browser reads a CSV as it streams in, so files of several gigabytes work. On an Apple M4 laptop the command line converts a 174 MB CSV of a million rows in under a second.