SQL Tutorial - insert into Statement


The 'INSERT INTO' statement is a DML statement. It is used to add a single/multiple record(s) into a table.

Here the 'INSERT INTO' statement is executed on the 'Employees' table.

The INSERT INTO Statement


The 'INSERT INTO' statement helps you insert data into a table.

SQL 'INSERT INTO' Syntax


INSERT INTO table
(column-1, column-2, ... column-n)
VALUES (value-1, value-2, ... value-n);

The insert Statement Example

The 'Employees' tables contains the following columns and their respective data type as shown below.

Table Name :

Employees

Column Name Data Type  
EmployeeID smallint Not Null
EmployeeName varchar(50) Not Null
DateOfBirth smalldatetime Not Null
DesignationID smallint Allows Null
DeptID smallint Allows Null
PhoneNo nvarchar(12) Allows Null
City nvarchar(50) Allows Null

The 'Insert  INTO' statement displays all the columns and data from the 'Employees' table as shown below.

INSERT INTO Employees
(EmployeeID, EmployeeName, DateOfBirth, DesignationID, DeptID, PhoneNo, City)
VALUES (9, 'Anthony Frank', '1988-02-22', 2, 2, '323 243 49', 'San Francisco');

The above 'INSERT INTO" statement inserts a new record into the 'Employees' table. Here care must be taken to match the value entered in a particular column to its datatype else the insert will fail. Also note that when entering values for datatypes of char,varchar, nvarchar and date, enclose the values within ' ' such as 'Anthony Frank'. values of datatype int, smallint goes in as is without any quotes.