SQL COPY TABLE

If you want to copy the data of one SQL table into another SQL table in the same SQL server, then it is possible by using the SELECT INTO statement in SQL.

The SELECT INTO statement in Structured Query Language copies the content from one existing table into the new table. SQL creates the new table by using the structure of the existing table.

Syntax of SELECT INTO statement in SQL

Examples of SELECT INTO statement in SQL

In this article, we have taken the following three different SQL examples which will help you how to copy the content of one table into another table in SQL:

Example 1: In this example, we have a table called Cars with three columns:

Car NameCar ColorCar Cost
Hyundai CretaWhite10,85,000
Hyundai VenueWhite9,50,000
Hyundai i20Red9,00,000
Kia SonetWhite10,00,000
Kia SeltosBlack8,00,000
Swift DezireRed7,95,000

Table: Cars

  • Suppose you want to copy the content of the above Car table into the new table Car_Details. For this, you have to type the following query in SQL:
  • Let's check the Car_Details table is created successfully or not in the database:
Car NameCar ColorCar Cost
Hyundai CretaWhite10,85,000
Hyundai VenueWhite9,50,000
Hyundai i20Red9,00,000
Kia SonetWhite10,00,000
Kia SeltosBlack8,00,000
Swift DezireRed7,95,000

Table: Car_Details

Example 2: In this example, we have a table called Employee with four columns:

Emp_IdEmp_NameEmp_SalaryEmp_City
201Abhay25000Goa
202Ankit45000Delhi
203Bheem30000Goa
204Ram29000Goa
205Sumit40000Delhi
  • Suppose you want to copy the record of the above Employee table into the new table Coding_Employees. For this, you have to type the following query in SQL:
  • Let's check the Coding_Employees table is created successfully or not in the database:
Emp_IdEmp_NameEmp_SalaryEmp_City
201Abhay25000Goa
202Ankit45000Delhi
203Bheem30000Goa
204Ram29000Goa
205Sumit40000Delhi

Table: Coding_Employees

Example 3: In this example, we have a table called Student with four columns:

RollNoNameMarksAge
1001Bhanu8817
1002Raman8216
1003Sumit8016
1004Shobhit9515
1005Akash8516

Table: Student

  • Suppose you want to copy the record of the above Student table into the new table Class_12_Students. For this, you have to type the following query in SQL:
  • Let's check the table is Class_12_Students table created successfully or not in the database:
RollNoNameMarksAge
1001Bhanu8817
1002Raman8216
1003Sumit8016
1004Shobhit9515
1005Akash8516

Table: Class_12_Students

Example 4: In this example, we have a table called Cars with three columns:

Car NameCar ColorCar Cost
Hyundai CretaWhite10,85,000
Hyundai VenueWhite9,50,000
Hyundai i20Red9,00,000
Kia SonetWhite10,00,000
Kia SeltosBlack8,00,000
Swift DezireRed7,95,000

Table: Cars

  • Suppose you want to copy Car_Color and Car_Name columns of the above Cars table into the new table Car_Color. For this, you have to type the following query in SQL:
  • Let's check the Car_Color table is created successfully or not in the database:
Car NameCar Color
Hyundai CretaWhite
Hyundai VenueWhite
Hyundai i20Red
Kia SonetWhite
Kia SeltosBlack
Swift DezireRed

Table: Car_Color

Syntax of SELECT INTO statement with WHERE clause in SQL

Examples of SELECT INTO statement with WHERE clause in SQL

Here, we have taken the following three different SQL examples, which will help you how to copy the content of one table into another table with a specific condition in SQL:

Example 1: In this example, we have a table called Cars with three columns:

Car NameCar ColorCar Cost
Hyundai CretaBlack10,85,000
Hyundai VenueBlack9,50,000
Hyundai i20Red9,00,000
Kia SonetWhite10,00,000
Kia SeltosBlack8,00,000
Swift DezireRed7,95,000

Table: Cars

  • Suppose we want to copy only the record of those cars whose color is black. For this, we have to type the following query in SQL:
  • Let's check the Black_Car_Details table is created successfully or not in the database:
Car NameCar ColorCar Cost
Hyundai CretaBlack10,85,000
Hyundai VenueBlack9,50,000
Kia SeltosBlack8,00,000

Table: Black_Car_Details

Example 2: In this example, we have a table called Employee with four columns:

Emp_IdEmp_NameEmp_SalaryEmp_City
201Abhay45000Goa
202Ankit45000Delhi
203Bheem38000Goa
204Ram49000Goa
205Sumit40000Delhi

Table: Employee

  • Suppose we want to copy only the record of those employees whose Salary is more than 40,000. For this, we have to type the following query in SQL:
  • Let's check the Emp_Salary_40000 table created successfully or not in the database:
Emp_IdEmp_NameEmp_SalaryEmp_City
201Abhay45000Goa
202Ankit45000Delhi
204Ram49000Goa

Table: Emp_Salary_40000


Next TopicSQL TEMP TABLE




Latest Courses