CoolInterview.com - World's Largest Collection of Interview Questions & Answers, FAQs, queries, sample papers, exam papers, dumps, what, why, how, where, when questions
Our Services
Get 9,000 Interview Questions & Answers in an eBook.




Get it now !!
Send your Resume to 6000 Companies

Search Interview Questions

Question: What command is used to create a table by copying the structure of another table?

Answer: CREATE TABLE .. AS SELECT command
Explanation:
To copy only the structure, the WHERE clause of the SELECT command should contain a FALSE statement as in the following.
CREATE TABLE NEWTABLE AS SELECT * FROM EXISTINGTABLE WHERE 1=2;
If the WHERE condition is true, then all the rows or rows satisfying the condition will be copied to the new table.



Category SQL Interview Questions & Answers - Exam Mode / Learning Mode
Rating (0.5) By 681 users
Added on 10/12/2009
Views 11101
Rate it!
Question: What command is used to create a table by copying the structure of another table?
Answer:

CREATE TABLE .. AS SELECT command
Explanation:
To copy only the structure, the WHERE clause of the SELECT command should contain a FALSE statement as in the following.
CREATE TABLE NEWTABLE AS SELECT * FROM EXISTINGTABLE WHERE 1=2;
If the WHERE condition is true, then all the rows or rows satisfying the condition will be copied to the new table. Source: CoolInterview.com


create table <table> as
Select * from <existing Table>
where 1=2; Source: CoolInterview.com

Answered by: paramjeet | Date: 2/9/2009 | Contact paramjeet Contact paramjeet

CREATE TABLE NEWTABLE AS SELECT * FROM EXISTINGTABLE WHERE 1=2;

This one is not working in SQL 2005. Source: CoolInterview.com

Answered by: MSB | Date: 3/11/2009 | Contact MSB Contact MSB

select into newtablename from existing_table_name where 1=2 Source: CoolInterview.com

Answered by: divya | Date: 4/19/2009 | Contact divya Contact divya

in case of sql server thew above command does not work so it has to be modified to the following query.
SELECT * INTO NEWTABLE FROM EXISTINGTABLE WHERE 1=2; Source: CoolInterview.com

Answered by: krishnan | Date: 4/20/2009 | Contact krishnan Contact krishnan

SELECT * INTO NEW_TABLE FROM OLD_TABLE WHERE 1=2
This will copy the entire structure of OLD_TABLE into NEW_TABLE without copying the rows. Source: CoolInterview.com

Answered by: Divya Gupta | Date: 5/28/2009 | Contact Divya Gupta Contact Divya Gupta

SELECT *
INTO <ownername.tablename>
FROM EXISTINGTABLE
WHERE 1=2 Source: CoolInterview.com

Answered by: JM | Date: 7/12/2009 | Contact JM Contact JM

The comman used to create a table by copying the structure of another table in SQL Server is given below:

SELECT TOP 0 *
INTO
NewTableName
FROM SourceTableName

Points to note:-
1) This command will not create the Keys(like Primary, Foreign Key etc.)available in the SourceTableName to the NewTableName.

2) This command will create the Constraints like (not null, default etc.) in the SourceTableName to the NewTableName.
Source: CoolInterview.com

Answered by: Manu Malik | Date: 7/22/2009 | Contact Manu Malik Contact Manu Malik

To copy only the structure of the existing table, we can use like;

SELECT * INTO NEWTABLE FROM EXISTINGTABLE WHERE 1=2; Source: CoolInterview.com

Answered by: Robin Joseph | Date: 8/18/2009 | Contact Robin Joseph Contact Robin Joseph

Create table tablename as(select * from Anothertable name where 1=2 or any invalid conition ) Source: CoolInterview.com

Answered by: Shabbir Alam | Date: 8/19/2009 | Contact Shabbir Alam Contact Shabbir Alam

Select * into tbl1 from tbl2; Source: CoolInterview.com

