Keys in DBMS

Hi, this is Khalid. I am new in DBMS. I have just started to study. I am having a little bit confusion in the Concept of Keys of DBMS and Attributes. So, I am getting little bit problem to understand the concept of Keys. Somebody, please help me.
Now, i am just going to show a Relation.
Employee EMP_ID EMP_NAME EMP_SALARY
101 Khalid 17000
102 Rajib 16000
103 Rahul 18000
104 Dibakar 17000
105 Akikul 16000
106 Bidyut 16500
107 Pranjal 16500
Somebody is saying that the rows or the tuples within the table are the Keys, whereas somebody's opinion is is the Column Title. So, i am in the confusion that if the column name is the key value, then what is an attribute ? Please explain the very basic concept of every type of Keys. Such as Super Key, Primery Key, Candidate Key, Foreign Key etc.
So, please help me. This is the very first time in any kind of forum. So, I politely request you everybody to give me a proper solution for my problem. Thanks.

Here EMPLOYEE represents a table.
EMP_ID, EMP_NAME, EMP_SALARY are attributes.
In the table mentioned above, EMP_ID is the primary key. Primary key is the key which can uniquely identify the rows of a table. Here u can see that primary key values are unique for each row.
The various types of key with e.g. in SQL are mentioned below, (For examples let suppose we have an Employee Table with attributes ‘ID’ , ‘Name’ ,’Address’ , ‘Department_ID’ ,’Salary’)
(I) Super Key – An attribute or a combination of attribute that is used to identify the records uniquely is known as Super Key. A table can have many Super Keys.
E.g. of Super Key
1 ID
2 ID, Name
3 ID, Address
4 ID, Department_ID
5 ID, Salary
6 Name, Address
7 Name, Address, Department_ID ………… So on as any combination which can identify the records uniquely will be a Super Key.
(II) Candidate Key – It can be defined as minimal Super Key or irreducible Super Key. In other words an attribute or a combination of attribute that identifies the record uniquely but none of its proper subsets can identify the records uniquely.
E.g. of Candidate Key
1 Code
2 Name, Address
For above table we have only two Candidate Keys (i.e. Irreducible Super Key) used to identify the records from the table uniquely. Code Key can identify the record uniquely and similarly combination of Name and Address can identify the record uniquely, but neither Name nor Address can be used to identify the records uniquely as it might be possible that we have two employees with similar name or two employees from the same house.
(III) Primary Key – A Candidate Key that is used by the database designer for unique identification of each row in a table is known as Primary Key. A Primary Key can consist of one or more attributes of a table.
E.g. of Primary Key - Database designer can use one of the Candidate Key as a Primary Key. In this case we have “Code” and “Name, Address” as Candidate Key, we will consider “Code” Key as a Primary Key as the other key is the combination of more than one attribute.
(IV) Foreign Key – A foreign key is an attribute or combination of attribute in one base table that points to the candidate key (generally it is the primary key) of another table. The purpose of the foreign key is to ensure referential integrity of the data i.e. only values that are supposed to appear in the database are permitted.
E.g. of Foreign Key – Let consider we have another table i.e. Department Table with Attributes “Department_ID”, “Department_Name”, “Manager_ID”, ”Location_ID” with Department_ID as an Primary Key. Now the Department_ID attribute of Employee Table (dependent or child table) can be defined as the Foreign Key as it can reference to the Department_ID attribute of the Departments table (the referenced or parent table), a Foreign Key value must match an existing value in the parent table or be NULL.
(V) Composite Key – If we use multiple attributes to create a Primary Key then that Primary Key is called Composite Key (also called a Compound Key or Concatenated Key).
E.g. of Composite Key, if we have used “Name, Address” as a Primary Key then it will be our Composite Key.
(VI) Alternate Key – Alternate Key can be any of the Candidate Keys except for the Primary Key.
E.g. of Alternate Key is “Name, Address” as it is the only other Candidate Key which is not a Primary Key.
(VII) Secondary Key – The attributes that are not even the Super Key but can be still used for identification of records (not unique) are known as Secondary Key.
E.g. of Secondary Key can be Name, Address, Salary, Department_ID etc. as they can identify the records but they might not be unique

