Unix Technical Forum

Select with serial number column

This is a discussion on Select with serial number column within the SQL Server forums, part of the Microsoft SQL Server category; --> Hi Friends, Help me in retrieving a table with a SNo column Select Name From SysObjects Where type = ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-01-2008, 03:24 PM
ArunDhaJ
 
Posts: n/a
Default Select with serial number column

Hi Friends,
Help me in retrieving a table with a SNo column

Select Name From SysObjects Where type = 'U' Order By Name asc

the above query would fetch the Table names. as

Name
Table1
Table2
Table3
Table4

i need a view which should also include the serial number

SNo Name
1 Table1
2 Table2
3 Table3
4 Table4

Regards,
ArunDhaJ

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-01-2008, 03:24 PM
Erland Sommarskog
 
Posts: n/a
Default Re: Select with serial number column

ArunDhaJ (arundhaj@gmail.com) writes:
> Help me in retrieving a table with a SNo column
>
> Select Name From SysObjects Where type = 'U' Order By Name asc
>
> the above query would fetch the Table names. as
>
> Name
> Table1
> Table2
> Table3
> Table4
>
> i need a view which should also include the serial number
>
> SNo Name
> 1 Table1
> 2 Table2
> 3 Table3
> 4 Table4


On SQL 2005:

SELECT name, row_number() OVER(ORDER BY Name)
FROM sysobjects
ORDER BY name

On SQL 2000:

SELECT name, (SELECT COUNT(*) FROM sysobjects b
WHERE a.name <= b.name)
FROM sysobjects
ORDER BY name

On for larger data sets, the performance of the SQL 2000 solution is
so poor that it is about unusual. The alternative is to bounce data over
a temp table with an IDENTITY column.

The SQL 2005 solution has excellent performance.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-01-2008, 03:24 PM
ArunDhaJ
 
Posts: n/a
Default Re: Select with serial number column

On Jul 2, 2:13 pm, Erland Sommarskog <esq...@sommarskog.se> wrote:
> ArunDhaJ (arund...@gmail.com) writes:
> > Help me in retrieving a table with a SNo column

>
> > Select Name From SysObjects Where type = 'U' Order By Name asc

>
> > the above query would fetch the Table names. as

>
> > Name
> > Table1
> > Table2
> > Table3
> > Table4

>
> > i need a view which should also include the serial number

>
> > SNo Name
> > 1 Table1
> > 2 Table2
> > 3 Table3
> > 4 Table4

>
> On SQL 2005:
>
> SELECT name, row_number() OVER(ORDER BY Name)
> FROM sysobjects
> ORDER BY name
>
> On SQL 2000:
>
> SELECT name, (SELECT COUNT(*) FROM sysobjects b
> WHERE a.name <= b.name)
> FROM sysobjects
> ORDER BY name
>
> On for larger data sets, the performance of the SQL 2000 solution is
> so poor that it is about unusual. The alternative is to bounce data over
> a temp table with an IDENTITY column.
>
> The SQL 2005 solution has excellent performance.
>
> --
> Erland Sommarskog, SQL Server MVP, esq...@sommarskog.se
>
> Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books...
> Books Online for SQL Server 2000 athttp://www.microsoft.com/sql/prodinfo/previousversions/books.mspx- Hide quoted text -
>
> - Show quoted text -


Thanks Erland

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:33 PM.


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