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? How would you view the execution plan?

807


What is a partition key?

676


Is sql server difficult to learn?

689


How we can compare two database data?

687


What are parameterized reports?

176






What does it mean to manipulate data?

748


What is a benefit of using an after insert trigger over using a before insert trigger?

724


How to create a stored procedure with a statement block in ms sql server?

747


How to delete duplicate rows?

710


What is explicit mode in sql server?

739


What happens when converting big values to integers?

729


I have triggers,views,functions,stored Procedures for a table. When I am dropping that table which objects are deleted?

779


Why should we go for stored procedures? Why not direct queries?

748


What are the filtered indexes?

780


What is user defined stored procedures?

718