Pre Exam Test Practice (SSC | Banking | IAS | GATE | State Level | CLAT | Railways | Insurance | Teaching Exams | NDA | Defence | IES |State Exam )

Organizational Research By

Surprising Reserch Topic

best practices net how to return pk against an oracle database

best practices net how to return pk against an oracle database  using -'.net,oracle'

With SQLServer, it seems to be generally accepted that adding a SELECT SCOPE_IDENTITY() to the end of your insert is the best way to return the PK of the newly-inserted record, assuming you're using an auto-increment field for the pk.

However, I can't seem to find the equivalent for Oracle.

Best practice seems to be to use a sequence to generate the PK, but there are different options for how to implement even that. Do you leave it up to the developer to insert sequence.nexval, or use a trigger?

In either case, getting the new ID back seems to be a common problem.

Suggestions and solutions I've run across include:

creating a stored proc that returns the PK
running a select id from seq.nextval, then passing that to the insert
select max(id) after insert (Note: Don't do this!)
add a RETURNING clause to the insert

What should the "best practice" solution be for this situation?

asked Sep 21, 2015 by atulpariharmca
0 votes

Related Hot Questions

Government Jobs Opening