What’s the sql standard to get the last inserted id? If there is such a thing.
mysql: LAST_INSERT_ID()
postgresql: … RETURNING f_id
mssql: SCOPE_IDENTITY()
… more examples here …
I mean, all databases have different implementations for that, there isn’t a standard for such a common task?
See this answer Retrieve inserted row ID in SQL
In short, there is no cross database way to do this, except MAX(ID) – but that is not a guaranteed result and has many many pitfalls, e.g.
The ANSI standard that relates to identity/autonumber/auto_increment/sequences first appeared in SQL:2003 awaiting implementation by all major RDBMS. It will most likely resemble Oracle/PostgreSQL sequences.
Another change in SQL:2003 is the
OUTPUT USING CLAUSEbut there is very little information about it. Sybase and SQL Server have done different things with it, so it is unclear as yet how it will pan out. SQL Server implements it as