Answered by: Gaurav | Date: 9/24/2009 | Contact Gaurav Contact Gaurav

Create table table_name as select * from existing_tablename where 1=2 Source: CoolInterview.com

Answered by: Yesvir Singh | Date: 9/26/2009 | Contact Yesvir Singh Contact Yesvir Singh

create table alok as select * from emp;


create table alok as select ename ,empno,sal from emp; Source: CoolInterview.com

Answered by: Alok Kumar Ranjan | Date: 10/3/2009 | Contact Alok Kumar Ranjan Contact Alok Kumar Ranjan

select * into from table1 where 1 = 0 Source: CoolInterview.com

Answered by: A Alagu Ganesh | Date: 10/12/2009 | Contact A Alagu Ganesh Contact A Alagu Ganesh

select * into from <tablename>

This is for sql 2005 Source: CoolInterview.com

Answered by: suganthisekar | Date: 10/29/2009 | Contact suganthisekar Contact suganthisekar

Create table <table name(destination table)> as select * from <table_name(source table)>

We can see by an example:

suppose a table named EMP is already exist in our database. Now we are willing to create a new table named EMP1 with all the contents of EMP in the sense,we have to follow the below syntax
create table EMP1 as select * from emp;
The above command will copy both the structure as well as the contents available in the source table(EMP)
TO copy only the structure of the table eliminating the contents, the command is as follows
Create table EMP1 as select * from EMP where 1=2;
if we are specifying a flase condition in the where clause, only the structure of the table is copied.

Source: CoolInterview.com

Answered by: A.S.Sathish kumar | Date: 11/2/2009 | Contact A.S.Sathish kumar Contact A.S.Sathish kumar

SELECT * INTO <newtable> FROM <existingtable> WHERE 1=2
/*this query is sqlserver*/

Source: CoolInterview.com

Answered by: RAJKANNAN.R | Date: 11/2/2009 | Contact RAJKANNAN.R Contact RAJKANNAN.R

What command is used to create a table by copying the all records of another table?

Ans:SELECT * INTO <newtable> FROM <existingtable>
/*this query is sqlserver*/ Source: CoolInterview.com

Answered by: Rajkannan.R | Date: 11/6/2009 | Contact Rajkannan.R Contact Rajkannan.R

IN Mysql: Create new table exactly like another one

Lets say you have a table at your mysql. Now you want to create a new table which will have exactly the same table structure of old one. Using the LIKE keyword of mysql you can easily create you desired table.

mysql> CREATE TABLE new_table LIKE old_table; Source: CoolInterview.com

Answered by: VIJIN | Date: 11/8/2009 | Contact VIJIN Contact VIJIN

create table <tablename> as select *from <existingtablename> where 1=2; Source: CoolInterview.com

Answered by: Arjun | Date: 1/7/2010 | Contact Arjun Contact Arjun

select * into <new table name> from < existing table> where 1=2 Source: CoolInterview.com

Answered by: Arun Chauhan | Date: 4/14/2010 | Contact Arun Chauhan Contact Arun Chauhan

CREATE TABLE <new_table_name> LIKE <existing_table_name> Source: CoolInterview.com

Answered by: sonali | Date: 5/28/2010 | Contact sonali Contact sonali


If you have the better answer, then send it to us. We will display your answer after the approval

Rules to Post Answers in CoolInterview.com:-

  • There should not be any Spelling Mistakes.
  • There should not be any Gramatical Errors.
  • Answers must not contain any bad words.
  • Answers should not be the repeat of same answer, already approved.
  • Answer should be complete in itself.

Post your answer here

