Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How bad is it to simulate IDENTITY/AUTOINCREMENT columns using triggers in Oracle?

I maintain an application that was originally written to be SQL Server-specific (using IDENTITY fields). Thus, we've had to define a lot of triggers to auto increment tables' primary keys.

I'm told that this is considered to be a hacky workaround in the Oracle world, but that was told to me in a "friend of a friend" kind of way. How big a deal is it to use triggers to increment primary keys from a sequence instead of using the sequence directly?

like image 493
Jason Baker Avatar asked Dec 07 '25 10:12

Jason Baker


1 Answers

It is a very common practice in my experience, and not a terribly bad one. However, if you have control over the inserts (e.g. if all inserts are done via a PL/SQL API) then it is more efficient to use the sequence directly in the INSERT statement - because it avoids the overhead of firing a trigger. But I really wouldn't worry unduly about it if you have used triggers!

like image 90
Tony Andrews Avatar answered Dec 10 '25 04:12

Tony Andrews



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!