Thursday, September 21, 2006

Restrict Row Count (Database) -- Sybase

Yesterday, a co-worker of mine asked me how to restrict the number of rows for his select statements. He only wanted 10-20 row returns but his queries returned thousands. By the way, we are running Sybase 12.0 DBMS.

Here's what we came up with.
1>use database
1> set rowcount 10
2> go
1> select * from table where ID='XXXXX'
2> go

Reset to default definition.
1> set rowcount 0
2> go


Jason L. Froebe said...

When you upgrade to ASE 12.5, you can use top N. For example:

select top 10 * from my_table

esofthub said...

Thanks Jason for the heads-up. We will be upgrading next week to 12.5.

Also, I like 12.5's syntax a lot better for this particular task.