How can I show the number of rows in a table so that when adding a new record, the number representing the row will be higher, and when the record is deleted, the number will be updated accordingly?
To be more clear, suppose I have a simple table:
ID int (primary key) Name varchar (5)
The identifier is set in order to receive the increase by itself (using the identification specification), therefore it cannot represent the number of lines (records), because if I have, for example, 3 records:
GO NAME
1 alex
2 Scott
3 sarah
and I will remove Alex and Scott and add a new entry:
3 Sara 4 Mina
So basically I'm looking for a sql-side solution for this so that I don't change anything else in the source code in several places.
I tried to write something to do this work, but it fails. Here he is:
SELECT COUNT(*) AS [row number],Name FROM dbo.Test GROUP BY ID, Name HAVING (ID = ID)
It shows how:
row number Name 1 Alex 1 Scott 1 Sara
while I want it to display as:
row number Name 1 Alex 2 Scott 3 Sara
source share