dbTalk Databases Forums  

Create Copy of Table with Subset of Rows

sybase.public.sqlanywhere.general sybase.public.sqlanywhere.general


Discuss Create Copy of Table with Subset of Rows in the sybase.public.sqlanywhere.general forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
PaulR
 
Posts: n/a

Default Create Copy of Table with Subset of Rows - 04-05-2006 , 11:07 AM






How do I do 'create table tab1 as select * from tab2
where...' (Oracle syntax) in Sybase?

Reply With Quote
  #2  
Old   
Richard Biffl
 
Posts: n/a

Default Re: Create Copy of Table with Subset of Rows - 04-05-2006 , 11:45 AM






According to the 9.0.2 docs (SELECT statement, SQL syntax), and not tested:

SELECT *
INTO dba.tab1
FROM tab2

If you can specify the select-list columns, you don't need to specify an
owner-name for the new table:

SELECT c1, c2, c3
INTO tab2
FROM tab2

Richard

<PaulR> wrote

Quote:
How do I do 'create table tab1 as select * from tab2
where...' (Oracle syntax) in Sybase?



Reply With Quote
  #3  
Old   
Richard Biffl
 
Posts: n/a

Default Re: Create Copy of Table with Subset of Rows - 04-05-2006 , 12:13 PM



Typo: Second example should be:

SELECT c1, c2, c3
INTO tab1
FROM tab2

BTW, Jasper developers, the need for an owner name, when the select-list has
a * instead of specified columns, seems kludgey.

Richard


"Richard Biffl" <sybaseforums (AT) removvethiisphrraseblacklettersoftware (DOT) com>
wrote in message news:4433e608$1 (AT) forums-1-dub (DOT) ..
Quote:
According to the 9.0.2 docs (SELECT statement, SQL syntax), and not
tested:

SELECT *
INTO dba.tab1
FROM tab2

If you can specify the select-list columns, you don't need to specify an
owner-name for the new table:

SELECT c1, c2, c3
INTO tab2
FROM tab2

Richard

PaulR> wrote

How do I do 'create table tab1 as select * from tab2
where...' (Oracle syntax) in Sybase?





Reply With Quote
  #4  
Old   
PaulR
 
Posts: n/a

Default Re: Create Copy of Table with Subset of Rows - 04-05-2006 , 12:17 PM



Thanks Richard - unfortunately I now get a error :

Syntax error or access violation: near '.' in * into

SQL is :

select * into DBA.client_master_new
from client_master a
where a.effective_date = (select max(b.effective_date)
from client_master b
where b.client_no =
a.client_no)

Paul

Quote:
According to the 9.0.2 docs (SELECT statement, SQL syntax)
, and not tested:

SELECT *
INTO dba.tab1
FROM tab2

If you can specify the select-list columns, you don't need
to specify an owner-name for the new table:

SELECT c1, c2, c3
INTO tab2
FROM tab2

Richard

PaulR> wrote in message
news:4433ccf4.631f.1681692777 (AT) sybase (DOT) com... How do I do
'create table tab1 as select * from tab2 where...'
(Oracle syntax) in Sybase?



Reply With Quote
  #5  
Old   
Greg Fenton
 
Posts: n/a

Default Re: Create Copy of Table with Subset of Rows - 04-05-2006 , 12:42 PM



PaulR wrote:
Quote:
How do I do 'create table tab1 as select * from tab2
where...' (Oracle syntax) in Sybase?
Richard is right that you can insert to a table with a select (INSERT
.... SELECT), but this won't create the table.

You can use the TSQL way of creating temporary tables:

SELECT *
INTO #my_temp_table
FROM tab2

(though, of course, no one would ever code "*" ... they would explicitly
list the columns their query requires/expects).

greg.fenton
--
Greg Fenton
Consultant, Solution Services, iAnywhere Solutions
--------
Visit the iAnywhere Solutions Developer Community
Whitepapers, TechDocs, Downloads
http://www.ianywhere.com/developer/


Reply With Quote
  #6  
Old   
Breck Carter [Team iAnywhere]
 
Posts: n/a

Default Re: Create Copy of Table with Subset of Rows - 04-05-2006 , 01:14 PM



Allow me to retort... this is a *perfect* place to use * if you want a
complete copy of the table... why on earth would you want to expose
yourself to a coding error such as missing out on a needed column?

On 5 Apr 2006 09:42:10 -0800, Greg Fenton
<greg.fenton_nospam_ (AT) ianywhere (DOT) com> wrote:

Quote:
PaulR wrote:
How do I do 'create table tab1 as select * from tab2
where...' (Oracle syntax) in Sybase?

Richard is right that you can insert to a table with a select (INSERT
... SELECT), but this won't create the table.

You can use the TSQL way of creating temporary tables:

SELECT *
INTO #my_temp_table
FROM tab2

