Automatically fill the primary key

We have Oracle database 10g. I've added a primary key column to my deo_language_resources_t of table with the following logic:

-- 1. create sequences
create sequences eod_lr_seq
Start increment by 10 by 5
MinValue 10 nomaxvalue
NoCache;

-- 2. Create the primary key column
ALTER table deo_language_resources_t
ADD NUMBER RESOURCE_ID;

-- 3. Fill the pk
Update deo_language_resources_t
Set id_ressource = eod_lr_seq.nextval
where id_ressource is null;

-- 3. Create the primary key constraint
ALTER table deo_language_resources_t
Add constraint resource_id_pk key (resource_id) primary;

insert into deo_language_resources_t
(first_name, last_name, id_ressource)
values ('John', 'Doe', eod_lr_seq.nextval);

The last INSERT statement successfully a line inserted into the table and populated by id_ressource with the next number in the sequence eod_lr_seq. Ok.

Is it possible to set a constraint on deo_language_resource_t so that when I INSERT a line the id_ressource is automatically set to eod_lr_seq.nextval? It is possible to define a trigger and resembling the logic of the trigger? The insert statement would be like:

INSERT INTO deo_language_resources_t (first_name, last_name) VALUES ('John', 'Doe');
create trigger deo_language_resources_trigger
before insert on deo_language_resources_t
for each row
begin
select eod_lr_seq.nextval into :resource_id from dual;
end;

Tags: Database

