I would like to return the last value of the primary key inserted in the table, but my primary key is CPF
so I can not use SELECT SCOPE_IDENTITY()
.
I would like to return the last value of the primary key inserted in the table, but my primary key is CPF
so I can not use SELECT SCOPE_IDENTITY()
.
There is no T-Sql for this. You only use SCOPE_IDENTITY or IDENT_CURRENT as long as the column is Identity.
I recommend the following readings:
An alternative is to add a DataInsercao
field with type datetime
to the structure of your table. By default
this field should receive the current date, the GETDATE () can be useful in this case.
This way you can sort by the most current date and check the last record inserted.
Select should be something like this:
Select top 1 * from MinhaTabela Order By DataInsercao DESC