SQL Server INSERT INTO SELECT + Examples

In this article, you will learn about the SQL Server INSERT INTO SELECT statement. We use this statement when we want to insert a row into a table with the data from another table.

We will see a number of examples using this statement. Also, we will see some use cases of this statement.

  • SQL Server insert into select statement
  • SQL Server insert into select with where clause
  • SQL Server insert into select distinct
  • SQL Server insert into select with identity column
  • SQL Server insert into select without identity column
  • SQL Server insert into select with identity_insert on
  • SQL Server insert into select with auto-increment
  • SQL Server insert into select without column names
  • SQL Server insert into select multiple rows
  • SQL Server insert into select from multiple tables
  • SQL Server insert into select from another database
  • SQL Server insert into select from another server
  • SQL Server insert into select avoid duplicates
  • SQL Server insert into select not exists
  • SQL Server insert into select from same table
  • SQL Server insert into select output
  • Insert into select SQL Server temp table

For all the examples, we have used SQL server 2019 express and SQL server management studio.

SQL Server insert into select statement

In case you have to copy data from one SQL server table into another in SQL Server, you can use the INSERT INTO SELECT statement. Let us see a general syntax for using this statement.

INSERT INTO <table1>(column1 , column2, column3)
VALUES(SELECT column1, column2, column3 from <table2>)
  • For example, I have created a table where I have stored the basic information of the top 10 companies in the world by market cap, say dbo.RankCompany.
USE BackupDatabase
GO
CREATE TABLE dbo.RankCompany(
[Rank] int IDENTITY(1,1),
[Company Name] nvarchar(20),
[Country] nvarchar(20)
)
USE BackupDatabase
GO
INSERT INTO dbo.RankCompany(
[Company Name], [Country])
VALUES('Apple', 'USA'),
	('Microsoft', 'USA'),
	('Alphabet', 'USA'),
	('Saudi Aramco', 'Saudi Arabia'),
	('Amazon', 'USA'),
	('Tesla', 'USA'),
	('Meta', 'USA'),
	('NVIDIA', 'USA'),
	('Berkshire Hathaway', 'USA'),
	('TSMC', 'Taiwan')

I have provided the code for the table so that you can try it at your end.

  • Now suppose you want to put this data into another table, but without the rank.
  • In this case you can use the INSERT INTO SELECT statement to copy only the required column into another table.
  • Let us create another table where we want to copy this data.
USE BackupDatabase
GO
CREATE TABLE dbo.Companies(
Company_Name nvarchar(20),
Country nvarchar(20)
)
  • Now I will use the INSERT INTO SELECT statement to copy data from the dbo.RankCompany table into the dbo.Companies table as:
USE BackupDatabase
GO
-- Using the INSERT INTO SELECT statement
INSERT INTO dbo.Companies(Company_Name, Country)
SELECT [Company Name], Country FROM dbo.RankCompany
GO
-- Showing the data of dbo.Companies table
SELECT * FROM dbo.Companies
sql server insert into select
Copied the specified data from one table to another

You can see that the specified data was retrieved from the dbo.RankCompany table and got inserted into the dbo.Company table.

Consider another example.

  • If you have a table named Student containing full details of the students.
sql server insert into select statement
Students Table
  • You want to create a new table where you want to store only the names and College IDs of the students.
  • If the name of the new table is StudentID, you will create the table and insert values using the INSERT INTO SELECT statement as:
USE [master]
GO
--Drop the table if it already exists
DROP TABLE IF EXISTS dbo.StudentID  
--Create the table
CREATE TABLE StudentID(
[First Name] nchar(30),
[Last Name] nchar(30),
CollegeID int
)
--Use INSERT INTO SELECT statement to copy data
INSERT INTO StudentID([First Name],[Last Name], CollegeID)
SELECT [First Name], [Last Name], [College ID] FROM dbo.Student

SELECT * FROM dbo.StudentID
sql server insert into select
StudentID Table
  • We copied the data from sepcific columns from the Student table to the StudentID table.

Hence, you might have learned something about the INSERT INTO SELECT statement. We will discuss more examples of this statement in the upcoming sections.

Read: Advanced Stored Procedure Examples in SQL Server

SQL Server insert into select with where clause

We can also copy the data from one table to another according to a specific condition. In this section, you will learn to use the INSERT INTO SELECT statement with the WHERE clause. Further, we will also use an example for demonstration.

  • We have created a table named Persons storing the basic details of some people.
