CREATE a table from another table

Answers were Sorted based on User's Feedback



CREATE a table from another table..

Answer / narendra

select *into newtable from oldtable.

Is This Answer Correct ?    4 Yes 0 No

CREATE a table from another table..

Answer / 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

More SQL Server Interview Questions

Is the log file is a part of file group?

0 Answers  


i have 4 tables.. T1, T2, T3, T4.. these tables have the same structure and they store the information entered in different years.. T1 stored 2002, T2 stored 2003, T3 stored 2004 and T4 stored 2005.. i want to copy contents in T1 to T2, T2 to T3, T3 to T4 and T4 to T1.. how do i do that? Temp tables cannot be used..

4 Answers  


How to use values from other tables in update statements in ms sql server?

0 Answers  


Describe the functionalities that views support.

0 Answers  


What are the purposes and advantages stored procedure?

0 Answers  






Explain log shipping?

0 Answers  


syntax and example for bitmap index in sql???

1 Answers  


What is a transact-sql statement?

0 Answers  


What is an index in a database?

0 Answers  


Does sql server 2000 full-text search support clustering?

0 Answers  


Can we do dml on views?

0 Answers  


What is a derived table?

0 Answers  


Categories