Since it is a self-increasing data column,
Then the data inserted at this point should be the last one, and its ID should be the largest
You can use select Max (ID) from table;
But there is a problem, if it is a data table that is being used with frequent inserts,
After you execute your INSERT statement, the ID of your select is not necessarily the ID of your statement until you execute the SELECT statement, and if another user inserts again.
All that should be used is
Inset into table name (column name, column name,.. ) Output inserted.id values (data, data, ...) ;
Examples of use:
1. For insert, you can refer to the inserted table to query the properties of the new row .
insert into [table name] (a) OUTPUT inserted.a values (' a ')
2. For delete, you can reference the deleted table to query the properties of the old row .
Delete [table name] OUTPUT deleted.a where links = ' a '
3. For update, use the deleted table to query the properties of the updated row before the change, using the inserted table to identify the changed value of the row being updated.
Update [table name] Set a = ' B ' OUTPUT inserted.a where a = ' a ' (returns the modified value)
Update [table name] Set a = ' B ' OUTPUT deleted.a where a = ' a ' (returns the value before modification)
How to get the value of the self-increment ID when inserting the current statement