(though, of course, no one would ever code "*" ... they would explicitly
list the columns their query requires/expects).

greg.fenton
--
Breck Carter [Team iAnywhere]
RisingRoad SQL Anywhere and MobiLink Professional Services
www.risingroad.com
The book: http://www.risingroad.com/SQL_Anywhe...ers_Guide.html
breck.carter (AT) risingroad (DOT) com


Reply With Quote
  #7  
Old   
Breck Carter [Team iAnywhere]
 
Posts: n/a

Default Re: Create Copy of Table with Subset of Rows - 04-05-2006 , 01:19 PM



Is that the *exact* SQL you used? Because this works OK for me in
9.0.2.3267:

select * into DBA.RowGenerator_new
from dbo.RowGenerator a
where a.row_num = (select max(b.row_num)
from dbo.RowGenerator b
where b.row_num = a.row_num)


Breck

On 5 Apr 2006 09:17:26 -0800, PaulR wrote:

Quote:
Thanks Richard - unfortunately I now get a error :

Syntax error or access violation: near '.' in * into

SQL is :

select * into DBA.client_master_new
from client_master a
where a.effective_date = (select max(b.effective_date)
from client_master b
where b.client_no =
a.client_no)

Paul

According to the 9.0.2 docs (SELECT statement, SQL syntax)
, and not tested:

SELECT *
INTO dba.tab1
FROM tab2

If you can specify the select-list columns, you don't need
to specify an owner-name for the new table:

SELECT c1, c2, c3
INTO tab2
FROM tab2

Richard

PaulR> wrote in message
news:4433ccf4.631f.1681692777 (AT) sybase (DOT) com... How do I do
'create table tab1 as select * from tab2 where...'
(Oracle syntax) in Sybase?


--
Breck Carter [Team iAnywhere]
RisingRoad SQL Anywhere and MobiLink Professional Services
www.risingroad.com
The book: http://www.risingroad.com/SQL_Anywhe...ers_Guide.html
breck.carter (AT) risingroad (DOT) com


Reply With Quote
  #8  
Old   
Richard Biffl
 
Posts: n/a

Default Re: Create Copy of Table with Subset of Rows - 04-05-2006 , 05:42 PM



As of 9.0.1, SELECT ... INTO ... can create a permanent table and populate
it.

Richard


"Greg Fenton" <greg.fenton_nospam_ (AT) ianywhere (DOT) com> wrote

Quote:
Richard is right that you can insert to a table with a select (INSERT
... SELECT), but this won't create the table.



Reply With Quote
  #9  
Old   
Greg Fenton
 
Posts: n/a

Default Re: Create Copy of Table with Subset of Rows - 04-05-2006 , 10:57 PM



Richard Biffl wrote:
Quote:
As of 9.0.1, SELECT ... INTO ... can create a permanent table and populate
it.
Man, I love these newsgroups...I keep learning and learning and learning...

greg.fenton
--
Greg Fenton
Consultant, Solution Services, iAnywhere Solutions
--------
Visit the iAnywhere Solutions Developer Community
Whitepapers, TechDocs, Downloads
http://www.ianywhere.com/developer/


Reply With Quote
  #10  
Old   
Paul Rowe
 
Posts: n/a

Default Re: Create Copy of Table with Subset of Rows - 04-06-2006 , 04:08 AM



Yes - that's the exact SQL. But I'm using 9.0.0.1108 -
could that be the difference?

Paul


Quote:
Is that the *exact* SQL you used? Because this works OK
for me in 9.0.2.3267:

select * into DBA.RowGenerator_new
from dbo.RowGenerator a
where a.row_num = (select max(b.row_num)
from dbo.RowGenerator b
where b.row_num = a.row_num)


Breck

On 5 Apr 2006 09:17:26 -0800, PaulR wrote:

Thanks Richard - unfortunately I now get a error :

Syntax error or access violation: near '.' in * into

SQL is :

select * into DBA.client_master_new
from client_master a
where a.effective_date = (select max(b.effective_date)
from client_master b
where b.client_no =
a.client_no)

Paul

According to the 9.0.2 docs (SELECT statement, SQL
syntax) >> , and not tested:

SELECT *
INTO dba.tab1
FROM tab2

If you can specify the select-list columns, you don't
need >> to specify an owner-name for the new table:

SELECT c1, c2, c3
INTO tab2
FROM tab2

Richard

PaulR> wrote in message
news:4433ccf4.631f.1681692777 (AT) sybase (DOT) com... How do I
do >> > 'create table tab1 as select * from tab2 where...'
(Oracle syntax) in Sybase?



--
Breck Carter [Team iAnywhere]
RisingRoad SQL Anywhere and MobiLink Professional Services
www.risingroad.com
The book:

http://www.risingroad.com/SQL_Anywhe...ers_Guide.html
breck.carter (AT) risingroad (DOT) com

Reply With Quote
Reply




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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.