CREATE a table from another table

Answer Posted / mohammadali.info

Syntax #1 - Copying all columns from another table

The basic syntax is:

CREATE TABLE new_table
AS (SELECT * FROM old_table);


For example:

CREATE TABLE suppliers
AS (SELECT *
FROM companies
WHERE id > 1000);

Syntax #2 - Copying selected columns from another table

The basic syntax is:

CREATE TABLE new_table
AS (SELECT column_1, column2, ... column_n FROM old_table);


For example:

CREATE TABLE suppliers
AS (SELECT id, address, city, state, zip
FROM companies
WHERE id > 1000);

Syntax #3 - Copying selected columns from multiple tables

The basic syntax is:

CREATE TABLE new_table
AS (SELECT column_1, column2, ... column_n
FROM old_table_1, old_table_2, ... old_table_n);


For example:

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

Is This Answer Correct ?    4 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is an execution plan? When would you use it?

570


What are the different authentication modes in sql server?

566


What is the order by used for?

613


What are triggers in ms sql server?

597


What is importing utility?

544






What is database mirroring?

561


What is function of ROLLUP ?

640


What is the significance of null value and why should we avoid permitting null values?

528


How many columns can we include on clustered index ?

507


Does a full backup include transaction log?

476


How to delete multiple rows with one delete statement in ms sql server?

509


How to check status of stored procedure in sql server?

440


what's the maximum size of a row? : Sql server database administration

539


How to list all objects in a given schema?

558


What is change tracking in sql server?

539