question

kemal avatar image
kemal asked

is there any rowid in sql server

Hi all, I am looking for a rowid like in Oracle in SQL Server but I could not find something like that. I don't want an identity column because the table that I was querying may not have an identity column and I don't want rownumber because it differs from query to query. But rowid in Oracle is always the same in the life time of a row hence when you have different select queries the rowid is the same. So is there any rowid, unique for a row?

Kemal

sql-server-2005identity
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Madhivanan avatar image
Madhivanan answered

1 If you dont have the identity column, move the resultset to temp table that has identity column and use it

2 You can create row_number for each row of the table and use it as rowid

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

TG avatar image
TG answered

No, sql server does not have an equivalent for oracle rowid. you would need to alter your structure to create something like that.

The only other thing I can think of is to use the primary key column(s) to derive either a checksum, binary_checksum, or perhaps hashBytes value. That would generate the same identifier consistently given the same inputs. So as long as your PK values don't change the identifier wont either.

What are you trying to do? There may be another way...

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Cade Roux avatar image
Cade Roux answered

I always monitor tables without a primary key with exception reports, because I really think it's important that tables have a primary key unless there is a really good reason not to have one.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Rajib Bahar avatar image
Rajib Bahar answered

you can also look into the rank() and denser version of the rank function

that may give you some ideas

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.