SQL Server insert into select with where clause
Persons Table
  • You can also create the same table for experiment with the following code:
USE [master]
GO
DROP TABLE IF EXISTS dbo.Persons
CREATE TABLE [dbo].[Persons](
	[First Name] [nchar](10) NOT NULL,
	[Last Name] [nchar](10) NULL,
	[Age] [smallint] NOT NULL,
	[Gender] [nchar](7) NULL,
	[Email] [nchar](30) NULL,
	[Phone] [nchar](20) NOT NULL,
	[Location] [nchar](20) NOT NULL
)
INSERT INTO dbo.Persons
VALUES('Ryan','Williams', 35,'Female', 'williams.ryan@yahoo.com', '+1 808 454 3464', 'Pearl City'),
	  ('Andrew','Brown', 34,'Male', 'andrewcool123@gmail.com', '+1 701 435 9867', 'Medora'),
	  ('Aaron','Wilson', 38,'Male', 'aaronaaron@gmail.com', '+1 701 567 4532', 'Mandan'),
	  ('Jordan','Smith', 35,'Male', 'jordan11101998@yahoo.com', '+1 505 467 2372', 'Taos'),
	  ('August','Taylor', 38,'Female', 'augusttaylor@gmail.com', '+1 206 876 5739', 'Rich Land'),
	  ('Thiago','Allen', 29,'Male', 'allenmelissa@gmail.com', '+1 209 754 2452', 'San Francisco'),
	  ('Emilio','Reid', 32,'Female', 'iamemi@yahoo.com', '+1 540 535 3839', 'Reston'),
	  ('Jax','Jones', 30,'Male', 'jonesjax123@gmail.com', '+1 213 983 8784', 'Fresno'),
	  ('Riley','Moore', 35,'Female', 'sweetriley@yahoo.com', '+1 804 897 0986', 'Ashburn'),
	  ('Heath','Adams', 34,'Male', 'thegreatadams@yahoo.com', '+1 310 754 0476', 'California City')
	  
SELECT * FROM dbo.Persons
  • Consider a situation where you want to create a separate table for the people aged less than 35.
  • You can create a new table and copy the data from the old table to the new table using the INSERT INTO SELECT statement.
USE [master]
GO
DROP TABLE IF EXISTS dbo.NewPersons
CREATE TABLE [dbo].[NewPersons](
	[First Name] [nchar](10) NOT NULL,
	[Last Name] [nchar](10) NULL,
	[Age] [smallint] NOT NULL,
	[Gender] [nchar](7) NULL,
	[Email] [nchar](30) NULL,
	[Phone] [nchar](20) NOT NULL,
	[Location] [nchar](20) NOT NULL
)
INSERT INTO dbo.NewPersons(
[First Name], [Last Name], Age, Gender, Email, Phone, Location)
SELECT [First Name], [Last Name], Age, Gender, Email, Phone, Location
FROM dbo.Persons WHERE Age<35
SELECT * FROM dbo.NewPersons
SQL Server insert into select where
Data Copied using INSERT INTO SELECT with WHERE Clause
  • As you can see the output, we have successfully copied data from the Persons table to the NewPersons table according the required condition.

Read: SQL Server Substring Function [9 Examples]

SQL Server insert into select distinct

We use the DISTINCT keyword to select distinct values from a table. We can use this keyword with the INSERT INTO SELECT statement to copy the distinct values retrieved from one table to another. In this section, we will understand this topic with an example.

  • For example, you have a table SalesTable storing information about the products purchased by the customers.
sql server insert into select distinct
SalesTable Table
  • In case if you want to create a separate Customers table that will store the details of the customer who purchased the products, you can copy data from the SalesTable table.
  • But, there is a challange. Observe the table. It contains duplicate values.
  • How will you remove that redundancy? You can use the DISTINCT keyword while copying data from the another table.
  • Firstly, create a new table with the required columns specifications.
  • Secondly, use the INSERT INTO SELECT statement to copy data.
USE [master]
GO
DROP TABLE IF EXISTS Customers
CREATE TABLE dbo.Customers(
[Customer ID] int,
[Customer Name] nchar(20)
)
INSERT INTO dbo.Customers([Customer ID], [Customer Name])
SELECT DISTINCT CustomerID, Name FROM dbo.SalesTable

SELECT * FROM dbo.Customers
  • After executing the above query, we will get the desired table.
insert into select distinct sql server
Customers Table

Hence, you might have understood how you can use the DISTINCT keyword with the INSERT INTO SELECT statement.

