You can also create a table from an existing table by copying the existing table's columns.
It is important to note that when creating a table in this way, the new table will be populated with the records from the existing table (based on the SQL SELECT Statement).
Syntax #1 - Copying all columns from another table
The syntax for CREATING a table by copying all columns from another table is:
CREATE TABLE new_table
AS (SELECT * FROM old_table);
For Example:
CREATE TABLE suppliers
AS (SELECT *
FROM companies
WHERE id > 1000);
This would create a new table called suppliers that included all columns from the companies table.
If there were records in the companies table, then the new suppliers table would also contain the records selected by the SELECT statement.
No comments:
Post a Comment