Unix Technical Forum

Create table as select

This is a discussion on Create table as select within the Sybase forums, part of the Database Server Software category; --> Hi there Is there a way of creating a table in sybase like in oracle CTAS e.g. Create table ...


Go Back   Unix Technical Forum > Database Server Software > Sybase

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 04:06 PM
Maria
 
Posts: n/a
Default Create table as select

Hi there


Is there a way of creating a table in sybase like in oracle CTAS

e.g.

Create table MYTABLE tablespace MYSPACE as select * from
test.mytable


In sybase the only way that I know is bcp out create a table bcp in
and then re name... is there a better way??


Many tanks
Maria
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 04:06 PM
Thomas Richards
 
Posts: n/a
Default Re: Create table as select

You can use SELECT INTO although you have to have this option turned
on for the database.

eg

1> create table mytable
2> (alpha char(1))
3> go
1> select * into mytable2
2> from mytable
3> go

This will copy the data you have too. If you don't want the data add
the condition 'where 1=2' and you'll get just the structure.

It won't copy any indexes or triggers and the job is not done as a
transaction, so it's quicker but you can't roll it back.

Regards
Tom


evoradba@yahoo.ca (Maria) wrote in message news:<351fd9d6.0311201933.4b085f8b@posting.google. com>...
> Hi there
>
>
> Is there a way of creating a table in sybase like in oracle CTAS
>
> e.g.
>
> Create table MYTABLE tablespace MYSPACE as select * from
> test.mytable
>
>
> In sybase the only way that I know is bcp out create a table bcp in
> and then re name... is there a better way??
>
>
> Many tanks
> Maria

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 04:06 PM
Nelson Ricardo
 
Posts: n/a
Default Re: Create table as select

select * from test.mytable into myspace.mytable ?

evoradba@yahoo.ca (Maria) wrote in message news:<351fd9d6.0311201933.4b085f8b@posting.google. com>...
> Hi there
>
>
> Is there a way of creating a table in sybase like in oracle CTAS
>
> e.g.
>
> Create table MYTABLE tablespace MYSPACE as select * from
> test.mytable
>
>
> In sybase the only way that I know is bcp out create a table bcp in
> and then re name... is there a better way??
>
>
> Many tanks
> Maria

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-08-2008, 04:06 PM
Subhas
 
Posts: n/a
Default Re: Create table as select

hi,
select into is a good way of doing it but it is a nonlogged operation
which means after you do it, you cannot backup the transaction log.I
would rather go with creating the table and insert into <tab1> select
* from <tab2>.

Regards

Jaideep
tom.richards@rocketmail.com (Thomas Richards) wrote in message news:<f118866.0311210459.63c97d76@posting.google.c om>...
> You can use SELECT INTO although you have to have this option turned
> on for the database.
>
> eg
>
> 1> create table mytable
> 2> (alpha char(1))
> 3> go
> 1> select * into mytable2
> 2> from mytable
> 3> go
>
> This will copy the data you have too. If you don't want the data add
> the condition 'where 1=2' and you'll get just the structure.
>
> It won't copy any indexes or triggers and the job is not done as a
> transaction, so it's quicker but you can't roll it back.
>
> Regards
> Tom
>
>
> evoradba@yahoo.ca (Maria) wrote in message news:<351fd9d6.0311201933.4b085f8b@posting.google. com>...
> > Hi there
> >
> >
> > Is there a way of creating a table in sybase like in oracle CTAS
> >
> > e.g.
> >
> > Create table MYTABLE tablespace MYSPACE as select * from
> > test.mytable
> >
> >
> > In sybase the only way that I know is bcp out create a table bcp in
> > and then re name... is there a better way??
> >
> >
> > Many tanks
> > Maria

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

« Parameters | Humour »

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:13 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com