Read: String or binary data would be truncated in SQL Server

SQL Server insert into select with identity column

In this section, you will learn how you use the INSERT INTO SELECT statement with an identity column. We have created an example where we will copy data from one table to another table having an identity column.

  • Suppose you want to create a new table where new employee IDs will be assigned to the employees. Also, you want to use the new Employee ID column as an identity column.
  • You have to import the data from the old table to a new table.
  • For instance, we have created a table named Employees storing the data of employees.
sql server insert into select with identity column
Employees Table
  • We will create a new table NewEmployees where we will use an identity column and import the employees’ data from the Employees table.
USE [master]
GO
DROP TABLE IF EXISTS dbo.NewEmployees
CREATE TABLE dbo.NewEmployees(
EmpID int IDENTITY(10,1),
EmpName nchar(30),
EmpDep nchar(20)
)
INSERT INTO dbo.NewEmployees(EmpName, EmpDep)
SELECT EmpName, EmpDep FROM dbo.Employees

SELECT * FROM dbo.NewEmployees
insert into select with identity column sql server
Imported Data into New Table with Identity Column
  • You can observe that despite we did not mention the EmpID column values, the values are automtically assigned because of being an identity column.

Read SQL Server DateTime vs Datetime2

SQL Server insert into select without identity column

In this section, you will learn how to use the INSERT INTO SELECT statement without the identity column.

  • Consider the example of the following table named TableIdentity having an identity column.
SQL Server insert into select without identity column
TableIdentity Table
  • We will create a new table NewTableIdentity into which we will copy the data.
  • The following query will copy the data from the TableIdentity table to the NewTableIdentity table except the identity column:
USE [master]
GO
DROP TABLE IF EXISTS dbo.NewTableIdentity
CREATE TABLE dbo.NewTableIdentity(
[Employee Name] nchar(20),
[Employee Department] nchar(20)
)
INSERT INTO dbo.NewTableIdentity
([Employee Name],[Employee Department])
SELECT EmpName, EmpDep FROM dbo.TableIdentity
GO
SELECT * FROM dbo.NewTableIdentity
insert into select without identity column SQL Server
Records Inserted Without the Identity Column
  • You can observe in the output that the records are successfully inserted without the identity column.

Read SQL Server stored procedure output parameter

SQL Server insert into select with identity_insert on

In one of the above sections, we have created a table with an identity column. This time we will set the IDENTITY_INSERT option ON and then insert values manually.

  • Consider the same table Employees.
SQL Server insert into select with identity_insert on
Employees Table
  • We will import all the data of this table to the NewEmployees table. But, we will set the IDENTITY_INSERT option to ON first.
USE [master]
GO
DROP TABLE IF EXISTS dbo.NewEmployees
CREATE TABLE dbo.NewEmployees(
EmpID int IDENTITY(10,1),
EmpName nchar(30),
EmpDep nchar(20)
)
SET IDENTITY_INSERT dbo.NewEmployees ON
GO
INSERT INTO dbo.NewEmployees(EmpID, EmpName, EmpDep)
SELECT EmpID, EmpName, EmpDep FROM dbo.Employees

SELECT * FROM dbo.NewEmployees
SET IDENTITY_INSERT dbo.NewEmployees OFF
GO
insert into select with identity_insert on SQL Server
Imported Data with IDENTITY_INSERT ON
  • Hence, you can see that we successfully inserted records into a new table using IDENTITY_INSERT and setting it to ON.

Read: Delete Duplicate Rows in SQL Server

SQL Server insert into select with auto-increment

In this section, you will learn how to use the insert into select statement with auto-increment in SQL Server 2019. If you want to import data from one table to another with automatically incrementing values, you can create an identity column in the new table.

When you create an identity column in the table, the key values for all records are created for reference. These key values increment automatically depending on the seed value and increment value at the time of column creation.

You can create an identity column using the IDENTITY function. We will understand this with the help of an example.

  • Consider the following Customers table. We will assign new customer IDs in the NewCustomers table with auto-increment values.
SQL Server insert into select with auto-increment
Customers Table
  • Firstly, create a table where you want to import the data with the auto-increment option with the IDENTITY function.