Inform me about updated answers to this question.
Related Questions
View Answer
What will be the output of the following query?
SELECT REPLACE(TRANSLATE(LTRIM(RTRIM('!! ATHEN !!','!'), '!'), 'AN', '**'),'*','TROUBLE') FROM DUAL;
View Answer
What will be the output of the following query?
SELECT DECODE(TRANSLATE('A','1234567890','1111111111'), '1','YES', 'NO' );
View Answer
What does the following query do?
SELECT SAL + NVL(COMM,0) FROM EMP;
View Answer
Which date function is used to find the difference between two dates?
View Answer
Why does the following command give a compilation error?
DROP TABLE &TABLE_NAME;
View Answer
What is the advantage of specifying WITH GRANT OPTION in the GRANT command?
View Answer
What is the use of the DROP option in the ALTER TABLE command?
View Answer
What is the value of comm and sal after executing the following query if the initial value of ?sal? is 10000
UPDATE EMP SET SAL = SAL + 1000, COMM = SAL*0.1;
View Answer
What is the use of DESC in SQL?
View Answer
What is the use of CASCADE CONSTRAINTS?
View Answer
Which function is used to find the largest integer less than or equal to a specific value?
View Answer
What is the output of the following query
SELECT TRUNC(1234.5678,-2) FROM DUAL;
View Answer

Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.

View All SQL Interview Questions & Answers - Exam Mode / Learning Mode




India News Network
Latest 20 Questions
Payment of time- barred debt is: (a) Valid (b) Void (c) Illegal (d) Voidable
Consideration is defined in the Indian Contract Act,1872 in: (a) Section 2(f) (b) Section 2(e) (c) Section 2(g) (d) Section 2(d)
Which of the following is not an exception to the rule, "No consideration, No contract": (a) Natural love and affection (b) Compensation for involuntary services (c) Completed gift (d) Agency
Consideration must move at the desire of: (a) The promisor (b) The promisee (c) The promisor or any other party (d) Both the promisor and the promisee
An offer which is open for acceptance over a period of time is: (a) Cross Offer (b) Counter Offer (c) Standing Offer (d) Implied Offer
Specific offer can be communicated to__________ (a) All the parties of contract (b) General public in universe (c) Specific person (d) None of the above
_________ amounts to rejection of the original offer. (a) Cross offer (b) Special offer (c) Standing offer (d) Counter offer
A advertises to sell his old car by advertising in a newspaper. This offer is caleed: (a) General Offer (b) Special Offer (c) Continuing Offer (d) None of the above
In case a counter offer is made, the original offer stands: (a) Rejected (b) Accepted automatically (c) Accepted subject to certain modifications and variations (d) None of the above
In case of unenforceable contract having some technical defect, parties (a) Can sue upon it (b) Cannot sue upon it (c) Should consider it to be illegal (d) None of the above
If entire specified goods is perished before entering into contract of sale, the contract is (a) Valid (b) Void (c) Voidable (d) Cancelled
______________ contracts are also caled contracts with executed consideration. (a) Unilateral (b) Completed (c) Bilateral (d) Executory
A offers B to supply books @ Rs 100 each but B accepts the same with condition of 10% discount. This is a case of (a) Counter Offer (b) Cross Offer (c) Specific Offer (d) General Offer
_____________ is a game of chance. (a) Conditional Contract (b) Contingent Contract (c) Wagering Contract (d) Quasi Contract
There is no binding contract in case of _______ as one's offer cannot be constructed as acceptance (a) Cross Offer (b) Standing Offer (c) Counter Offer (d) Special Offer
An offer is made with an intention to have negotiation from other party. This type of offer is: (a) Invitation to offer (b) Valid offer (c) Voidable (d) None of the above
When an offer is made to the world at large, it is ____________ offer. (a) Counter (b) Special (c) General (d) None of the above
Implied contract even if not in writing or express words is perfectly _______________ if all the conditions are satisfied:- (a) Void (b) Voidable (c) Valid (d) Illegal
A specific offer can be accepted by ___________. (a) Any person (b) Any friend to offeror (c) The person to whom it is made (d) Any friend of offeree
An agreement toput a fire on a person's car is a ______: (a) Legal (b) Voidable (c) Valid (d) Illegal
Cache = 0.03125 Seconds