Code has been added to clipboard!

INSERT INTO – SQL Data Insertion

Reading time 1 min
Published Aug 9, 2017
Updated Oct 9, 2019

TL;DR – To insert new records in a table, the INSERT INTO statement is used. You can insert a whole new row and or just the selected data.

Inserting values into specified column names

Example
INSERT INTO mytable_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);

Adding values for all the table columns

Example
INSERT INTO mytable_name
VALUES (value1, value2, value3, ...);

Example using a demo database

The Developers table

ID Name City Country
1 Tom Kurkutis New York USA
2 Ana Fernandez London UK
3 Antonio Indigo Paris France
4 Aarav Kaelin Delhi India
5 Andrew Tumota Miami USA

Inserting a new row

Example
INSERT INTO Developers (Name, City, Country)
VALUES ('Luke Christon', 'London', 'UK');

The result

ID Name City Country
1 Tom Kurkutis New York USA
2 Ana Fernandez London UK
3 Antonio Indigo Paris France
4 Aarav Kaelin Delhi India
5 Andrew Tumota Miami USA
6 Luke Christon London UK

Note: the ID column is automatically updated with a unique number for each table record.

Inserting a row with data in two columns

Example
INSERT INTO Customers (Name, City)
VALUES ('Winston Wellington', 'Oslo');

The result

ID Name City Country
1 Tom Kurkutis New York USA
2 Ana Fernandez London UK
3 Antonio Indigo Paris France
4 Aarav Kaelin Delhi India
5 Andrew Tumota Miami USA
6 Luke Christon London UK
7 Winston Wellington Oslo Null
Learn SQL
Introduction
Syntax
Data Types
Server Data Types
Commands
Commands List
Wildcards
Constraints
Aggregate Functions
Date Functions
Date Format
Injection
SQL Server Hosting
Views
Auto-incrementation
SQL Operators
AS
AND & OR
IN
BETWEEN
WHERE
GROUP BY
HAVING
ORDER BY
LIKE
NOT
NOT EQUAL
UNION
NULL
NOT NULL
DEFAULT
UNIQUE
FOREIGN KEY
PRIMARY KEY
CHECK
Indexes
ALTER TABLE
CREATE DATABASE
CREATE TABLE
DELETE
DROP
INSERT INTO SELECT
INSERT INTO
SELECT
SELECT DISTINCT
SELECT INTO
SELECT TOP
UPDATE
FULL OUTER JOIN
INNER JOIN
JOIN
LEFT JOIN
RIGHT JOIN
AVG()
COUNT
FIRST
LAST
MAX
MIN()
SUM()
LEN
UCASE
MID
NOW
ROUND
FORMAT
LOWER
CONVERT
ISNULL