USE [master]
GO
DROP TABLE IF EXISTS NewCustomers
CREATE TABLE NewCustomers(
CustomerID int IDENTITY(1000,1),
[Customer Name] nchar(30)
)
INSERT INTO NewCustomers([Customer Name])
SELECT [Customer Name] FROM Customers
SELECT * FROM NewCustomers
  • In the above example, we created an identity column named CustomerID with the initial value of 1000 and the increment value of 1. This means the values will start from 1000 and will auto-increment with the value 1. You can define your own set of values for the identity column.
  • Let us see in the output if we got he expected result.
insert into select with auto-increment sql server
NewCustomers Table
  • As you can see, the values are being auto-incremented and we do not have to insert values manually.

Read: Types of Backup in SQL Server

SQL Server insert into select without column names

In this section, you will learn how to insert values into a table using the SELECT statement and not specifying the column names.

When you use the INSERT INTO SELECT statement, you have to specify some values in the SELECT statement that you want to insert into the table. These can be any values or the column names of the other table.

You will learn how you can use the INSERT INTO SELECT statement without specifying column names i.e. using values only.

  • We have created a table Names having two columns:
    • First Name
    • Last Name
  • Suppose you want to insert values into it using the SELECT statement. You will do this as:
Use [master]
GO
INSERT INTO dbo.Names([First Name], [Last Name])
SELECT 'Geroge' , 'Smith'
GO
SELECT * FROM dbo.Names
SQL Server insert into select without column names
Record Inserted Without using Column Names
  • As you can observe, we have successfully created a record with using column names and using only values.
  • Keep in mind the number of values should be the same as the number of columns in the table into which you are inserting values.

SQL Server insert into select multiple rows

This section will learn how you can insert multiple rows with the INSERT INTO SELECT statement.

You can use the UNION operator to insert multiple rows using the SELECT statement. The UNION operator combines the resultset of two SELECT statements. The following example shows how you can perform this task:

  • Consider the above Names table. The table has two columns:
    • First Name
    • Last Name
  • We will try to insert multiple rows using the select statement.
Use [master]
GO
INSERT INTO dbo.Names([First Name], [Last Name])
SELECT 'Geroge' , 'Smith'
UNION 
SELECT 'Shakes',' Williams'
  • Now we will check if the values are inserted into the table or not.
USE [master]
GO
SELECT * FROM dbo.Names
SQL Server insert into select union
Names Table
  • You can see that the rows are inserted.

Thus, you might have understood how you can use the UNION operator to insert multiple values in a table in SQL Server.

Read: SQL Server Row_Number – Complete tutorial

SQL Server insert into select from multiple tables

This section will learn how you can insert values into a table from multiple tables using the INSERT INTO SELECT statement. Also, you will see an example where we will implement this logic.

You can insert data from multiple tables using SQL Joins. You will see an example where we have used an inner join between two tables to insert data into a new table.

  • Consider the following two tables:
sql server insert into select from multiple tables
Employees Table
insert into select from multiple tables sql server
Department Table
  • We have created two tables:
    • Employees
    • Department
  • We will insert the column values from these two tables to a new table.
  • If we have a new table named EmployeeDetails into which we want to store the employee’s ID, employee’s name, employee’s department, firstly, we will create the table as:
USE [master]
GO
DROP TABLE IF EXISTS dbo.EmployeeDetails
CREATE TABLE dbo.EmployeeDetails(
[Employee ID] int,
[Employee Name] nchar(20),
[Employee Department] nchar(20)
)
  • Then we will insert records into it from the two tables i.e. Employees and Department using INNER JOIN.
USE [master]
GO
INSERT INTO dbo.EmployeeDetails
SELECT Employees.EmpID,Employees.EmpName, Department.DepName
FROM Employees INNER JOIN Department
ON Employees.DepID= Department.DepID
GO
SELECT * FROM dbo.EmployeeDetails
insert into select from multiple tables
Records Inserted into EmployeeDetails Table
  • You can observe that the EmployeeDetails table is filled with values.

Hence, you might have understood how you can use the INSERT INTO SELECT statement in SQL Server.

Read: IDENTITY_INSERT in SQL Server

SQL Server INSERT INTO SELECT from another database

You might face some scenarios where you would want to copy the data from one server to another server. For example, taking a backup of the server using replicas. So, in this section, we will learn how we can do this.

We will use the INSERT INTO SELECT statement to get this task done. We will understand this procedure with the help of an example.

  • You can copy data from one database to another using the below script:
INSERT INTO DestinationDB.schema.table
SELECT * FROM SourceDB.schema.table
  • Let us understand with an example.
  • We have a table Persons in the master database and the schema name is dbo.
  • We will create the same table in the destination database with the same structure.
