I always use this query in sql server to get Row number in a table:
SELECT *
FROM (SELECT *,
Row_number()
OVER(
Though this is an old question, this has worked for me, but I've never tested its efficiency...
SELECT
(SELECT COUNT(t1.SourceID)
FROM [SourceTable] t1
WHERE t1.SourceID
Some advantages of this method:
RowID is calculated on its actual value and those that are less than it.Number, String or Date).Final Thoughts
Though this will work with practically any data type, I must emphasise that, for some, it may create other problems. For instance, with strings, consider:
ID Description ROWID
aaa Aardvark 1
bbb Bear 2
ccc Canary 3
If I were to insert: bba Boar, then the Canary RowID will change...
ID Description ROWID
aaa Aardvark 1
bbb Bear 2
bba Boar 3
ccc Canary 4