[fpc-pascal] Re: How to insert a record and get the primary key with sqldb?

Inoussa OUEDRAOGO inoussa12 at gmail.com
Sat Oct 22 15:35:25 CEST 2011


> Ok, searching some more I see that "select scope_identity()" could
> return the generated primary key. But how to get the value?

Better use the RETURNING* clause** as it clearly state the column
value you are expecting; The "scope_identity()" may be a source of
subtle bugs that are
difficult to resolve, for example :
  what if the table make use of two sequences (yes sometime this is needed)
  what if the table's insert trigger generates a insert query(or
stored procedure) into another table which make use of sequence

(*) http://www.postgresql.org/docs/8.3/interactive/sql-insert.html
(**) this clause is at least supported by Firebird, MS SQL SERVER, ORACLE

-- 
Inoussa O.



More information about the fpc-pascal mailing list