USE [DemoDB]
GO
DROP TABLE IF EXISTS dbo.Persons
CREATE TABLE dbo.Persons(
[First Name] nchar(20),
[Last Name] nchar(20),
Age int,
Gender nchar(7),
Email nchar(30),
Phone nchar(20),
Location nchar(30)
)
  • Once you have created the table, you can use the below mentioned script to copy data from the master database table to the DemoDB database table:
INSERT INTO DemoDB.dbo.Persons
SELECT * FROM master.dbo.Persons
SQL Server INSERT INTO SELECT from another database
Copied Data from the Source Database to the Destination Database
  • Now you can verify if the records are copied or not.
USE DemoDB
GO
SELECT * FROM dbo.Persons
INSERT INTO SELECT from another database sql server
Persons table in the DemoDB Database

Thus, at the end of this section, you might have seen how easy it is to copy data from one database to another database.

Read: SQL Server Agent won’t start

SQL Server INSERT INTO SELECT from another server

You cannot directly copy data from another server. Firstly, you have to create a connection with another server. Only then you can copy data from another server. You can try the following method to copy data from another server database:

USE [DestinationDB]

SELECT *
INTO DestinationTable
FROM OPENDATASOURCE (
        'SQLNCLI'
        ,'Data Source=<server name>;Initial Catalog=SourceDB;User ID=<userid>;Password=<password>'
        ).[SourceDB].schema.SourceTable
    /* 
            1-  [DestinationDB] means the database into which we will import 
            2-  DestinationTable means create copy table in Destination       database where we want insert record
            3- <server name> means the server name.
            4-  SourceDB means the server database from which we will import.
            5-  userid and password are the login credentials of the SourceDB
            6-  SourceTable is the table in another server from where we will    import data. */

Thus, using the above script, you can import data from one server’s database to another server’s database.

SQL Server insert into select avoid duplicates

In this section, you will learn how to use the INSERT INTO SELECT statement to copy data from one table into another without inserting duplicate values.

The following example will help you to understand this:

  • Consider the two tables Student and StudentID.
SQL Server insert into select avoid duplicates
StudentID Table
insert into select avoid duplicates SQL Server
Student Table
  • You want to copy the records from the Student table to the StudentID table without duplicates. You can write the query as:
USE [master]
GO
INSERT INTO dbo.StudentID([First Name], [Last Name], CollegeID)
SELECT [First Name],
       [Last Name],
	   [College ID]
FROM   dbo.Student
WHERE  NOT EXISTS 
(SELECT * FROM   dbo.StudentID
 WHERE  Student.[College ID] = StudentID.CollegeID)
 GO
 SELECT * FROM dbo.StudentID
  • In the above query, we assume that the college IDs of the students are unique and we can use them for comparison.
  • After comparison, only those records will be selected by the SELECT statement that are not already present in the StudentID table.

Hence, in this way you can insert the records from one table into another table without duplicate records.

SQL Server insert into select not exists

In this section, we will learn how you can use the INSERT INTO SELECT statement with the NOT EXISTS keyword. We use the NOT EXISTS keyword to check for duplicate values. In case the same records are already available in the target table, we can use this keyword with the SELECT statement to avoid redundancy.

We have also used this keyword in the above section also. The above section contains the method to avoid duplicate values with an example. We will see an example again to use the NOT EXISTS keyword.

  • We have a two tables:
    • Persons
    • NewPersons
SQL Server insert into select not exists
Persons Table
insert into select not exists SQL Server
NewPersons Table
  • Suppose you want to copy data from the Persons table to the NewPersons table but do not want duplicate data.
  • In this case, you can use the NOT EXISTS keyword to verify the records if they are already available.
  • You can do this with the following query:
USE [master]
GO
INSERT INTO dbo.NewPersons
SELECT * FROM dbo.Persons
WHERE  NOT EXISTS 
(SELECT * FROM   dbo.NewPersons
 WHERE  Persons.[First Name] = NewPersons.[First Name]) 
 GO
 SELECT * FROM dbo.NewPersons
  • In the above code, we used the NOT EXISTS keyword to find the records that are not already availabe in the NewPersons table.
  • After knowing these records, we inserted these records into the NewPersons table with the INSERT INTO SELECT statement.
insert into select not exists
Records inserted into the NewPersons table with the NOT EXISTS Keyword
  • As you can see in the output, there are no duplicate records.

Hence, you might have understood how you can use the NOT EXISTS keyword with the INSERT INTO SELECT statement to avoid data redundancy.

