{"id":2645,"date":"2012-07-10T13:38:26","date_gmt":"2012-07-10T17:38:26","guid":{"rendered":"https:\/\/pitss.org\/us\/2012\/07\/10\/create-trigger-to-automatically-generate-primary-key\/"},"modified":"2017-06-28T15:14:22","modified_gmt":"2017-06-28T19:14:22","slug":"auto-generate-primary-key-for-oracle-database","status":"publish","type":"post","link":"https:\/\/pitss.org\/us\/2012\/07\/10\/auto-generate-primary-key-for-oracle-database\/","title":{"rendered":"Create Trigger to Automatically Generate Primary Key"},"content":{"rendered":"<p>It is possible to automatically generate a primary key for Oracle Database tables when they are created. The steps below will show how to configure database tables so that primary keys are automatically generated:<\/p>\n<p>The following example would create an automatic primary key generation with the following table:<\/p>\n<ol>\n<li><strong>Create Table with primary key and any additional attributes.<br \/>\n<\/strong>create table test (id number, testdata varchar2(255));<\/li>\n<li><strong>Create Sequence<\/strong><br \/>\ncreate sequence test_seq<br \/>\nstart with 1<br \/>\nincrement by 1<br \/>\nnomaxvalue;<\/li>\n<li><strong>Create Trigger<br \/>\n<\/strong>create trigger test_trigger<br \/>\nbefore insert on test<br \/>\nfor each row<br \/>\nbegin<br \/>\nselect test_seq.nextval into :new.id from dual;<br \/>\nend;<br \/>\n\/<\/li>\n<li><strong>Test<\/strong><br \/>\ninsert into test values(&#8216;hello world!&#8217;);<br \/>\ncommit;<br \/>\nselect * from test;<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>It is possible to automatically generate a primary key for Oracle Database tables when they are created. The steps below will show how to configure database tables so that primary keys are automatically generated: The following example would create an automatic primary key generation with the following table: Create Table with primary key and any [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[95,4],"tags":[15,11,16,13,27],"class_list":["post-2645","post","type-post","status-publish","format-standard","hentry","category-database","category-install-config","tag-10g","tag-11g","tag-11gr2","tag-installation-setup","tag-oracle-database"],"_links":{"self":[{"href":"https:\/\/pitss.org\/us\/wp-json\/wp\/v2\/posts\/2645","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pitss.org\/us\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pitss.org\/us\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pitss.org\/us\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pitss.org\/us\/wp-json\/wp\/v2\/comments?post=2645"}],"version-history":[{"count":4,"href":"https:\/\/pitss.org\/us\/wp-json\/wp\/v2\/posts\/2645\/revisions"}],"predecessor-version":[{"id":9484,"href":"https:\/\/pitss.org\/us\/wp-json\/wp\/v2\/posts\/2645\/revisions\/9484"}],"wp:attachment":[{"href":"https:\/\/pitss.org\/us\/wp-json\/wp\/v2\/media?parent=2645"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pitss.org\/us\/wp-json\/wp\/v2\/categories?post=2645"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pitss.org\/us\/wp-json\/wp\/v2\/tags?post=2645"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}