Wednesday, February 1, 2012

create tables

CREATE TABLE Persons
(
P_Id int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
)

--

CREATE a table from another table


CREATE TABLE new_table
AS (SELECT * FROM old_table);

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.

CREATE TABLE suppliers
AS (SELECT companies.id, companies.address, categories.cat_type
FROM companies, categories
WHERE companies.id = categories.id
AND companies.id > 1000);

This would create a new table called suppliers based on columns from both the companies and categories tables.

create a table from another table without copying any values from the old table?

CREATE TABLE new_table
AS (SELECT * FROM old_table WHERE 1=2);

No comments:

Post a Comment