How to get rowid in sql server 2005

  • I want to get the rowid internally generated at table level in sql server. Because I need to perform some task according to the rowid.

  • do you want to return a result with a row number as part of the output or do you want to grab a specific row, as in you want row 10 of the data set?

    Dan

    If only I could snap my figures and have all the correct indexes apear and the buffer clean and.... Start day dream here.

  • nitinkumar_tss (3/26/2010)


    I want to get the rowid internally generated at table level in sql server. Because I need to perform some task according to the rowid.

    Unfortunately, there isn't an internally generated rowid at the table level in SQL Server.

  • It seems like Oracle uses something like this that you can access, but unfortunately MS SQL does not. If you can give more details on your goal, it's possible we can suggest another way to do it.

    Seth Phelabaum


    Consistency is only a virtue if you're not a screwup. 😉

    Links: How to Post Sample Data[/url] :: Running Totals[/url] :: Tally Table[/url] :: Cross Tabs/Pivots[/url] :: String Concatenation[/url]

  • what kind of row id du you need.

    If you need row id which is stored in your table then you can use table's identity value for the same

  • there is not rowid equivalent in SQL Server

  • Lynn Pettis (3/26/2010)


    nitinkumar_tss (3/26/2010)


    I want to get the rowid internally generated at table level in sql server. Because I need to perform some task according to the rowid.

    Unfortunately, there isn't an internally generated rowid at the table level in SQL Server.

    Well, technically there is, sort of, but it is undocumented and not intended for use by end users.

  • Paul White NZ (3/28/2010)


    Well, technically there is, sort of, but it is undocumented and not intended for use by end users.

    +1 for that.

    All records do have a "hidden" record identifier, when there is not primary key on the table. That's the way SQL Server distinguishes between two identical records.

    Read more about what Kalen Delaney writes about this.


    N 56°04'39.16"
    E 12°55'05.25"

  • SwePeso (3/28/2010)


    Paul White NZ (3/28/2010)


    Well, technically there is, sort of, but it is undocumented and not intended for use by end users.

    +1 for that.

    All records do have a "hidden" record identifier, when there is not primary key on the table. That's the way SQL Server distinguishes between two identical records.

    Read more about what Kalen Delaney writes about this.

    Is it actually a row identifier, like this is row 10? Reason I ask is that is what most people are looking for when they are asking about an internal rowid. Is that what this individual is asking, not sure.

  • Lynn Pettis (3/28/2010)


    Is it actually a row identifier, like this is row 10? Reason I ask is that is what most people are looking for when they are asking about an internal rowid. Is that what this individual is asking, not sure.

    Think they're talking about the RID. Row Identifier, binary value, 8-byte combination of file id, page number and slot index. It's accessible on all tables (not just heaps), however it's likely to change whenever the clustered index is rebuilt (and, on SQL 2008, if the heap is ever rebuilt) because it's the physical location of the row.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • SwePeso (3/28/2010)


    All records do have a "hidden" record identifier, when there is not primary key on the table. That's the way SQL Server distinguishes between two identical records.

    I assume you mean 'clustered index', not 'primary key'.

    The RID's there on all tables, cluster and heap. It's only used in nonclustered indexes if the underlying table's a heap, but it can be viewed on all tables.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Paul White NZ (3/28/2010)


    Lynn Pettis (3/26/2010)


    nitinkumar_tss (3/26/2010)


    I want to get the rowid internally generated at table level in sql server. Because I need to perform some task according to the rowid.

    Unfortunately, there isn't an internally generated rowid at the table level in SQL Server.

    Well, technically there is, sort of, but it is undocumented and not intended for use by end users.

    My gut was telling me that was the case, but my google skills apparently failed me. I couldn't find anything on it. Anyone have a link?

    Seth Phelabaum


    Consistency is only a virtue if you're not a screwup. 😉

    Links: How to Post Sample Data[/url] :: Running Totals[/url] :: Tally Table[/url] :: Cross Tabs/Pivots[/url] :: String Concatenation[/url]

  • GilaMonster (3/28/2010)


    I assume you mean 'clustered index', not 'primary key'.

    The RID's there on all tables, cluster and heap. It's only used in nonclustered indexes if the underlying table's a heap, but it can be viewed on all tables.

    Yes, of course. You're right. I meant clustered index.


    N 56°04'39.16"
    E 12°55'05.25"

  • Garadin (3/28/2010)


    My gut was telling me that was the case, but my google skills apparently failed me. I couldn't find anything on it. Anyone have a link?

    http://sqlskills.com/BLOGS/PAUL/post/SQL-Server-2008-New-(undocumented)-physical-row-locator-function.aspx

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • GilaMonster (3/28/2010)


    Garadin (3/28/2010)


    My gut was telling me that was the case, but my google skills apparently failed me. I couldn't find anything on it. Anyone have a link?

    http://sqlskills.com/BLOGS/PAUL/post/SQL-Server-2008-New-(undocumented)-physical-row-locator-function.aspx

    %%LockRes%% in 2005 is the closest equivalent.

    I wasn't going to mention it though, since I thought it would just confuse matters.

Viewing 15 posts - 1 through 15 (of 40 total)

You must be logged in to reply to this topic. Login to reply