Similar Questions

  • Shape of the apex - how to get the primary key value manually?

    Hello

    Whenever I create form by using wizard Apex, he asks me to specify the trigger/sequence/pl/sql function to fill the primary key value.

    However, if I want to specify primary key myself (ie. undetermined generated automatically), how I can clarify that?

    Thanx

    Hello

    You mean by yourself: by hand or by a pl/sql?

    If you say by trigger, the system does not take on what number is sent. If you can give it "manually".

    May I ask what is the reason for this?

    See you soon,.

    Arnaud

  • How to get generated automatically the primary key to create procedure

    I have a service of physical data corresponding to a table named ACCOUNT. The primary key on the table is called ACCOUNT_ID. There's a trigger on the database which generates the primary key value and adds it during an insert. I would like to have this primary key value returned by the procedure of creation of physical data service. Any ideas on how this can be done? Thanks in advance.

    as the primary key automatically obtained by ODSI leave a sequence in the DB and used during a procedure for creating

    Go to the design for the physical data service view

    Click the column which is filled from the sequence.

    In the Properties tab (bottom window), under general, for automatic numbering, click the 'Value' column, select sequence. You get a noise on some things have changed, just click OK. With AutoNumber = sequence setting, this column appears as optional (question mark).

    Just below that, for purpose of sequence, type the name of the sequence (you can also specify MYSCHEMA. In case the sequence SEQUENCE_NAME is under another schema).

    When you create objects SDO - leave the update vacuum column.

    that is if he were CUSTOMER_ID, your client would look like this...


    John
    Smith

    and when you read it back to the database, it would be...


    38738
    John
    Smith

    Published by: mikereiche on April 28, 2009 11:40

  • How to fill out the table foreign key to the primary key form

    Hi all

    I'm stuck in this problem for 3 days, and I'm about to research and implement solutions on the internet.

    I have two tables

    create table prim (a number primary key, b varchar2 (100));

    create table CHILD (a number references (a) prim, varchar2 (100)) c;

    I created a page for PRIM table.

    = page name form on PRIM2

    I have manually two columns for the CHILD table to know

    P26_A_1 (for the primary key in the CHILD table)

    P26_C (for the column in the CHILD Table c)

    now when the user clicks on the button CREATE, a row must be inserted into the child table.

    I want to assign the P26_A to P26_A_1 during the validation process, so that a line must be inserted into the PRIM table as well as in the CHILD table.

    How to do this?

    I downloaded my application page in https://apex.oracle.com

    my workspace identifiers are inferior to

    name of the workspace = IMBERT

    username = demo

    password = demo

    kindly guide me.

    Thank you.

    Hello

    I created a new page (page 30) similar to your page and added the insertion of the child. It just check the page and code. It works now, when you insert the prim file is triggered a second trial which inserts the child record manually.

    On page 26 it was some sort of mistake, was easier to create a new as it was almost a standard form.

    Concerning

    Bottom

  • Automatic generation of primary key

    Hello

    I am downloading a file limited tab using the "Loading data" page option APEX.

    When creating the page, he asked the table whose data must be downloaded and unique key.

    My problem is that I can't give the unique key in the file. It must be generated and automatically inserted each row.

    But with her when I try to download im getting the error
    •Ora-01008: not all variables

    I created a sequence and a trigger to generate this primary key value, but don't know where and how implement it. Help, please.

    Thanks in advance

    Hello

    I don't know what the problem is. I tried to reproduce this on apex.oracle.com. He never asks for the primary key when loading. Here's what I have.

    CREATE SEQUENCE   "T1_SEQ"  MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 5 NOCACHE  ORDER  NOCYCLE
    /
    
    CREATE TABLE  "T1"
       (     "ID" NUMBER,
         "NAME" VARCHAR2(1000),
          CONSTRAINT "T1_PK" PRIMARY KEY ("ID") ENABLE
       )
    /
    
    CREATE OR REPLACE TRIGGER  "T1_TRG1"
    BEFORE
    insert on "T1"
    for each row
    begin
      if :NEW."ID" is null then
        select "T1_SEQ".nextval into :NEW."ID" from sys.dual;
      end if;
    end;
    
    /
    ALTER TRIGGER  "T1_TRG1" ENABLE
    /
    

    Then I load a file containing only the name column and the trigger fills in the primary key. ???

    Kind regards
    Howard

  • need to based on the primary key of different table 2 foreign key constraint

    I'm using Oracle 11.2.0.3.

    I have 2 table invl with invl_pk as primary key and org with org_pk as the primary key.

    In the third table entity_list, I have entity_pk that can be indvl_pk or org_pk.   How can I create this constraint?

    Thanks for your time.

    Hello

    Assuming that your model is correct, then what you describe is a normal type of ER modeling construction known as a relationship of the CRA. It is characterized by an entity with two or more links that are mutually exclusive to each other (XOR). A typical example may be where a person entity and an entity of the Organization relate both to a bank account entity, but a bank account can only be used by a person or an organization in a mutually exclusive way. In order to serve this on a diagram, an arc is drawn between effective relationships on the side of the child, where the name of a relationship of the CRA.

    Google will be of multiple examples and explanations.

    In a perspective of physical databases, this can be implemented in general in two different ways.

    1. assuming that all parents in the relationship of the CRA have identical PK, that is to say, a number that is generated, the child may have a FK of the same type and an entity of type column that defines what entity the FK is. The advantage of this is that it is a bit more compact and is expandable without schema changes if you want to add more relationships. The downside of this is that the CF cannot be defined at the database level and will build on the code to be executed or both in the application and the database as a trigger.

    2. regardless of types PK for parent entities, the child has a separate optional FK appropriate for each relationship in the arc. Each FK is defined at the database level while maintaining the exclusivity of relationships, a constraint is defined on the table that prevents several FK being filled for a given instance. This can be a little messier that there must be a (column/s) FK for each relationship in the arc, but the relationship may be limited to the level of the object database with the help of FK constraints and a check constraint. This could also be considered to be more technically correct implementation.

    Hope this helps

    André

  • best method to update the primary key

    Can someone tell me the best possible method to update the primary key so that the foreign key is also updated.
    Please explain with example

    940340 wrote:
    Can someone tell me the best possible method to update the primary key so that the foreign key is also updated.
    Please explain with example

    You're after a mechanism that lets you update the primary key sometimes on some lines, or did you just impossible, which means that you must update all the data because of some kind of change in the structural definition?

    If all you need is a rational method to change keys sometimes (and this isn't quite mortal sin that other posters have been suggesting) then recreate your foreign key as a constraint can be delayed may help.

    Oracle allows no you cascading updates automatically for primary keys, but if the foreign key is carried forward you can proceed as follows:

    set constraint {foreign key constraint name} deferred;
    update parent primary key;
    update child foreign key;
    set constraint {foreign key constraint name} immediate;
    

    Concerning
    Jonathan Lewis

  • Get the primary key of entry just created by submitting the form

    Hi guys,.

    I have a form built in APEX based on a table. The PK is generated by the sequence and the values of the form are recorded by DML (insert).

    Do I have to do is once I have create a new entry with my, I need to update a whole bunch of other tables with the new PK that I can easily do this by creating a process of PL/SQL after DML.



    However, I need the primary key generated by the new entry (created by filling out the form + submit).

    One way around it is
    Select max(userid) from user
    to retrieve it, but I don't know if it's a good idea/practice.

    Any idea guys? See you soon.

    Taepodong wrote:
    Hi guys,.

    I have a form built in APEX based on a table. The PK is generated by the sequence and the values of the form are recorded by DML (insert).

    Do I have to do is once I have create a new entry with my, I need to update a whole bunch of other tables with the new PK that I can easily do this by creating a process of PL/SQL after DML.

    However, I need the primary key generated by the new entry (created by filling out the form + submit).

    One way around it is

    Select max(userid) from user
    

    to retrieve it, but I don't know if it's a good idea/practice.

    This will only give the maximum ID and not currently generated ID

    Any idea guys? See you soon.

    Use this feature APEX
    Change your page > change you the DTF process for the form > Enter you page back key point in the element (this returns the new pk value generated by this form)

  • How did the foreign key that is recognized by the primary key

    Hi, when I have two user tables and userLevel and the primary key of the user is the user name and I add a field to userLevel userID is only to make the userID field in userLevel automatically the foreign key of the table? Or do you switch the engine of MyISAM tables to InnoDB to make relational links. Can someone please explain this in English clear to me, because I just can't get my head around this.

    In the case of a query such as SELECT statement, we talked, being a key actually means that the field is indexed so that the database can quickly look up.  Thus, in phpMyAdmin, you set the field to be indexed by the visualization of the structure of the table and clicking the icon index (the one with the Lightning) for the field in the Action section.

    If you are looking for integrity refrential between tables we also talked about and using the InnoDB engine, you can click the link 'Show the relational' in the table structure page of phpMyAdmin and define foreign key constraints.

  • Speech recognition automatically press the home key

    Hey, I had a problem with the text-to-speech software since I started using it.  If to dictate or Commander, several times when he does not understand me it displays "what was it?" then automatically, press the home key.  It's especially annoying when you try to use the becauset internet it always takes me to my home page when he doesn't understand me.  I hope that this can be easily treated.  Thank you.

    Hello

    Did you change your computer?

    I suggest you to follow the links and check out them.

    Set up speech recognition

    http://Windows.Microsoft.com/en-us/Windows-Vista/set-up-speech-recognition

    Dictate text using speech recognition

    http://Windows.Microsoft.com/en-us/Windows-Vista/dictate-text-using-speech-recognition

    Common commands in speech recognition

    http://Windows.Microsoft.com/en-us/Windows-Vista/common-commands-in-speech-recognition

  • How to find the primary key columns in the tables in MS Access using SQL queries

    How to find the primary key columns in the tables in MS Access using SQL queries

    Hello

    This is the forum for Windows Vista programs related issues.

    For better assistance, please try instead the Forums in SQL Server .

    Thank you! Vincenzo Di Russo - Microsoft MVP Windows Internet Explorer, Windows Desktop Experience & security - since 2003. ~ ~ ~ My MVP profile: https://mvp.support.microsoft.com/profile/Vincenzo

  • Make required error appears only the primary key generated in prior Database Table insert trigger

    Dear all,

    I am a beginner in the ADF and am under Jdeveloper Studio Edition Version 12.2.1.0.0.


    I'm trying to insert a record, I created the trigger for insertion prior to get the primary key and set some other default values.


    On the page, I did read-only primary key column and false required.


    When I try to save - commit (Programmatic), I get errors for the required value. How can I stop this errors.


    Secondly, I also tried changing the agent to disabled on the attribute View object that raised the error below:


    < oracle.dfw.impl.incident.DiagnosticsDataExtractorImpl > < DiagnosticsDataExtractorImpl > < createADRIncident > < incident created 148 to key problem "DFW-99998 [oracle.jbo.PersistenceException] [oracle.jbo.server.RowReference.verifyPrimaryKeys] [Proposals]" >


    Hoping for help.


    Thanks and greetings


    Arif Khadas

    If the primary key values from DB sequence, you can follow this approach:

    Using the sequence of database in ADF - Souza Waslley Blog

    Oracle Fusion Middleware Technologies: ADF 11 G: generate the primary key sequence number

    Otherwise, instead of DB trigger, create the DB function that retrieves the value of the PK and call stored function in the overloaded method create() entity:

  • Houston-25013: too many objects match the [primary key Lookup.USR_PROCESS_TRIGGERS USR_EMP_TYPE] oracle.jbo.Key.

    Hello

    I am trying to open the Console of the IOM of Sysadmin,

    try checking the research,

    search specific "Lookup.USR_PROCESS_TRIGGERS".

    and get the error on the screen

    Houston-25013: too many objects match the [primary key Lookup.USR_PROCESS_TRIGGERS USR_EMP_TYPE] oracle.jbo.Key.

    This known issue?

    This patch it for it?

    tried searching discussion forums, nothing here

    Thank you

    Check from the console design.  Looks like you have a duplicate key Code value.

    -Kevin

  • Comparison of the data of several rows in a table - based on the primary key

    Currently I have a select statement that returns hundreds of records.  Each returned record is linked to A NUMBER of ORDER this order number has a recipe.  (a bit like a cooking recipe).  Each recipe has many records in the database related to this order number and records should be compared to records in a table that bind to a specific primary key...  (I have already developed the logic to isolate what PK I need).  If all these records that are returned by the select statement below does not match all the records containing PK in the table below, I need to get the next PK and compare all these recordings for select statements return.

    See below for a better understanding. Need a good example detailed on how to solve my problem here.

    Just to help you understand:

    Each element of the recipe is 3 parts (side, ref_des, part_number).  1 single recipe can have several parts (where the part_number), and each of these pieces should be placed on the lower side or top of the Board that is there "side" comes into play.  Same thing with Ref_Des.

    What is going on

    Select statement returns the RECIPE of ORDER NUMBER A.  There will be multiple records returned by this query.

    Select the Return statement:

    • Side
    • Ref_Des
    • Part_Number

    Example of return:

    B c17 75145-2

    T f14 89242-8

    B s12 45123-3

    etc,

    In general - what I need to do:

    There is a table called AUTO_RECIPE_DETAILS.  I take all of the records returned by the select query above and compare for each record in this table relating to the recipe 30319-000001.  30319-000001 a number of records.  It is the primary key for a whole recipe as seen above.  This primary key is bound the number of data records in this table.  The comparison is to see if all records under RECIPE_NAME 30319 -000001 match all the records returned by the select statement.

    IF IT DOES NOT MATCH: recover the following recipe in this table below 30319 -000002 and make the same comparison.

    Here's a perfect example of what the table looks like: (AUTO_RECIPE_DETAILS)


    RECIPE_NAME SIDE REF_DES PART_NUM

    -30319-000001 C16 87595-1 B

    -30319-000002           T B14 74150-4

    -30319-000001 T B14 34251-2          

    -30319-000001            T F24 84180-7

    -30319-000002 T B12 13710-8          



    It is the solution to my original question.  By this thread, it's the right answer and I hope this helps someone who is trying to compare two arrays element-by-element.  In the end, the advice given in this thread were correct and I will be using all of your suggestions and the scrapping of this.  Thank you everyone for your help though.

    FOR index_p IN pid_recipe. FIRST... pid_recipe. LAST

    LOOP

    Result WHEN the OUTPUT = 1;

    FOR index_d IN details_recipe. FIRST... details_recipe. LAST

    LOOP

    IF (pid_recipe (index_p). SIDE = details_recipe (index_d). SIDE)

    AND (pid_recipe (index_p). REF_DES = details_recipe (index_d). REF_DES)

    AND (pid_recipe (index_p). PART_NUM = details_recipe (index_d). PART_NUM)

    THEN

    EXIT;

    ON THE OTHER

    DBMS_OUTPUT. Put_line("IT WAS NOT a MATCH");

    result: = 1;

    EXIT;

    END IF;

    END LOOP;

    END LOOP;

    DBMS_OUTPUT. Put_line('LOOP OUT');

  • generate a numerical value to use as the primary key

    Can someone correct me, in an interview that the question was asked.

    How not one generates a numeric value to use as the primary key?

    Years

    We can get it using the sequence. For example:

    CREATE SEQUENCE cust_seq

    START BY
    1000

    INCREMENT OF
    1

    NOCACHE

    NOCYCLE;

    Hi Shu,

    sequence would be my choice and 12 c new type called identity.

Maybe you are looking for

  • I forgot my email address?

    I forgot my email address?

  • Updated Firefox 13.0.1 and lost AVG Linkscanner to 2012. Suggestions?

    AVG shows Linkscanner existis is active, but it is neither in Firefox after upgrade to 13.0.1.

  • HELP e280

    The player has frozen all playing a song. Keep showing the SanDisk opening screen, then screen goes gray and did the same thing again.  It seems to be stuck in a loop. I have to close it, then go back on it and it does the same thing. I took out the

  • How can I restore deleted user account?

    During a session to help with Intuit on the installation of a product update, it became necessary to set up a new user in Windows XP Tablet Edition.  In the process of all other user accounts have been deleted. How to restore a user account?  The new

  • Recycle inkjet cartridge Info

    I can connect to the HP site but I can't log on to HP.com/recycle it does not address or password by email. I just want to get cartridge recycling envelope. Seems HP is not really into recycling and wants me to throw the cartridge in a landfill