How to read the last row with SQL Server

后端 未结 17 847
别那么骄傲
别那么骄傲 2020-11-29 03:40

What is the most efficient way to read the last row with SQL Server?

The table is indexed on a unique key -- the \"bottom\" key values represent the last row.

17条回答
  •  南笙
    南笙 (楼主)
    2020-11-29 04:14

    If you have a Replicated table, you can have an Identity=1000 in localDatabase and Identity=2000 in the clientDatabase, so if you catch the last ID you may find always the last from client, not the last from the current connected database. So the best method which returns the last connected database is:

    SELECT IDENT_CURRENT('tablename')
    

提交回复
热议问题