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

How to select true false based on column value in sql server?

0 Answers  


How to create a simple stored procedure in ms sql server?

0 Answers  


What is Transparent Data Encryption?

0 Answers  


How to handle errors in Stored Procedures.

2 Answers   Accenture,


What is the maximum length of an alert name?

0 Answers  






What is dirty read?

0 Answers  


Differentiate between a having clause and a where clause.

0 Answers  


How do I setup a sql server database?

0 Answers  


There is a trigger defined for INSERT operations on a table, in an OLTP system. The trigger is written to instantiate a COM object and pass the newly insterted rows to it for some custom processing. What do you think of this implementation? Can this be implemented better?

1 Answers  


Explain the properties of subqueries in sql server?

0 Answers  


Why Do you want to work in this company?

4 Answers   HCL,


What are the ways available in sql server to execute sql statements?

0 Answers  


Categories