How to create a table from an existing table?
Posted in 2000
Topics: General Discussion
I want to create a table from an other table containing data but only few columns will be selected. e.g table table1 has col1, col2, col3, col4 col5 I want to create a table table2 with data from table1.col1 table1.col3 only. a command like "create table2 as select col1, col3 from table1" Thanks
Do you mean you want to create a view or an entirely new table? If you
want to use the same data, real-time, you would want a view. If you
want to take a snapshot of table1, columns 1 and 3, and have it be
static you want to create another table.
create view as 'select table1.col1, table1.col2 from table1';
Otherwise, to create another table, you'd have to create the table
itself, then insert into that table from column1 and column2.
In article <FsLuD3.J1@igsrsparc2.er.usgs.gov>,
"Mahmoud Kamoun" <kamounm@usgs.gov> wrote:
> I want to create a table from an other table containing data but only
few
> columns will be selected.
>
> e.g
>
> table table1 has col1, col2, col3, col4 col5
>
> I want to create a table table2 with data from table1.col1 table1.col3
only.
>
> a command like "create table2 as select col1, col3 from table1"
>
> Thanks
>
>
--
# unrm /
ksh: unrm: not found
# man cpio
Sent via Deja.com http://www.deja.com/
Before you buy.
In article <FsLuD3.J1@igsrsparc2.er.usgs.gov>,
"Mahmoud Kamoun" <kamounm@usgs.gov> wrote:
> I want to create a table from an other table containing data but only
few
> columns will be selected.
>
> e.g
>
> table table1 has col1, col2, col3, col4 col5
>
> I want to create a table table2 with data from table1.col1
table1.col3 only.
>
> a command like "create table2 as select col1, col3 from table1"
>
> Thanks
>
For temporary tables try:
select col1, col2, col3 from table1 into temp table2.
The temp table2 will be only available for the life of the session and
will only be available to the session only. In other words the
temporary table created like this will not be available for the same
user connected to the database from another session.
I cannot think of a way to create a permanent table on the fly.
Other obvious solution to your problem is to first create the table
using the "Create table" syntax.
Create table table2 (col1 char(1),col2 char(2), col3 char(3));
insert into table2 select col1, col2, col3 from table1
You might want to think about the logs when creating temporary tables.
Hope this helps.
Ram S.
>
Sent via Deja.com http://www.deja.com/
Before you buy.