Take a look: Scope_identity
SCOPE_IDENTITY()
The table that has the Identity property from this table, we can get the last inserted record identifier, will look like this:
SELECT SCOPE_IDENTITY()
OR
But this is not a safe technique:
SELECT MAX(Id) FROM Ticket
OR
This is also not a safe technique:
SELECT TOP 1 Id FROM Ticket ORDER BY Id DESC
source share