Can you create a table having same structure of another table only name differ and having no data of olf table?

Showing Answers 1 - 1 of 1 Answers

sreekanth

  • Nov 21st, 2006
 

create table tablename2 (variables ) as select (variables) from tableprevious

  Was this answer useful?  Yes

satish

  • Nov 22nd, 2006
 

Its simple to create a table structure (with out data) from other table by:

Create new_table as select * from old_table where 1=2;

  Was this answer useful?  Yes

TANVEER

  • Nov 22nd, 2006
 

CREATE TABLE  <Any-table-name>

AS

SELECT *

FROM <table-name>

WHERE 1=2;

Mark

  • Dec 2nd, 2006
 

In SQL Server:

Select top 0 *

into table_destination

from table_source

  Was this answer useful?  Yes

Pawan Ahuja

  • Dec 3rd, 2006
 

create table tab_name as select * from old_tab_name

where 1=2;

Regards

Pawan Ahuja

  Was this answer useful?  Yes

faheem quadri

  • Dec 16th, 2006
 

create table <new table name>as select * from<original tablename> where 1>2;

  Was this answer useful?  Yes

To create a table in oracle from using the existing table without taking records from the original table  .The command will be

Create table <table name > as select * from <oldtable name > where condition which should not ture in the old table

e.g

create table t1 as select * from t2 where age=0;

in above example age can not be 0 for any value.

So , in above case only the sturcture of the table will copy and no records will be there in the new table .

  Was this answer useful?  Yes

Rohan Deshpande

  • Jan 30th, 2007
 

create table as select * from where 4=5; we must mention the condition in where clause.and that condition should not satisfy.so you can give any condition.

  Was this answer useful?  Yes

Create table tab1 as select * from tab2 where 1=2;


In where clause give any condition which never satisfies,just like the above condition.
Never  will be 1 equal to 2.Hence it fails and only the structure of tab2 will be created as structure of tab1.

  Was this answer useful?  Yes

rakhee

  • Nov 20th, 2007
 

Yes, Suppose you have a table emp and you want to create another table emp1 with same structure as wmp with no rows then create table emp1
as
select * from emp
where 0=1;

  Was this answer useful?  Yes

Mohammad salman

  • Sep 29th, 2018
 

its not working,,,,
error is that
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword As.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions