These SQL queries will create the basic table and its fields but not indexes, constraints, or triggers as it is in the existing table.
CREATE AN EMPTY TABLE FROM AN EXISTING TABLE:
Syntax:
CREATE TABLE new_table
AS (SELECT *
FROM old_table WHERE 1=2);
Example:
CREATE TABLE suppliers
AS (SELECT *
FROM companies
WHERE 1=2);
CREATE A TABLE FROM AN EXISTING TABLE WITH DATA:
Syntax:
CREATE TABLE new_table
AS (SELECT *
FROM old_table);
CREATE TABLE suppliers AS (SELECT * FROM companies WHERE id > 1000);
CREATE A TABLE WITH ONLY A FEW COLUMNS FROM AN EXISTING TABLE WITH DATA:
Syntax:
CREATE TABLE new_table
AS (SELECT column_1, column2, ... column_n
FROM old_table);
CREATE TABLE suppliers AS (SELECT id, address, city, state, zip FROM companies WHERE id > 1000);
CREATE A TABLE WITH ONLY A FEW COLUMNS FROM AN EXISTING MULTIPLE TABLES WITH DATA:
Syntax:
CREATE TABLE new_table
AS (SELECT column_1, column2, ... column_n
FROM old_table_1, old_table_2, ... old_table_n);
CREATE TABLE suppliers AS (SELECT companies.id, companies.address, categories.cat_type FROM companies, categories
WHERE companies.id = categories.id AND companies.id > 1000);
No comments:
Post a Comment