dbaspot
Tags Register FAQ Calendar Search Today's Posts Mark Forums Read

how to add identity column to a view - sqlserver-server

This is a discussion on how to add identity column to a view - sqlserver-server ; hi all, how to add identity column to a view in sql server 2000. plz help....


Home > Database Forum > Microsoft SQL Server > sqlserver-server > how to add identity column to a view

Reply

 

LinkBack Thread Tools Display Modes
  #1  
Old 12-20-2007, 10:16 AM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default how to add identity column to a view

hi all,

how to add identity column to a view in sql server 2000.
plz help.

Reply With Quote
  #2  
Old 12-20-2007, 10:38 AM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: how to add identity column to a view

Amit,

Sorry, but you cannot add an identity column to a view. What is your need?
Are you trying to get a row number attached to each row returned? Must it
be in a view or can you use some other mechanism?

You can do the following, but it will get expensive if the result set is
quite large.

SELECT (select count(*) from MyTable where KeyColumn <= a.KeyColumn) AS
RowNumber, a.*
FROM MyTable AS a
ORDER BY RowNumber

RLF

"amit sharma" wrote in message
news:351A9D82-3E62-465C-90AE-1405C2747667@microsoft.com...
> hi all,
>
> how to add identity column to a view in sql server 2000.
> plz help.
>



Reply With Quote
  #3  
Old 12-20-2007, 01:40 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default RE: how to add identity column to a view

Hi

Along with Russells reply..

You should probably add the "row number" in the client application as this
would be the most efficient way to generate a sequence number.

John

"amit sharma" wrote:

> hi all,
>
> how to add identity column to a view in sql server 2000.
> plz help.
>

Reply With Quote
  #4  
Old 12-21-2007, 12:55 AM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: how to add identity column to a view

hi Russell,
thanx for your reply.
i have a table with identity column and values are not continous in that
column.
thats why i want to create a view which has continous values in identity
column.
so that i can implement custom paging in my front end application.



"Russell Fields" wrote:

> Amit,
>
> Sorry, but you cannot add an identity column to a view. What is your need?
> Are you trying to get a row number attached to each row returned? Must it
> be in a view or can you use some other mechanism?
>
> You can do the following, but it will get expensive if the result set is
> quite large.
>
> SELECT (select count(*) from MyTable where KeyColumn <= a.KeyColumn) AS
> RowNumber, a.*
> FROM MyTable AS a
> ORDER BY RowNumber
>
> RLF
>
> "amit sharma" wrote in message
> news:351A9D82-3E62-465C-90AE-1405C2747667@microsoft.com...
> > hi all,
> >
> > how to add identity column to a view in sql server 2000.
> > plz help.
> >

>
>
>

Reply With Quote
  #5  
Old 12-21-2007, 04:02 AM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: how to add identity column to a view

Hi

You may want to read
http://databases.aspfaq.com/database...recordset.html

John

"amit sharma" wrote:

> hi Russell,
> thanx for your reply.
> i have a table with identity column and values are not continous in that
> column.
> thats why i want to create a view which has continous values in identity
> column.
> so that i can implement custom paging in my front end application.
>
>
>
> "Russell Fields" wrote:
>
> > Amit,
> >
> > Sorry, but you cannot add an identity column to a view. What is your need?
> > Are you trying to get a row number attached to each row returned? Must it
> > be in a view or can you use some other mechanism?
> >
> > You can do the following, but it will get expensive if the result set is
> > quite large.
> >
> > SELECT (select count(*) from MyTable where KeyColumn <= a.KeyColumn) AS
> > RowNumber, a.*
> > FROM MyTable AS a
> > ORDER BY RowNumber
> >
> > RLF
> >
> > "amit sharma" wrote in message
> > news:351A9D82-3E62-465C-90AE-1405C2747667@microsoft.com...
> > > hi all,
> > >
> > > how to add identity column to a view in sql server 2000.
> > > plz help.
> > >

> >
> >
> >

Reply With Quote
  #6  
Old 10-29-2009, 01:03 PM
Database Newbie
 
Join Date: Oct 2009
Posts: 1
Theofilus is on a distinguished road
Thumbs up Re: how to add identity column to a view

http://support.microsoft.com/default...b;en-us;186133
is a nice solution from MS using rank().

I like the one given by Russel though:

SELECT (select count(*) from Table where KeYCol<=a.KeyCol) AS RowNo, a.*
FROM Table AS a
ORDER BY RowNo

Thank you Russel!!!
A very smart solution.
Reply With Quote
Reply

Thread Tools
Display Modes



All times are GMT -4. The time now is 01:26 AM.