How to define Composite primary key for a Table

Hi ,
I am basically more into Java Programming , with little bit knowledge on Oracle as DataBase .so please excuse for my silly doubts .
Can anybody please tell me how to define a Composite Primary Key on a Table .
Thanks in advance .
Edited by: user672373773 on Sep 25, 2009 8:54 AM

Here is an example right out of the Oracle documentation and the syntax for adding PK since you mention adding a composite PK.
Example creating composite index
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14251/adfns_indexing.htm#sthref594
Syntax for adding a PK (composite or not)
alter table oooooooo.tttttttt
add constraint tttttttt_PK
primary key (sample_column2,
sample_column1)
using index
tablespace IDXSPC
pctfree 05
initrans 04
maxtrans 08
storage (initial 16k
next 16k
maxextents 32
pctincrease 0);
-- dictionary management with restricted storage, change as desired.
HTH -- Mark D Powell --

Similar Messages

  • Define composite primary key in UDT

    hi experts,
    Anyone know how to define composite primary key in UDT with code.
    thanks,
    regards,
    sohch

    There is a metadata object for this, UserKeysMD.
    Documented in the SDK Help File.

  • Is it possible to create many primary key for a table?

    hello sir/mam.
    i am selva, i am new to abap,
    is it possible to create many primary key for a table?
    please guide me.

    Hi Selva,
    Many Primary Keys = Composite Key.
    i.e some set of columns will enable you to identify a unique row from a set of rows in the table.
    This can be achieved by checking the primary key check box in se11.
    Hope it helps.
    Regards,
    Maheswaran.B
    Message was edited by: Maheswaran B

  • Composite primary key in oe_order_headers_all table?

    Hi all
    What are columns involved in composite primary key in oe_order_headers_all table? how to identify that?
    (Order_number, order_type, org_id) are the combination of composite primary key or anything else ?

    select * From all_constraints where table_name = 'OE_ORDER_HEADERS_ALL'
    SELECT AIC.* FROM ALL_INDEXES AI, ALL_IND_COLUMNS AIC
    WHERE AI.TABLE_NAME='OE_ORDER_HEADERS_ALL'
    AND AI.UNIQUENESS='UNIQUE'
    AND AI.INDEX_NAME = AIC.INDEX_NAME
    order by AI.INDEX_NAME
    Hope this helps,
    Sandeep Gandhi

  • Multiple composite primary key in Master Table

    Dears ,
    I am try to find any solution about Multiple composite primary key by search in forum , but i didn't success ... i am try to built master detail , the master structure table built with multiple composite primary key , i know that apex 4.2 still support tow primary key , in detail table i solved the problem by depend on rowid , and now i can use multiple composite primary key in detail table , the problem with master table because it's support only tow primary key , there are any solution by manual process or any something else ?
    Thanks
    Abo Yahya

    Hi,
    I've never done this so all I can do is give some suggestions. It takes more effort because you are going beyond what APEX currently supports. That said, you might try searching the forum with this search string:
    key AND table AND instead
    Make sure the ANDs are capitailized in the search criteria. Also, look at this thread {thread:id=395870} and the forum thread asociated with this message {message:id=10542916}.
    Best wishes,
    Howard

  • How add new field as primary key for existing table

    Hi,
    There is table with name REVIEWER_REUSE_EFFORT and the table has 8000 rows in it.
    Now the enhacement i must do on this table is there is no primary key on this table. so i must create a ID also add values to this table of ID
    Table structure is like this
    Create table REVIEWER_REUSE_EFFORT
    PRO_ID number,
    POBJ_ID number,
    TASK_ID number,
    POTENTIAL_EFFORT number,
    COMMENTS varchar2(1200),
    CREATED_BY varchar2(100),
    CREATION_DATE sysdate
    UPDATED_BY varchar2(1200),
    UPDATED_DATE sysdate
    Please suggest me how to add values in that 8000 rows
    Thanks
    Sudhir

    Hi,
    If you want to add a new column and update the new column with sequence of number
    alter table REVIEWER_REUSE_EFFORT add (ID number);
    update REVIEWER_REUSE_EFFORT  set ID=rownum;Regards,
    Prazy
    Edited by: Prazy on Jun 21, 2010 3:13 PM

  • How many primary keys for one table?can we add more primary keys

    In general Table have one  primary key.is it possible to more than one primary key in a table?(ie is it possible to add more than one pirmary key in a table). Help me out.

    pls do check this link
    [http://help.sap.com/saphelp_nw04/helpdata/en/cf/21ea0b446011d189700000e8322d00/frameset.htm|http://help.sap.com/saphelp_nw04/helpdata/en/cf/21ea0b446011d189700000e8322d00/frameset.htm]
    All the key fields of a table must be stored together at the beginning of the table. A non-key field may not occur between two key fields.
    A maximum of 16 key fields per table is permitted. The maximum length of the table key is 255.
    If the key length is greater than 120, there are restrictions when transporting table entries. The key can only be specified up to a maximum of 120 places in a transport. If the key is larger than 120, table entries must be transported generically.

  • How to create a foreign key for the table from two different tables?

    Hi All,
    I have a three table like below. In the below table SAMPLE_CONS_CHECK and SAMPLE_CONS2_CHECK will be having the primary key for NAME column. The same SAMPLE_CONS3_CHECK table also having the primary key for NAME column and forieign key for SAMPLE_CONS_CHECK and SAMPLE_CONS2_CHECK tables. See the below code 2
    code 1:
    CREATE TABLE SAMPLE_CONS_CHECK
            (NAME VARCHAR2(10),
            SERIES  VARCHAR2(5)
    CREATE TABLE SAMPLE_CONS2_CHECK
            (NAME  VARCHAR2(5),
             MODEL  NUMBER
    CREATE TABLE SAMPLE_CONS3_CHECK
            (NAME  VARCHAR2(5),
             MODEL_NO  NUMBER
            )code 2
    alter table SAMPLE_CONS_CHECK
    add constraint SAMPLE_CONS_CHECK_pk primary key (NAME)
    alter table SAMPLE_CONS2_CHECK
    add constraint SAMPLE_CONS2_CHECK_pk primary key (NAME)
    alter table SAMPLE_CONS3_CHECK
    add constraint SAMPLE_CONS3_CHECK_pk primary key (NAME)
    ALTER TABLE SAMPLE_CONS3_CHECK ADD
    CONSTRAINT SAMPLE_CONS3_CHECK_FK1 FOREIGN KEY
         NAME
    ) REFERENCES SAMPLE_CONS_CHECK
        NAME
    ) ON DELETE CASCADE;
    ALTER TABLE SAMPLE_CONS3_CHECK ADD
    CONSTRAINT SAMPLE_CONS3_CHECK_FK2 FOREIGN KEY
         NAME
    ) REFERENCES SAMPLE_CONS2_CHECK
        NAME
    ) ON DELETE CASCADE;From the above schenario i am able to insert the data to SAMPLE_CONS3_CHECK table. But the parent data is already available in the parent table. The problem is here two different constarints from two different tables. While inserting, it is checking from both the tables whether the parent is exist or not.
    How can i solve this problem? Can anyone halp me about this?
    Thanks
    Edited by: orasuriya on Aug 8, 2009 2:02 AM

    Actually the design is completely incorrect.
    What you say is
    I have
    'foo', 'foo series'
    'foo','foo model'
    'foo',666
    By virtue of table3 referring to both table1 and table2.
    This means you actually need to have 1 (one) table:
    'foo','foo series','foo model', 666
    And the 'problem' disappears.
    Sybrand Bakker
    Senior Oracle DBA

  • How to get the PRIMARY KEY of a table at runtime ???

    Hi everybody,
    My requirement is to update a z-table at runtime according to the data given ata runtime. So the main difficulties for me is that whenever I tried to update the table based on the data given in UI many rows are getting updated as these fields are not unique. So I think if I can get the PRIMARY KEY along with these given fields then I can update only one row at a time.
    So Can anyone suggest me how to get PRIMARY KEY of a table based on the data in UI..??
    Any suggestions will be appreciated..
    Thanks,
    Sekhar

    U will get primary keys of transparent tables using FM "REUSE_FIELDCALATLOG_MERGE".
    pass tyour table name and u will get fieldcatalog filled. In tht their is a field called "KEY" if it has 'X' then tht field is a primary key of transparent tables & if it has "space" then it is not a primary key...
    Or else you can try with 'DDIF_TABT_GET'
    Or try this code
    PARAMETERS: p_table TYPE tabname OBLIGATORY.
    DATA: go_strucdescr   TYPE REF TO cl_abap_structdescr,
          gt_tab_fields   TYPE ddfields.
    FIELD-SYMBOLS: <gwa_tab_field> TYPE dfies.
    TRY .
    *   Get the details of the DDIC table
        go_strucdescr ?= cl_abap_elemdescr=>describe_by_name( p_table ).
      CATCH cx_sy_move_cast_error .
        MESSAGE 'Error while casting' TYPE 'S'. RETURN.
    ENDTRY.
    * Check if input is a DDIC table
    CHECK go_strucdescr->is_ddic_type( ) = 'X'.
    * Get the details of the table fields
    gt_tab_fields = go_strucdescr->get_ddic_field_list( ).
    * Display the Key fields of the table
    LOOP AT gt_tab_fields ASSIGNING <gwa_tab_field> WHERE keyflag = 'X'.
      WRITE: / <gwa_tab_field>-fieldname.
    ENDLOOP.

  • How to create one primary key for each vendor

    Hi all
    i am doing IDOC to jdbc scenario
    i am triggering idoc from R/3 and the data is going into DB table vendor through XI.
    structures are as follows:
    sender side: ZVendorIdoc (this is a customized IDOC , if i triger IDOC for multiple vendors then it triggers only 1 idoc with multiple segment )
    Receiver side:
    DT_testVendor
        Table
            tblVendor
                action UPDATE_INSERT
                access                     1:unbounded
                    cVendorName         1
                    cVendorCode        1
                    fromdate                1
                    todate                    1
                 Key1
                    cVendorName         1
    if i trigger idoc for multiple vendors ,for example vendor 2005,2006 and 2010 . then i can see that the only key comes from the very first field (2005) and the whole record for vendor 2005,2006 and 2010  goes into the table with this(2005) as a primary key
    now again if i send data for these three vendor 2005, 2006 , 2010, in which record for the vendor 2005 is same and for 2006 and 2010 are different than it takes 2005 as a primary key and it does not update the data in the table.
    my requirement is like this:   for each vendor there should be one unique key assigned.
                                              for above said example there should come three keys one for each vendor .
    could you please help me how to do this???????????

    Hi,
      In Mapping Make the statement is 0-unbounded.For each vendor create a statement.This will solve your problem.
    Regards,
    Prakasu.M

  • How to "auto" generate "Primary Key" in custom table?

    Hi Folks,
    Requirement:
    I need a function module or program that can create automatically a primary key.
    Scenario:
    I have a program that creates an entries and save it to a custom table at the same time, but a primary key should always be generated respective to the entries saved.
    Example:
    Material(MATNR) 4001001, Plant(WERKS) XX01, ID[Primary Key-auto generated]
    (I'm thinking of a similar concept/logic on how a unique IDOC number is being generated or how SAP standard creates a unique entry)
    I try to look for any SAP FM that can generate a PK, but there's no luck.
    Thanks.
    Regards,
    Jun

    Hi Keshu and All,
    The links are helpful, however:
    #1. I don't have authorization to create a new object in transaction SNRO, but the way I see the objects in SNRO is just for defining the length(number of characters) for the ranges that will be use if I'm not mistaken.
    #2. FM NUMBER_GET_NEXT - yes it can populate incremental unique entries but it's only occurring at runtime ?? So when the program get terminated it's not being saved nowhere.
    So after if I use FM NUMBER_GET_NEXT, I always have to look for all the last primary key in my custom table, then target it as my starting point for creating a new PK.  I think this will give a performance issue, any comments?
    For better visualization, I have scenario:
    1.  (ZQ_CREATE_PK) Create unique incremental PK for material, batch, so on..
    2.  Append line/entries to ZQ_TABLE
    3.  Repeat #1 and #2
    4.  User exits the program
    5.  Back to 1 --> At this point, I need to get the "LATEST" PK then start this as a starting point again to generate PK and append it to ZQ_TABLE
    I'm assuming that SAP has other SAP FMs related in creating this scenario.   Similar to IDOC # creation..
    Thanks.

  • How to use 2 primary key in 1 table

    Hi,
    When i creating the table,in this the following are the columns Name,Street,City,Pin in this they give some rules the column Name & City as Primary Key. But when type the query it shows the error table contains one primary key, how i do this? Tell the mistakes

    Hi,
    Welcome to the forum!
    Whenever you have a question, please post your code. Ithelps people understand what the problem is. and allows them to test ideas.
    1000492 wrote:
    Hi,
    When i creating the table,in this the following are the columns Name,Street,City,Pin in this they give some rules the column Name & City as Primary Key. But when type the query What do you mean by "But when type the query"?
    Do you mean "But when I run this query ..."?
    it shows the error table contains one primary key, how i do this? What is the query you're running? What are the results? Did you expect other results? What results did you expect? Why?
    Tell the mistakesThere are not necessarily any mistakes.
    By definition, a table can never have more than 1 primary key. (If needed, a table can have any number of unique keys, that are like primary keys in everything but name.)
    Any key, primary or unique, can be composed of 1, 2, 3 or more columns.

  • Any easy way to generate unique primary key for database table?

    I'm currently playing with the J2EE reference implementation from Sun which comes with the IBM Cloudscape database. This Cloudscape database supports the use of an AutoIncrement field.
    First question: Can I use CMP and assume that the database will generate a proper key for me? Anyone tried it out successfully before?
    Also, based on what I've heard so far, it seems that generating database primary key is not really well-supported by J2EE using CMP in that a lot of J2EE developers have to resort to workarounds like using a session bean, JDBC and (1) some seed numbers for ID implanted in the database itself (as in the J2EE tutorial DukesBankApp example) or (2) using the SQL MAX aggregation command + 1. Usign seed number is contradictory to good database design and using MAX is dangerous for heavy traffic application if 2 beans try to insert themselves into the database at the same time (synchronizarion problem).
    Anyway I find it dumb that we still have to go back to JDBC and SQL which was the reason why the concept Entity Bean was introduced; to make database persistence transparent! Now it seems that J2EE makes it worse and more troublesome than before.
    Second Question: Is there any easy (hopefully transparent/automatic) way of generating primary key ID?

    if you want to rely on your container or database then go hard, will probably be faster.
    to make a cross container/db soln I used a CMP Entity bean called Sequence with one field for uid
    I use one instance and increment the field each time.
    To do the logic, I have a utils class with static method, no need for session bean overhead
    I reckon this approach is OK considering all things

  • Primary key for active table

    hi
    can anyone tell me step by step to create primarykey for active table of dso that already has data loaded. few requests are activated and few are not activated.
    points for sure.
    regards
    anil

    Anil,
    This is absolutely mandatory to delete the data from any of the table if you want to change the key fields of the table. This is as good as universal law in data base theory
    Now as far as your ODS is concerned, you have to delete the complete data from it and then you can change the key fields of it. Again you just need to change this in the definition of ODS and not in any particular table.
    Just change the definition of ODS in development and transport it to production. Make sure top delete the data before you transport it. If not, transport will fail.
    Hope this info helps you.
    Regards,
    Yogesh

  • How to define a standard value for a table field

    Hi All,
    I have a date field in a database table, for that while maintaining if we don't give any value it should get the present date.  How can we do this.
    Thanks,
    bsv.

    Hi,
    This functionality is known to be very important and is a key part of the next major release of the JRC planned for the first half of 2008.
    Regards,
    <p>Blair Wheadon</p>
    <p>Product Manager, Crystal Reports</p>

Maybe you are looking for

  • Self referencing VO in an ADF Tree

    Hi @all i want to create an ADF Tree and found the following helpful example: ADF Code Corner sample #32 show how to build a tree table from a self referencing VO: [http://www.oracle.com/technetwork/developer-tools/adf/learnmore/index-101235.html#Cod

  • Kinect for Windows v2 Hand Pointer Gestures

    Hi, how can I use Kinect for Windows v2 WPF control ? I would like to write some app which will use a hand and finger pointer. I saw that this is possible in Windows Store application but I want to write in WPF. Is it possible ? I think I should use

  • Dynamically include jsp:param

    Is it possible to include <jsp:param> inside <jsp:forward> dynamically? There are two ways: 1) <jsp:forward ...> <% if (...) { %>      <jsp:param ... /> <% } %> </jsp:forward> 2) <jsp:forward ...> <util:if predicate="...">      <jsp:param ... /> </ut

  • LSMW for GL account Master data

    Hi all, I have to create one lsmw tool in GL ACCOUNT master data. Please suggest me which method i should adopt. direct input, BAPI , Recording OR IDOC. IF bapi or recording, please tell me BAPI or transaction for GL account master data. Reagrds, Ruc

  • HT1692 my iPhone4 screen is broken and i need my contacts list ?

    MY IPHONE4 SCREEN IS BROKEN I NEED RECOVER MY CONTACTS A.S.A.P