Read: SQL Server Add Column + Examples

SQL Server insert into select from same table

In this section, you will learn how you can use the INSERT INTO SELECT statement to copy data from the same table.

There are some situations when you would want to modify data in a table. Sometimes, you cannot modify it with the UPDATE statement. So, you insert the records again after some modification. Let us understand this with an example:

  • Consider the table named Names. It has two columns:
    • First Name
    • Last Name
  • Now if you want to add a new column storing the full names i.e First Name + Last Name.
  • You can add a new column Full Name with the ALTER TABLE statement.
USE [master]
GO
ALTER TABLE dbo.Names
ADD [Full Name] nchar(30)
  • The new column will be populated with NULL values.
  • You can insert new records with the following query along with the Full Name:
USE [master]
GO
INSERT INTO dbo.Names([First Name],[Last Name],[Full Name])
SELECT [First Name],[Last Name],[First Name]+[Last Name] FROM dbo.Names
SELECT * FROM dbo.Names
SQL Server insert into select from same table
Records Inserted
  • Now you can remove the records having the NULL values in the Full Name column.
USE [master]
GO
DELETE FROM dbo.Names WHERE [Full Name] IS NULL
SELECT * FROM dbo.Names
insert into select from same table SQL Server
Names Table
  • You have successfully deleted the records having NULL values. Now your table contains the Full Name column that you created from the First Name and the Last Name.

Thus, you might have understood how you can copy and insert the data from the same table in SQL Server using the INSERT INTO SELECT statement.

SQL Server insert into select output

In this section, you will learn how you can use the OUTPUT clause with the INSERT INTO SELECT statement.

We use the OUTPUT clause to see the output of some operations. For example, if we are using the INSERT statement to insert the records, we can use the OUTPUT clause to check which values are inserted into the table. We can also store these values in a table. We can also store this output in a table variable.

We have created an example where we have used the OUTPUT clause with the INSERT INTO SELECT statement.

  • We have a table named Employees. We will copy data from this table into a new table and display the output.
USE [master]
GO
DROP TABLE IF EXISTS dbo.Demo
CREATE TABLE dbo.Demo(
[Employee ID] int,
[Employee Name] nchar(30),
[Department ID] int
)
INSERT INTO dbo.Demo([Employee ID], [Employee Name],[Department ID])
OUTPUT INSERTED.[Employee ID]
SELECT * FROM dbo.Employees
SQL Server insert into select output
The output of Inserted Rows
  • We have chosen the Employee ID column of the Demo table to be shown in the output.
  • You can choose any column of your choice. You can also choose multiple columns to be displayed.

Insert into select SQL Server temp table

You will learn how you can copy data from one table to a temp table in SQL Server. Also, you will see an example of the same thing.

  • We will create a temp table in the tempdb database and copy data into it.
  • Consider the Student table below containing the details of the students.
Insert into select SQL Server temp table
Student Table
  • We will copy the College ID, E mail and Phone columns of this table to a temp table.
  • For this, firstly, create a table in the tempdb database.
USE [tempdb]
GO
DROP TABLE IF EXISTS #demo
CREATE TABLE #demo(
[College ID] int,
[Email] nchar(20),
Phone int
)
  • You can verify if the table is created in the Object Explorer Window.
  • Now we will copy the data from the Student table to the #demo table.
INSERT INTO [dbo].[#demo]
SELECT [College ID], [E mail], Phone FROM [master].[dbo].[Student]
GO
SELECT * FROM [dbo].[#demo]
Insert into select temp table SQL Server
#demo Table
  • We have successfully inserted daata into the table.

You may like the following SQL server tutorials:

Hence, you might be clear about the procedure to use the INSERT INTO SELECT statement to copy data from a table to a temp table in SQL server.

  • SQL Server insert into select statement
  • SQL Server insert into select with where clause
  • SQL Server insert into select distinct
  • SQL Server insert into select with identity column
  • SQL Server insert into select without identity column
  • SQL Server insert into select with identity_insert on
  • SQL Server insert into select with auto-increment
  • SQL Server insert into select without column names
  • SQL Server insert into select multiple rows
  • SQL Server insert into select from multiple tables
  • SQL Server insert into select from another database
  • SQL Server insert into select from another server
  • SQL Server insert into select avoid duplicates
  • SQL Server insert into select not exists
  • SQL Server insert into select from same table
  • SQL Server insert into select output
  • Insert into select SQL Server temp table