Similar Messages

  • The 'c' XUSER key for the DBM user does not exist or could not be identified

    Hello members,
    I am getting this message  'The 'c' XUSER key for the DBM user does not exist or could not be identified' in SUM preparation phase while upgrading SOLMAN from 7.01 to 7.1
    Does anyone has any idea on this. What steps need to be followed for this.
    My DB is MaxDB.
    Thanks,
    Srikanth

    Hello,
    Figured out the problem. Actually SAP System was moved from actual server to Virtual machine on the server. In this process some of the DB configuration got corrupted. And this activity was done by one of our previous employee.
    Since this was a standalone system, I took backup of all current configuration and uninstalled SAP and installed new Solman 7.1 SPS12. Issue is resolved now.
    Best Regards,
    Srikanth
    Solman Upgrade from 7.01 to 7.1 stuck in Extraction-PREP_EXTRACT/BEGIN_PRE phase 

  • How do I create an Entity Bean with unknown primary keys

    Hi,
    Can a good folk help me.
    I am mapping an entity bean to an oracle table for the purpose of logging . I do not need a primary key contraint on this table. How do I specify in my entity bean file descriptor not to use any field for primary key ...
    I have done this so far...
    in my ejb.xml file - I set....
    <prim-key-class>java.lang.Object</prim-key-class>
    and deleted ....
    <primkey-field>...</primkey-field>
    My table structure is .....
    CREATE TABLE FAMS_REQUEST_LOG (
    EDITEDBY VARCHAR2(20),
    OLDTRANSDATE DATE,
    REQUESTID VARCHAR2(30) NOT NULL,
    OLDQTY NUMBER(20),
    NEWQTY NUMBER(20),
    NEWTRANSDATE DATE)
    but I still get this error message on deploying...
    [#|2006-03-01T14:30:29.250+0100|INFO|sun-appserver-pe8.1_02|javax.enterprise.system.tools.deployment|_ThreadID=19;|Total Deployment Time: 11000 msec, Total EJB Compiler Module Time: 0 msec, Portion spent EJB Compiling: 0%|#]
    [#|2006-03-01T14:30:29.265+0100|SEVERE|sun-appserver-pe8.1_02|javax.enterprise.system.tools.deployment|_ThreadID=19;|Exception occured in J2EEC Phase
    com.sun.enterprise.deployment.backend.IASDeploymentException: Fatal Error from EJB Compiler -- JDO74046: JDOCodeGenerator: Caught a MappingConversionException loading or creating mapping model for application 'fixassetenterpriseapp' module 'FixAssetEnterpriseApp-EJBModule': JDO71030: There is no column in table FAMS_REQUEST_LOG which can be used to support the servers implementation of unknown key classes.
    at com.sun.ejb.codegen.CmpCompiler.compile(CmpCompiler.java:274)
    at com.sun.ejb.codegen.IASEJBC.doCompile(IASEJBC.java:615)
    at com.sun.ejb.codegen.IASEJBC.ejbc(IASEJBC.java:563)
    at com.sun.enterprise.deployment.backend.EJBCompiler.preDeployApp(EJBCompiler.java:340)
    at com.sun.enterprise.deployment.backend.EJBCompiler.compile(EJBCompiler.java:209)
    at com.sun.enterprise.deployment.backend.AppDeployer.runEJBC(AppDeployer.java:284)
    at com.sun.enterprise.deployment.backend.AppDeployer.deploy(AppDeployer.java:176)
    at com.sun.enterprise.deployment.backend.AppDeployer.doRequestFinish(AppDeployer.java:107)
    at com.sun.enterprise.deployment.phasing.J2EECPhase.runPhase(J2EECPhase.java:146)
    at com.sun.enterprise.deployment.phasing.DeploymentPhase.executePhase(DeploymentPhase.java:71)
    at com.sun.enterprise.deployment.phasing.PEDeploymentService.executePhases(PEDeploymentService.java:633)
    at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:188)
    at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:520)
    at com.sun.enterprise.management.deploy.DeployThread.deploy(DeployThread.java:143)
    at com.sun.enterprise.management.deploy.DeployThread.run(DeployThread.java:172)
    |#]
    Dotun

    you will have to create a sequence and a trigger
    CREATE SEQUENCE <SEQUENCE NAME>
    INCREMENT BY  1
    START WITH  1
    NOCACHE
    /this sequence will guarantee that each requested number is unique
    the trigger will select from this sequence and insert the obtained value in the new record
    CREATE OR REPLACE TRIGGER <TRIGGER NAME>
    BEFORE INSERT ON <TABLE NAME>
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
        BEGIN
            select
                <SEQUENCE NAME>.nextval
            into
                :NEW.<COLUMN NAME>
            from
                dual;
        END;
    [/CODE]
    this will always take the value from the sequence, even if you already provided a value yourself
    (otherwise you will first have to test if :NEW.<column name> is null, but I wouldn't do this for a key column.
    if you need the generated key back for further processing (inserting it into a child table for example), you can use the returning clause on the insert statement
    see the oracle documentation for more information about sequences, triggers and the returning clause
    greetings
    Freek D
    I am new to Oracle and need to know how to create a table that uses an automatic incrementation on a primay key for it's default. I need the uniqueness automatically managed by the DBMS.. This activity is know as setting the Column (primary key with identity) in Ms-SQL..
    Your help would be appreciated greatly....
    Thanks....

  • Error in connect to database2EETW169 no connect possible: "DBMS = ORACLE

    Dear All,
    I am facing probem in sarting the sap after system copy.
    Database is up and running .Please find the logs
    There error it can connect to database
    r3trans log
    This is r3trans version 6.09 (release 640 - 26.10.04 - 15:45:42).
    unicode enabled version
    2EETW169 no connect possible: "DBMS = ORACLE                           --- dbs_o
    ra_tnsname = 'TAT'"
    r3trans finished (0012).
    trc file: "dev_disp", trc level: 1, release: "640"
    Wed Jul 22 20:03:18 2009
    kernel runs with dp version 128000(ext=102000) (@(#) DPLIB-INT-VERSION-128000-UC)
    length of sys_adm_ext is 524 bytes
    systemid   560 (PC with Windows NT)
    relno      6400
    patchlevel 0
    patchno    43
    intno      20020600
    make:      multithreaded, Unicode
    pid        552
    ***LOG Q00=> DpSapEnvInit, DPStart (00 552) [dpxxdisp.c   1100]
         shared lib "dw_xml.dll" version 43 successfully loaded
         shared lib "dw_xtc.dll" version 43 successfully loaded
         shared lib "dw_stl.dll" version 43 successfully loaded
         shared lib "dw_gui.dll" version 43 successfully loaded
    Wed Jul 22 20:03:23 2009
    WARNING => DpNetCheck: NiAddrToHost(1.0.0.0) took 5 seconds
    ***LOG GZZ=> 1 possible network problems detected - check tracefile and adjust the DNS settings [dpxxtool2.c  3886]
    MtxInit: -2 0 0
    DpSysAdmExtInit: ABAP is active
    DpSysAdmExtInit: JAVA is not active
    DpShMCreate: sizeof(wp_adm)          10528     (1316)
    DpShMCreate: sizeof(tm_adm)          2780232     (13832)
    DpShMCreate: sizeof(wp_ca_adm)          24000     (80)
    DpShMCreate: sizeof(appc_ca_adm)     8000     (80)
    DpShMCreate: sizeof(comm_adm)          290000     (580)
    DpShMCreate: sizeof(vmc_adm)          0     (372)
    DpShMCreate: sizeof(wall_adm)          (38456/34360/64/184)
    DpShMCreate: SHM_DP_ADM_KEY          (addr: 04540040, size: 3192688)
    DpShMCreate: allocated sys_adm at 04540040
    DpShMCreate: allocated wp_adm at 04541B58
    DpShMCreate: allocated tm_adm_list at 04544478
    DpShMCreate: allocated tm_adm at 045444A0
    DpShMCreate: allocated wp_ca_adm at 047EB0E8
    DpShMCreate: allocated appc_ca_adm at 047F0EA8
    DpShMCreate: allocated comm_adm_list at 047F2DE8
    DpShMCreate: allocated comm_adm at 047F2E00
    DpShMCreate: allocated vmc_adm_list at 04839AD0
    DpShMCreate: system runs without vmc_adm
    DpShMCreate: allocated ca_info at 04839AF8
    DpShMCreate: allocated wall_adm at 04839B00
    MBUF state OFF
    EmInit: MmSetImplementation( 2 ).
    <ES> client 0 initializing ....
    <ES> InitFreeList
    <ES> block size is 1024 kByte.
    Using implementation flat
    <EsNT> Memory Reset disabled as NT default
    <ES> 2456 blocks reserved for free list.
    ES initialized.
    rdisp/http_min_wait_dia_wp : 1 -> 1
    ***LOG CPS=> DpLoopInit, ICU ( 2.6.1 2.6 4.0) [dpxxdisp.c   1462]
    ***LOG Q0K=> DpMsAttach, mscon ( RFCLTEST) [dpxxdisp.c   9736]
    Wed Jul 22 20:03:24 2009
    CCMS: Initalizing shared memory of size 60000000 for monitoring segment.
    CCMS: start to initalize 3.X shared alert area (first segment).
    DpMsgAdmin: Set release to 6400, patchlevel 0
    MBUF state PREPARED
    MBUF component UP
    DpMBufHwIdSet: set Hardware-ID
    ***LOG Q1C=> DpMBufHwIdSet [dpxxmbuf.c   1025]
    DpMsgAdmin: Set patchno for this platform to 43
    Release check o.K.
    Wed Jul 22 20:04:04 2009
    ERROR => W0 (pid 2956) died [dpxxdisp.c   12187]
    ERROR => W1 (pid 2080) died [dpxxdisp.c   12187]
    my types changed after wp death/restart 0xbf --> 0xbe
    ERROR => W2 (pid 3556) died [dpxxdisp.c   12187]
    my types changed after wp death/restart 0xbe --> 0xbc
    ERROR => W3 (pid 2604) died [dpxxdisp.c   12187]
    my types changed after wp death/restart 0xbc --> 0xb8
    ERROR => W4 (pid 4024) died [dpxxdisp.c   12187]
    ERROR => W5 (pid 3816) died [dpxxdisp.c   12187]
    my types changed after wp death/restart 0xb8 --> 0xb0
    ERROR => W6 (pid 2820) died [dpxxdisp.c   12187]
    my types changed after wp death/restart 0xb0 --> 0xa0
    ERROR => W7 (pid 1448) died [dpxxdisp.c   12187]
    my types changed after wp death/restart 0xa0 --> 0x80
    DP_FATAL_ERROR => DpWPCheck: no more work processes
    DISPATCHER EMERGENCY SHUTDOWN ***
    increase tracelevel of WPs
    killing W0-2956 (SIGUSR2)
    ERROR => DpWpKill(2956, SIGUSR2) failed [dpxxtool.c   2468]
    killing W1-2080 (SIGUSR2)
    ERROR => DpWpKill(2080, SIGUSR2) failed [dpxxtool.c   2468]
    killing W2-3556 (SIGUSR2)
    ERROR => DpWpKill(3556, SIGUSR2) failed [dpxxtool.c   2468]
    killing W3-2604 (SIGUSR2)
    ERROR => DpWpKill(2604, SIGUSR2) failed [dpxxtool.c   2468]
    killing W4-4024 (SIGUSR2)
    ERROR => DpWpKill(4024, SIGUSR2) failed [dpxxtool.c   2468]
    killing W5-3816 (SIGUSR2)
    ERROR => DpWpKill(3816, SIGUSR2) failed [dpxxtool.c   2468]
    killing W6-2820 (SIGUSR2)
    ERROR => DpWpKill(2820, SIGUSR2) failed [dpxxtool.c   2468]
    killing W7-1448 (SIGUSR2)
    ERROR => DpWpKill(1448, SIGUSR2) failed [dpxxtool.c   2468]
    NiWait: sleep (10000 msecs) ...
    NiISelect: timeout 10000 ms
    NiISelect: maximum fd=1597
    NiISelect: read-mask is NULL
    NiISelect: write-mask is NULL
    Wed Jul 22 20:04:14 2009
    NiISelect: TIMEOUT occured (10000 ms)
    dump system status
    Workprocess Table (long)               Wed Jul 22 14:34:14 2009
    ========================
    No Ty. Pid      Status  Cause Start Err Sem CPU    Time  Program  Cl  User         Action                    Table
    0 DIA     2956 Ended         no      1   0             0                                                             
    1 DIA     2080 Ended         no      1   0             0                                                             
    2 UPD     3556 Ended         no      1   0             0                                                             
    3 ENQ     2604 Ended         no      1   0             0                                                             
    4 BTC     4024 Ended         no      1   0             0                                                             
    5 BTC     3816 Ended         no      1   0             0                                                             
    6 SPO     2820 Ended         no      1   0             0                                                             
    7 UP2     1448 Ended         no      1   0             0                                                             
    Dispatcher Queue Statistics               Wed Jul 22 14:34:14 2009
    ===========================
    --------++++--
    +
    Typ
    now
    high
    max
    writes
    reads
    --------++++--
    +
    NOWP
    0
    3
    2000
    10
    10
    --------++++--
    +
    DIA
    5
    5
    2000
    5
    0
    --------++++--
    +
    UPD
    0
    0
    2000
    0
    0
    --------++++--
    +
    ENQ
    0
    0
    2000
    0
    0
    --------++++--
    +
    BTC
    0
    0
    2000
    0
    0
    --------++++--
    +
    SPO
    0
    0
    2000
    0
    0
    --------++++--
    +
    UP2
    0
    0
    2000
    0
    0
    --------++++--
    +
    max_rq_id          13
    wake_evt_udp_now     0
    wake events           total     9,  udp     8 ( 88%),  shm     1 ( 11%)
    since last update     total     9,  udp     8 ( 88%),  shm     1 ( 11%)
    Dump of tm_adm structure:               Wed Jul 22 14:34:14 2009
    =========================
    Term    uid  man user    term   lastop  mod wp  ta   a/i (modes)
    Workprocess Comm. Area Blocks               Wed Jul 22 14:34:14 2009
    =============================
    Slots: 300, Used: 1, Max: 0
    --------++--
    +
    id
    owner
    pid
    eyecatcher
    --------++--
    +
    0
    DISPATCHER
    -1
    WPCAAD000
    NiWait: sleep (5000 msecs) ...
    NiISelect: timeout 5000 ms
    NiISelect: maximum fd=1597
    NiISelect: read-mask is NULL
    NiISelect: write-mask is NULL
    Wed Jul 22 20:04:19 2009
    NiISelect: TIMEOUT occured (5000 ms)
    Shutdown server ...
    DpJ2eeDisableRestart
    DpModState: buffer in state MBUF_PREPARED
    NiBufSend starting
    NiIWrite: write 110, 1 packs, MESG_IO, hdl 3, data complete
    MsINiWrite: sent 110 bytes
    MsIModState: change state to SHUTDOWN
    DpModState: change server state from STARTING to SHUTDOWN
    Switch off Shared memory profiling
    ShmProtect( 57, 3 )
    ShmProtect(SHM_PROFILE, SHM_PROT_RW
    ShmProtect( 57, 1 )
    ShmProtect(SHM_PROFILE, SHM_PROT_RD
    DpWakeUpWps: wake up all wp's
    Stop work processes...
    Stop gateway
    killing process (2004) (SOFT_KILL)
    Stop icman
    killing process (932) (SOFT_KILL)
    Terminate gui connections
    [DpProcDied] Process lives  (PID:2004  HANDLE:1576)
    waiting for termination of gateway
    NiWait: sleep (1000 msecs) ...
    NiISelect: timeout 1000 ms
    NiISelect: maximum fd=1597
    NiISelect: read-mask is NULL
    NiISelect: write-mask is NULL
    Wed Jul 22 20:04:20 2009
    NiISelect: TIMEOUT occured (1000 ms)
    [DpProcDied] Process died  (PID:2004  HANDLE:1576)
    [DpProcDied] Process died  (PID:932  HANDLE:1568)
    DpHalt: cancel all lcom connections
    MPI CancelAll 2 -> 0
    MPI DeleteAll 2 -> 0
    NiIMyHostName: hostname = 'RFCLTEST'
    AdGetSelfIdentRecord: >                                                                           <
    AdCvtRecToExt: opcode 60 (AD_SELFIDENT), ser 0, ex 0, errno 0
    AdCvtRecToExt: opcode 4 (AD_STARTSTOP), ser 0, ex 0, errno 0
    DpConvertRequest: net size = 163 bytes
    NiBufSend starting
    NiIWrite: write 562, 1 packs, MESG_IO, hdl 3, data complete
    MsINiWrite: sent 562 bytes
    send msg (len 110+452) to name          -, type 4, key -
    detach from message server
    ***LOG Q0M=> DpMsDetach, ms_detach () [dpxxdisp.c   9962]
    NiBufSend starting
    NiIWrite: write 110, 1 packs, MESG_IO, hdl 3, data complete
    MsINiWrite: sent 110 bytes
    MsIDetach: send logout to msg_server
    MsIDetach: call exit function
    DpMsShutdownHook called
    NiSelClear: removed hdl 3 from selectset
    MBUF state OFF
    AdGetSelfIdentRecord: >                                                                           <
    AdCvtRecToExt: opcode 60 (AD_SELFIDENT), ser 0, ex 0, errno 0
    AdCvtRecToExt: opcode 40 (AD_MSBUF), ser 0, ex 0, errno 0
    AdCvtRecToExt: opcode 40 (AD_MSBUF), ser 0, ex 0, errno 0
    blks_in_queue/wp_ca_blk_no/wp_max_no = 1/300/8
    LOCK WP ca_blk 1
    make DISP owner of wp_ca_blk 1
    DpRqPutIntoQueue: put request into queue (reqtype 1, prio LOW, rq_id 19)
    MBUF component DOWN
    NiBufClose: clear extensions for hdl 3
    NiBufSetStat: bufstat of hdl 3 changed from OK to OFF
    NiICloseHandle: shutdown and close hdl 3 / socket 1580
    MsIDetach: detach MS-system
    EsCleanup ....
    ***LOG Q05=> DpHalt, DPStop ( 552) [dpxxdisp.c   8495]
    Good Bye .....
    Regards,

    Hi,
    Yes it is running and in r3trans  log error
    [dboci.c     ,00000]  *** ERROR => OCI-call 'OCISessionBegin' failed: rc = 1017
    4 ETW000                                                                            4210  0.068739
    4 ETW000  [dbsloci.    ,00000]  *** ERROR => CONNECT failed with sql error '1017'
    4 ETW000                                                                              27  0.068766
    4 ETW000  [dev trc     ,00000]  Try to connect with default password                 155  0.068921
    4 ETW000  [dev trc     ,00000]  Connecting as SAPTST/<pwd>@TST on connection 0 ...
    4 ETW000                                                                              23  0.068944
    4 ETW000  [dev trc     ,00000]  Assigning username to user session 01DF23E0           16  0.068960
    4 ETW000  [dev trc     ,00000]  Assigning password to user session 01DF23E0           24  0.068984
    4 ETW000  [dev trc     ,00000]  Starting user session (con_hdl=0,svchp=01DE8C0C,srvhp=01DE9814,usrhp=01DF23E0)
    4 ETW000                                                                              27  0.069011
    4 ETW000  [dboci.c     ,00000]  *** ERROR => OCI-call 'OCISessionBegin' failed: rc = 1017
    4 ETW000                                                                            1521  0.070532
    4 ETW000  [dbsloci.    ,00000]  *** ERROR => CONNECT failed with sql error '1017'
    4 ETW000                                                                              24  0.070556
    4 ETW000  [dblink      ,00419]  ***LOG BY2=>sql error 1017   performing CON [dblink#1 @ 419]
    4 ETW000                                                                            4668  0.075224
    4 ETW000  [dblink      ,00419]  **LOG BY0=>ORA-01017: invalid username/password; logon denie*d [dblink#1 @ 419]
    4 ETW000                                                                              25  0.075249
    2EETW169 no connect possible: "DBMS = ORACLE                           --- dbs_ora_tnsname = 'TST'"
    REgards,

  • How do I Create an AutoIncrement on a Primary key Default

    I am new to Oracle and need to know how to create a table that uses an automatic incrementation on a primay key for it's default. I need the uniqueness automatically managed by the DBMS.. This activity is know as setting the Column (primary key with identity) in Ms-SQL..
    Your help would be appreciated greatly....
    Thanks....

    you will have to create a sequence and a trigger
    CREATE SEQUENCE <SEQUENCE NAME>
    INCREMENT BY  1
    START WITH  1
    NOCACHE
    /this sequence will guarantee that each requested number is unique
    the trigger will select from this sequence and insert the obtained value in the new record
    CREATE OR REPLACE TRIGGER <TRIGGER NAME>
    BEFORE INSERT ON <TABLE NAME>
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
        BEGIN
            select
                <SEQUENCE NAME>.nextval
            into
                :NEW.<COLUMN NAME>
            from
                dual;
        END;
    [/CODE]
    this will always take the value from the sequence, even if you already provided a value yourself
    (otherwise you will first have to test if :NEW.<column name> is null, but I wouldn't do this for a key column.
    if you need the generated key back for further processing (inserting it into a child table for example), you can use the returning clause on the insert statement
    see the oracle documentation for more information about sequences, triggers and the returning clause
    greetings
    Freek D
    I am new to Oracle and need to know how to create a table that uses an automatic incrementation on a primay key for it's default. I need the uniqueness automatically managed by the DBMS.. This activity is know as setting the Column (primary key with identity) in Ms-SQL..
    Your help would be appreciated greatly....
    Thanks....

  • Duplicate record with same primary key in Fact table

    Hi all,
       Can the fact table have duplicate record with same primary key . When i checked a cube i could see records with same primary key combination but the key figure values are different. My cube has 6 dimentions (Including Time,Unit and DP) and 2 key figures. So 6 fields combined to form the composite primary key of the fact table. When i checked the records in se16 i could see duplicate records with same primary key. Ther are no parallel loading happening for the cube.
    BW system version is 3.1
    Data base is : Oracle 10.2
    I am not sure how is this possible.
    Regards,
    PM

    Hi Krish,
       I checked the datapacket dimention also. Both the record have same dimention id (141). Except the Keyfigure value there is no other change in the Fact table record.  I know this is against the basic DBMS primary key rule. But i have records like this in the cube.
    Can this situation arise when same records is there in different data packet of same request.
    Thx,
    PM
    null

  • Changeover from DBM to SLM  not effecting

    Hi,
    I have created a depreciation key in transaction AFAMA with a changeover from DBM to SLM, provided when SLM depreciation is higher than DBM in 2 phases.  But when I run the depreciation for a asset, the changeover is not effecting rather it is calculating depreciation @ 50% across the life of the asset, instead of calculating the depreciation @ 25% DBM.

    Here we are not setting any changeover year, as per the req, it should compare the DBM with SLM, and whenever the SLM is higher than DBM dep, the changeover should become effective.
    Here how can we chk the changeover year?

  • Use of Foreign Keys in MDM

    Hi All,
    Is there any mean by which we can use Foreign Keys in MDM.
    Sighting an example.
    We have 3 table with fields:
    Products(Main Table): Material No( UF)
    Product Regions(Flat): Marerial No ( Foreign Key),Region: Lookup
    Prices(Flat): Material No( Foreign Key),Region: Lookup(Foreign Key),Price Type: Lookup.
    How is it possible to achieve the above mentioned scenerio.
    And are Foreign Keys same as Unique Fields in MDM. 
    Thanks
    Manish
    Edited by: manish gupta on Mar 4, 2009 12:30 PM

    Hi Manish,
    MDM server sits on the database server.
    The database server is a DBMS.MDM repository does not work with the tables and fields structure in exactly the same way as an RDBMS.
    So we do not use in the real sense the same Primary key Unique key concept.However we have the linkup/lookup field concept in MDM.
    Where a field in the main table can reference another field in the lookup table.
    So if you relate this to the RDBMS concept.The primary field in one table is the Foriegn key in another table.So in the lookup table we can refer a field of the main table.
    say for eg:
    You have a field Regions in the main table of type lookup flat.
    This field is actually used in the lookup flat table say lookup regions.
    This table has a field regions which is holding a legal set of values.
    So the field Regions in main table is used in the Lookup table as well.Where in the main table it was the linking field and in the lookup table it is the field holding the lookup values.
    So you can to an extent relate these 2 concepts but it does not precisily work in the same way in MDM.
    Hope It Helped
    Thanks & Regards
    Simona Pinto

  • Are foreign keys really necessary in a database design?

    Hi All,
    I am working on a database which has no foreign keys.
    Please suggest the necessity of foreign keys in database and can the foreign key implementation enhance the performance of the database.
    Thanks & Regards,
    Deepak Pushkarna

    [email protected] wrote:
    Hi Orion,
    As the application is a legacy application, so it has handled all the integrity part.Until someone touches the data outside the application. Can you spell "sqlplus"? Can you spell "odbc"?
    Or until some developer misses .... oh, developers never write buggy code ....
    >
    Regarding performance, the relation is not very complex but data is huge. So, if I implement foreign key relation, so will there be any improvement.
    It's really not about performance at all. It's about data integrity and data integrity is best protected by the dbms itself. In fact, the dbms is the only layer that you can be sure is going to protect your data integrity.
    >
    Thanks & Regards,
    Deepak Pushkarna

  • Composite Primary Key question

    I have a new question regarding composite primary keys on another table I have created.
    I have the following table with the following definition:
    CREATE TABLE "APSOM"."CPULIST"
    ( "CPU_ID" VARCHAR2(10 BYTE),
    "SERVER_ID" VARCHAR2(10 BYTE),
    "CREATED_DATETIME" TIMESTAMP (6),
    "UPDATED_DATETIME" TIMESTAMP (6)
    with the following composite PK definition:
    ALTER TABLE "APSOM"."CPULIST" ADD CONSTRAINT "CPULIST_PK" PRIMARY KEY ("CPU_ID", "SERVER_ID")
    Then, I inserted data in the following way:
    insert into CPULIST
    values ('CPU1', 'P1', SYSDATE, SYSDATE);
    with following CPU ID values from 'CPU1' to 'CPU16' for SERVER ID value 'P1' also inserted as well.
    Now, I am trying to insert values for SERVER ID value 'P2'
    insert into CPULIST
    values ('CPU1', 'P2', SYSDATE, SYSDATE);
    and I am getting the following error message:
    Error starting at line 1 in command:
    insert into CPULIST
    values ('CPU1', 'P2', SYSDATE, SYSDATE)
    Error report:
    SQL Error: ORA-00001: unique constraint (APSOM.XPKCPULIST) violated
    00001. 00000 - "unique constraint (%s.%s) violated"
    *Cause: An UPDATE or INSERT statement attempted to insert a duplicate key.
    For Trusted Oracle configured in DBMS MAC mode, you may see
    this message if a duplicate entry exists at a different level.
    *Action: Either remove the unique restriction or do not insert the key.
    Using the following SQL command:
    select column_name from all_cons_columns
    where constraint_name = 'CPULIST_PK'
    and owner = 'APSOM';
    I get the following records
    1. CPU_ID
    2. SERVER_ID
    This error does not make sense to me. Any help would be appreciated.
    Thanks,
    Patrick Quinn
    Operations
    Turning Point Global Solutions

    So, if there is a hidden unique constraint XPKCPULIST that cannot be pulled the all_cons_column table and I drop the XPXCPULIST constraint with the following SQL:
    alter table CPULIST drop constraint XPKCPULIST;
    Error starting at line 1 in command:
    alter table CPULIST drop constraint XPKCPULIST
    Error report:
    SQL Error: ORA-02443: Cannot drop constraint - nonexistent constraint
    02443. 00000 - "Cannot drop constraint - nonexistent constraint"
    *Cause:    alter table drop constraint <constraint_name>
    *Action:   make sure you supply correct constraint name.
    What can I do to get past this so I can perform the following insert and receive this error message??
    insert into CPULIST
    values ('CPU1', 'P2', SYSTIMESTAMP, SYSTIMESTAMP);
    Error starting at line 1 in command:
    insert into CPULIST
    values ('CPU1', 'P2', SYSTIMESTAMP, SYSTIMESTAMP)
    Error report:
    SQL Error: ORA-00001: unique constraint (APSOM.XPKCPULIST) violated
    00001. 00000 - "unique constraint (%s.%s) violated"
    *Cause:    An UPDATE or INSERT statement attempted to insert a duplicate key.
    For Trusted Oracle configured in DBMS MAC mode, you may see
    this message if a duplicate entry exists at a different level.
    *Action:   Either remove the unique restriction or do not insert the key.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Primary key generation

    How do use primary keys generated by database within entity bean?

    DBMS primary key generation uses a set of deployment descriptors that
    are specified at compile time to generate container code which is used
    in conjunction with a supported database to provide key generation
    support. Specify the name of the supported DBMS and the generator name,
    if required by the database. Generated primary key support for Oracle
    databases use Oracle's SEQUENCE. Once the SEQUENCE already exists in the
    database, you specify automatic key generation in the XML deployment
    descriptors. In the weblogic-cmp-rdbms-jar.xml file
    <automatic-key-generation>
    <generator-type>ORACLE</generator-type>
    <generator_name>test_sequence</generator-name>
    <key-cache-size>10</key-cache-size>
    </automatic-key-generator>
    You need to specify the name of the ORACLE SEQUENCE to be used in the
    generator-name element. If the ORACLE SEQUENCE was created with an
    INCREMENT value, then you must specify a key-cache-size. This value must
    match the Oracle SEQUENCE INCREMENT value.
    Owen wrote:
    How do use primary keys generated by database within entity bean?

  • Account Assignment Group in DBM Order

    Hey Experts,
    When I change the account assignment group (AcctAssgGr) in DBM order split screen for the customer in the transaction level it is not taking the changed accont assignment group. Basically I want to overwrite the account assignment group given in the customer master record. Please advice.
    This requirment is basically since the customer is defined as a credit customer, but at times the customer will have cash sale transactions as well. Thus the account that needs to be posted is different. For this I need to change the account assignment group in the transaction level without changing the master record.
    Hope the question is clear.

    Hi,
    yes I found that this is standard behavior programmed, i.e. AAG is picked from customer master while passing to billing document. Only way I think is to use user exit
    USEREXIT_FILL_VBRK_VBRP in program SAPLV60A
    Below is sample code:
       DATA: lo_order   TYPE REF TO /dbm/cl_order.
       FIELD-SYMBOLS:  <ls_splhdr>   TYPE /DBM/SPLIT_COM.
       if xkomfkgn-/dbm/vbeln IS NOT INITIAL.
       and xkomfkgn-/dbm/splnr IS NOT INITIAL.
       PERFORM get_order_object_for_billing IN PROGRAM /dbm/saplorder_int
                                                    USING fkomfkgn-/dbm/vbeln
                                                 CHANGING lo_order.
       CHECK lo_order IS BOUND.
    * transport charg from order item to the invoice
       READ TABLE lo_order->MT_SPLHDR_COM WITH KEY vbeln = fkomfkgn-/dbm/vbeln
                                                SPLNR =  fkomfkgn-/dbm/splnr
                                                  ASSIGNING <ls_splhdr>.
        VBRK-ktgrd = <ls_splhdr>-ktgrd.
       endif.

  • Database Primary Key Question - Best Practices

    I posted this in the ADDT forum, but I imagine I'll get more
    responses here:
    All you database developers - how do you deal with primary
    keys? Do you
    ALWAYS use an AutoIncrement/AutoNumber? Or only sometimes? Is
    there an
    argument to NOT use AutoIncrement? I know how I create
    databases and how
    I usually do things. I know how a few of my colleagues work.
    But how
    about the rest of the world? (Research for a MS Access book I
    am
    involved with.)
    Alec
    Adobe Community Expert

    .oO(Alec)
    >I posted this in the ADDT forum, but I imagine I'll get
    more responses here:
    >All you database developers - how do you deal with
    primary keys? Do you
    >ALWAYS use an AutoIncrement/AutoNumber?
    No.
    >Or only sometimes? Is there an
    >argument to NOT use AutoIncrement?
    AUTO_INCREMENT is a proprietary MySQL feature. For some
    people this
    might be an argument against it, but doesn't have to. Every
    DBMS has its
    own special features. You just have to decide whether you
    want to keep
    your code/queries as portable as possible or want to get the
    most out of
    your DB. Usually I prefer performance/features over
    portability, simply
    because for me and my projects it's very unlikely that I have
    to change
    the DBMS. I've chosen MySQL for good reasons and will stay
    with it for
    quite a while.
    >I know how I create databases and how
    >I usually do things. I know how a few of my colleagues
    work. But how
    >about the rest of the world? (Research for a MS Access
    book I am
    >involved with.)
    It always depends on the table itself, what data it contains,
    what I
    want to do with it and also some personal preferences. In n:m
    tables for
    example there's no need for an extra numeric PK, since the
    entire record
    already is the PK, built from two or more FKs.
    But if I need a numeric PK, I usually use sequences. Some
    DBMS support
    them natively, in MySQL they can be emulated with an extra
    table. It
    simply means, that the used PK number is generated _before_
    the record
    itself is inserted. For me and my framework this has some
    advantages
    (makes the internal work a bit easier), but of course in
    other cases an
    AUTO_INCREMENT might be more appropriate.
    So IMHO there's no general solution. If an AUTO_INCREMENT or
    something
    similar fits your needs, you should use it. I don't see a
    real problem
    with that.
    Micha

  • ResultSet updateRow ,insertRow ,deleteRow APIs on table with no PRIMARY KEY

    Hi,
    When I use ResultSet.insertRow , updateRow ,deleteRow API's on a table which contais no primary key column I find the following Exception ,
    java.sql.SQLException: Operation invalid. No primary key for the table
    at com.tandem.sqlmx.Messages.createSQLException(Messages.java:69)
    at com.tandem.sqlmx.SQLMXResultSet.getKeyColumns(SQLMXResultSet.java:3501)
    at com.tandem.sqlmx.SQLMXResultSet.prepareInsertStmt(SQLMXResultSet.java:3652)
    at com.tandem.sqlmx.SQLMXResultSet.insertRow(SQLMXResultSet.java:2073)
    at testdateupdate.main(testdateupdate.java:33)
    It looks like the table needs to have a primary key column to update or insert or delete rows using the ResultSret APIs.
    I use a proprietary JDBC driver. I find the Explanation for this behavior like this ,
    JDBC allows update stmts on tables w/out a primary key defined if the stmt is issued by the application. For updateable ResultSets, a primary key restriction is required to avoid updating more rows than desired.I dont understand this explanation and also I dont find this behavior is some other JDBC drivers that I tried with.
    Some one Please Clarify the same.
    Thanks in Advance.
    Thanks and Regards,
    Jay

    Hi,
    in simple words, when a table does not have primary key you can send update and delete on it only by using a Statement object. When using ResultSet.updateRow or ResultSet.deleteRow the jdbc looks for the primary key on the metadata in order to send the correct where clause to the rdbms. I think that this could maybe work with Oracle DBMS, which has a unique id (ROWID) for each record.
    Kiros

  • Retrieving Primary Keys MetaData from database

    Hello all,
    I am trying to retrieve a list of primary keys, give a catalogname, schemaname and tablename. But the ResultSet that's being returned doesn't have the "PK_NAME" column itself.
    ResultSet rset = dbm.getPrimaryKeys(null,null,tablename);
    while(rset.next())
    ResultSetMetaData rsmetadata = rs.getMetaData();
    int ncols = rsmetadata.getColumnCount();
    for(int i=1;i<=rsmetadata.getColumnCount();i++)
    //Here's where I print the columnnames in the ResultSet
         System.out.println(rsmetadata.getColumnName(i));
    Can someone tell me how to retrieve the list of primary keys if not this way?
    Thanks

    Ahh don't worry about this. I figured out the problem :)
    Thanks guys.

Maybe you are looking for