Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)
How can I create a table using the data which is already there in another table (copy of table)?

1 Answer

0 votes
by (12.7k points)

The most compact means of copying a table is to:

  1. Initially, create a new table using the "CREATE TABLE" statement
  2. And you have to use "INSERT" based on the "SELECT" from the old table:
INSERT INTO new_table
SELECT * FROM old_table

In the SQL Server, You need to use the "INTO" syntax:

SELECT *
    INTO new_table
  FROM old_table

Because in the SQL Server, the "INTO" clause creates a table that doesn't already present.

Join the SQL Training course now if you want to gain more knowledge in SQL.

Browse Categories

...