Equivalent of Oracle's RowID in SQL Server

前端 未结 13 1255
长发绾君心
长发绾君心 2020-11-27 04:22

What\'s the equivalent of Oracle\'s RowID in SQL Server?

13条回答
  •  悲哀的现实
    2020-11-27 05:22

    You can get the ROWID by using the methods given below :

    1.Create a new table with auto increment field in it

    2.Use Row_Number analytical function to get the sequence based on your requirement.I would prefer this because it helps in situations where you are you want the row_id on ascending or descending manner of a specific field or combination of fields

    Sample:Row_Number() Over(Partition by Deptno order by sal desc)

    Above sample will give you the sequence number based on highest salary of each department.Partition by is optional and you can remove it according to your requirements

提交回复
热议问题