Duplicating Tables
We can create a duplicate of a table using the following query:
CREATE TABLE table_name AS (SELECT STATEMENT);
The above query creates a new table named table_name and inserts the results of the SELECT STATEMENT into it.
Creating an Exact Copy
CREATE TABLE students_duplicate AS SELECT * FROM students;
This query creates a new table called students_duplicate from the result of the query SELECT * FROM students;.
Creating a Concise Table
We can also create a more concise table by selecting specific columns from the target table:
CREATE TABLE students_basic_info AS SELECT name, age FROM students;
This query creates a new table named students_basic_info containing only the first_name and age columns from the students table.
Key Points
- The new table (
table_name) is created with the structure and data of theSELECTquery's result; - This method is useful for creating backups, filtered copies, or summary tables.
Demonstration:
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Ask me questions about this topic
Summarize this chapter
Show real-world examples
Awesome!
Completion rate improved to 1.72
Duplicating Tables
Swipe to show menu
We can create a duplicate of a table using the following query:
CREATE TABLE table_name AS (SELECT STATEMENT);
The above query creates a new table named table_name and inserts the results of the SELECT STATEMENT into it.
Creating an Exact Copy
CREATE TABLE students_duplicate AS SELECT * FROM students;
This query creates a new table called students_duplicate from the result of the query SELECT * FROM students;.
Creating a Concise Table
We can also create a more concise table by selecting specific columns from the target table:
CREATE TABLE students_basic_info AS SELECT name, age FROM students;
This query creates a new table named students_basic_info containing only the first_name and age columns from the students table.
Key Points
- The new table (
table_name) is created with the structure and data of theSELECTquery's result; - This method is useful for creating backups, filtered copies, or summary tables.
Demonstration:
Thanks for your feedback!