There are different ways of inserting values into a database table using INSERT INTO statement, as per the requirement of the Database Administrator (DBA). So, let us discuss them one by one.
SQL INSERT INTO Statement
- The INSERT INTO statement is used to add new data to a database.
- The INSERT INTO statement adds a new record to a table.
- INSERT INTO can contain values for some or all of its columns.
- INSERT INTO can be combined with a SELECT to insert a record.
Make sure you have admin privileges before creating any database. Once a database is created, you can check it in the list of databases with the following SQL command: SHOW DATABASES;
- CREATE DATABASE databasename;
- CREATE DATABASE Organization;
- CREATE TABLE table_name (
- column1 datatype,
- column2 datatype,
- column3 datatype,
- ....
- );
- CREATE TABLE Persons
- (
- PersonID int,
- LastName varchar(255),
- FirstName varchar(255),
- Address varchar(255),
- City varchar(255)
- );
- select * from persons

Method 1
- INSERT INTO table-name (column-names) VALUES (values) ;
- INSERT INTO Persons (PersonID, LastName, FirstName, Address, City)
- VALUES ('101', 'Erichsen', 'Tom', 'Street no-21', 'New York');
- INSERT INTO Persons (PersonID, LastName, FirstName, Address, City)
- VALUES ('102', 'Johnson', 'Marry', 'Old Street Road-43', 'California');

Method 2
- INSERT INTO Persons (PersonID, LastName,FirstName)
- VALUES ('103', 'Steve','Rossy')

Method 3
- INSERT INTO Persons VALUES ('104', 'Allen', 'Ketty', 'South Side Road', 'U.S.');
- select * from persons

Method 4
- INSERT INTO table-name (column-names)
- SELECT column-names
- FROM table-name
- WHERE condition
Here, the condition is that the number of columns and respective data types returned in a select query should match with the insert table command.


- CREATE TABLE [dbo].[Manager](
- [ManagerID] [int] ,
- [ManagerName] [varchar](50) NULL,
- [ContactName] [varchar](50) NULL,
- [Address1] [varchar](100) NULL,
- [City] [varchar](50) NULL,
- [PostalCode] [varchar](50) NULL,
- [Country] [varchar](50) NULL,
- [salary] [int] NULL
- )

- select * into CustomerCopy from Customer
The into <New Table> clause is used to copy the result set into a new table that does not exist in the database. In the above query, it creates a new table "CustomerCopy" from "Customer" table data.
The following query creates a new temporary table from the query result set.
- select * into #tmpCustomerCopy from Customer
Create a stored procedure that returns data of table “Customer”.
- create procedure spGetCustDetails as
- begin
- select * from Customer
- end
- insert into Customer
- exec spGetCustDetails
Here, the number of columns returned by the stored procedure should match with the inserting table (Customer). We can also specify the columns in the query to insert particular columns data.
Note: It is not possible to insert stored procedure result set data into a new table. Thus, create a table based on the result set returned by the stored procedure.

jose loraPosted Aug 26, 2021, 2:06 PM
Excelent post
Praveen KumarPosted Jun 17, 2019, 6:52 AM
Nice Post Priyanka.