Keys in the table

I am new to writing SQL queries to pull the data from more than one table. how many keys can a table have. Can there be a combination of more than one key to identify a unique record in a table. How will I know which keys should be used to join the tables.

Depending on one's definition of "key", a table can have as many keys as you would like. A table can have only one primary key, but you can declare as many columns or combinations of columns as unique keys as you would like. Subject, of course, to the limit of ~1000 columns per table and the combinatorial limit on the number of ways that many columns can be combined.
Yes, you can define either the primary key or a unique key as a combination of multiple columns.
How will I know which keys should be used to join the tables.Option 1 would be to have an ERD diagram on hand to show the relationships between tables.
Option 2 would be to query the DBA_CONSTRAINTS table (or, more likely, to look at the table definition in your favorite PL/SQL IDE) and to look at the foreign key relationship between the parent and the child tables.
Justin

Similar Messages

  • Foreign keys at the table partition level

    Anyone know how to create and / or disable a foreign key at the table partition level? I am using Oracle 11.1.0.7.0. Any help is greatly appreciated.

    Hmmm. I was under the impression that Oracle usually ignores indices on columns with mostly unique and semi-unique values and prefers to do full-table scans instead on the (questionable) theory that it takes almost as much time to find one or more semi-unique entries in an index with a billion unique values as it does to just scan through three billion fields. Though I tend to classify that design choice in the same category as Microsoft's design decision to start swapping ram out to virtual memory on a PC with a gig of ram and 400 megs of unused physical ram on the twisted theory that it's better to make the user wait while it needlessly thrashes the swapfile NOW than to risk being unable to do it later (apparently, a decision that has its roots in the 4-meg win3.1 era and somehow survived all the way to XP).

  • 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

  • Error while renaming indexes and keys in the tables

    hi gems...good afternoon..
    i am using oracle 11gr2 database.
    when i am trying to rename the primary key, foreign key, indexes of all the tables as per the standard, then the following error is given...
    ORA-00604: error occurred at recursive SQL level 1
    ORA-01000: maximum open cursors exceeded
    ORA-00604: error occurred at recursive SQL level 1
    ORA-01000: maximum open cursors exceeded
    ORA-01000: maximum open cursors exceeded
    currently the maximum open cursors parameter is set to 300.
    please help..thanks in advance

    thanks a lot for your help..
    there are total 162 records in the v$open_cursor for that user.
    among that the open cursor is only 4 and open-recursive cursor is only 6 for that user.
    in my session i am executing only the renaming of the constraints and nothing more.
    When i have queried the v$open_cursor for cursor_type='OPEN' for all the users, then i got that it has exceeded the value of open_cursors parameter.
    So how can i resolve that....

  • DBMS_CDC find only the columns that are changed along with the primary key in the table

    Hello,
    We are having a requirement to find the change data in the production environment.
    We are planning to use the DBMS_CDC utility.
    But for  example in the create change table 1 picked emp_id,ename, address, salary,dob.
    I have a sample data of
    empid
    ename
    address
    salary
    DOB
    1
    test1
    24 test street
    2000
    20-Jan-98
    2
    test2
    25 test street
    2500
    15-Aug-97
    if ename for empid 1 is changed to test1_test3 from test1.
    My CDC is capturing  the values in the old and new values in the 5 columns.
    But i need to get only the empid (primary key of the source table) and the ename column as only that's been updated not the rest of the 3 columns.
    Can i accomplish this.
    Please advice.

    Hello,
    Thanks for the information.
    but if i change the change table  then i will miss the other columns right?
    I want to get the columns( empid and ename) only if ename is changed. i.e when ever any column in emp table changes i need to get all the columns where the data is changed along with the primary key columns empid.
    Is there any way i can tweak the parameters so that i can achieve this or is there any other way using the cdc i can get this data.
    Thanks

  • REFRENCEING PRIMARY KEY IN THE TABLE

    Hi,
    I want to refer the composite primary key column into one table that is i have one primary key with three columns and i want to refer only one column as a forigen key in the other table.
    how do i do that ?
    regards
    gaurav
    null

    Foreign keys have to map to primary keys. If your master table requires three columns to uniquely identify a record then its children must have those three columns as well. This can lead to the apparently absurd situation where you have tables whose keys consist of more columns than the actual table data.
    The alternative is to use an artificial ID column as the PK and make the other columns an unique key. The problem with synthetic primary keys is that it makes it difficult to identify children or grandchildren: you always have to join with the parent table or denormalise your data.
    Example: ORDERS identified by Ord_No
    ORDER_ITEMS identified by ord_itm_no
    Natural key: ORDERS PK = order_no
    ORDER_ITEMS PK = order_no
    , ord_itm_no
    Here it is easy enough to find which items belong to Order 1234 just by querying ORDER_ITEMS table.
    Synthetic key: ORDERS PK = id
    UK = order_no
    ORDER_ITEMS PK = ORDERS.id, id
    UK = order_no, ord_itm_no
    Here to find which items belong to Order 1234 you have to query ORDERS to find the ID before querying ORDER_ITEMS table. You have to have triggers on the ORDER_ITEMS table to populate the denormalised columns order_no and ord_item_no.
    Which approach you take ought to depend upon your database and what you do with it but it take on the flavour of a religious war. The orthodox view (the word of Codd) firmly supports using natural keys.
    ciao, APC

  • Object Key in the table BKPF

    hi,
    can somebody tell me how the data is filling to the filed " object key"(AWKEY) in the table "BKPF". do we define this in the configuration in FI?  is there any link with the document number ??
    G

    Hi
    For every document you create the system creates automatically on reference key number and that stores in table 'BKPF' in field 'AWKEY'.
    To see the reference key number  for the document, just goto document display and click on Header Data icon.
    Regards
    Laxmiprasad

  • Remove the primary key constraint and add new primar key to the table.

    Hi all,
    We had a design plan to remove a primary from the table on column X(VARCHAR) and add a new primary key on column Y(sequence)(dimensional table). Instead, I am planning to create a unique index on the column Y (I am referring column Y in my Fact table).
    I am using the column Y while joining the dimensional and fact table. Now, my question is.
    Is the retrieval will be faster if I make column Y as primary key or Is it the performance same if I create a unique index on it ?
    Note: Both column X and Y in dimension table are unique and not null. Don't want to alter the existing system hence want to create unique index .
    Please suggest.
    Thanks and Regards
    Nagaraja Akkivalli

    When you define a column as Primary key column you give certain information to Oracle that i can use when accessing that table. And similarly when you say a column as Unique Key column you give certain details to oracle that i can use when accessing that table.
    So it is up to you to decide if the what that column is meant to do. And decide based on that.
    For example a Unique column can have NULL values. But a primary key cannot have NULL value. This piece of information can be critical to oracle to generate the best plan.

  • Hash keys and the table Pagesize.

    Hi,
    We look to be running into some performance issues running on TimesTen 5.1.25, and feel that we may be running into a problem of having the hash size set too small, as we are seeing lock contention on the index hash values.
    The documentation says that the hash size can only be changed by recreating the table, however the documentation also states, that to resize a hash index, the "ALTER TABLE owner.name SET PAGES = CURRENT;" statement can be used.
    Could you please explain which of these statements is correct, and whether this may be leading to greater lock contention, or whether we should be looking elsewhere.
    Regards,
    mgh

    Yes, an undersized hash index can lead to performance issues and excessive contention. One should always size the index based on the formula PAGES = (maximum number of rows) / 256. The ttXactAdmin utility can be used to investigate lock and latch contention on the hash index. The degree of impact depends on the ratio of actual rows to expected rows. If A is the actual number of rows and H is the number of rows for which the hash index has been sized then the ratio A / H should always be <= 1. If it exceeds 1 by a small amount (e.g. 1.1) then the impact is small but once it exceeds one by a significant amount e.g. 1.5 upwards then the impact increases very quickly.
    In 5.1, the only way to resize the index is by unloading the table data to a file (ttBulkCp), dropping the table, re-creating with the 'correct' hash index sizing and then reloading the data (ttBulkCp).
    The ability to resize the index using ALTER TABLE was introduced in TimesTen 6.0.
    Since this is an obvious and well known source of performance problems and increased contention I would recommend that you try to eliminate this issue in the first instance and see if that improves things. If it does not then you can move on to investigate other areas.
    Chris

  • Primary key in the table

    Hi All,
    Can we have a primary key field declared as INT4  or should we only have the primary key field as character type.
    Thanks in Advance.
    Neha

    Hi,
    Yes, you can have primary key field declared as INT4 .
    Explain me whatz d type of type.
    Regards,
    Muneesh Gitta.

  • Error on activating the table "DB length of the key of table too large"

    Hi Experts,
    I am getting the error while activating my table PSM_REQ_BO_ELM_NAME.  Activation error log is as follows
    "DB length of the key of table PSM_REQ_BO_ELM_NAME is too large (>900)"..
    I have a table which has 4 filed as key one with char 6 and rest 3 with char 120 each.
    Could you please help me to get rid of this error.
    Thanks in advance.
    Regards,
    Pradeep

    When ever we create a table in Data dictionary, a corresponding database table will be created in Data base server. For the primary key we maintained in Data Dictionary, another data base table will be created seperately where as the table length should not exceed some limit set by the Administrator.
    So, Reduce the length of the primary key in the table by deleting the field as key field/ reducing the size of the field.
    In your case, maintain the primary key field length not more than 400.
    ***Length if the Primary key should not exceed 120. other wise performance will be low while fetching the data.

  • The column in the table do not match an existing primary key

    I've got two tables tbl_Workshop and tbl_Material
    tbl_Workshop has columns workshopID, workshopTitle, materialID
    tbl_Material has materialID, name, workshopTitle
    when I'm trying to create a relationship between the workshopTitle of tbl1 and tbl2, it gives me an error that says the column in the table do not match an existing primary key.
    What could be the reason for this error and how to overcome it.
    ps. The datatypes and names of both the table's column match.

    Have you created primary key on workshopTitle column in tbl_Workshop
    You can add foreign key relationship from tbl_Material.workshopTitle
    to tbl_Workshop.workshopTitle
     only if latter is a primary key of the table.
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Fields missing in SM30 after adding new fields to the table

    Hi ABAPers,
    I added a new field & marked another field as primary key in the table. Then I generated the table maintenance view for the table in SE55 and adjusted Database utility SE14.
    When i saw the table in SM30. The number of fields in the overview screen of SM30 shows less field then existing in table. i.e in my table i have 10 fields(3 primary). in SM30 it shows only 5 fields(3 primary + 2 normal fields)
    In SE51, the overview screen of the table show less fields in the field list..
    I want all the fields in the Table maintenance overview screen. Please suggest me a way forward friends..
    Note: the system is 4.0B.
    Thanks...Suresh Kumar

    Hi
    You have to re-generate your dialog for SM30 by table maitenance generator.
    - From Se11 go to table maitenance generator
    - Choose update icon
    - Set flags for NEW FIELD
    - Go to expert
    - Set flag to re-generate dynpro
    Message was edited by: max bianchi

  • Finding the missing number from the table

    I have vendor table with the following column, refvendor_id, the refvendor_id is a primary key in the table. the customer use the application to enter information to the vendor table using an interface
    created in Java. my question is how can I query the refvendor_id numbers that have been skipped by the customer when they enter information to the vendor table.
    refvendor_id is a varchar data type.
    for example
    refvenodr_id
    1
    2
    3
    5
    6
    9
    I would like to capture in my sql the refvendor_id that is skipped here.
    4,7,8
    select refvendor_id
    from  vendor

    I suggest to find the number values with a regular expression.
    Here is a modified version, that will only use the pure number refvendor_ids
    -- Test-Data:
    with vendor as
    select '1' refvendor_id from dual union all
    select '2' refvendor_id from dual union all
    select '3' refvendor_id from dual union all
    select '5' refvendor_id from dual union all
    select '6' refvendor_id from dual union all
    select '9' refvendor_id from dual union all
    select '10'  refvendor_id from dual union all
    select '12'  refvendor_id  from dual union all
    select 'A'  refvendor_id from dual
    -- Query:
    select rownum from dual connect by rownum <= (select max(to_number(refvendor_id)) from vendor where regexp_like(refvendor_id,'^[0-9]+$') )
    minus
    select to_number(refvendor_id) from vendor where regexp_like(refvendor_id,'^[0-9]+$')
    order by 1;(I produce output in number-format, because i want numeric ordering in output)
    Edited by: hm on 14.12.2010 13:32 :
    Of cause you can also use your restrictions, but I can't see if that are really only numbers:
    select rownum from dual connect by rownum <= (select max(to_number(refvendor_id)) from vendor where SUBSTR (refvendor_id, 1, 1) IN ('1', '2', '3', '4', '5', '6', '7', '8', '9') AND LENGTH (refvendor_id) < 5 )
    minus
    select to_number(refvendor_id) from vendor where SUBSTR (refvendor_id, 1, 1) IN ('1', '2', '3', '4', '5', '6', '7', '8', '9') AND LENGTH (refvendor_id) < 5 )
    order by 1;

  • How Do You Display the key in the F4 Value Help

    I have setup a characteristic variable for Ship-To party as a Select Option.
    However when displaying the possible list of entries using the F4 key, the key to the table ie the Customer number is NOT displayed. Instead the search help starts with the medium text description.
    Is there any way of enabling the variable so that the key is displayed.
    Note if a similar variable is setup as a single entry against the same characteristic then the key IS displayed.
    Many thanks

    You have to enable this in the Characteristic.
    In the Query Designer, right click on the characteristic Customer and select the option Display as Key and text.
    If this is already enabled then goto RSA1 and check whether this option is enabled in the Business Explorer tab of  the infoobject
    Regards,
    Rakesh

Maybe you are looking for

  • Regarding sy-uzeit

    My OutPut should be like 12:2900  = hh:mmss i want : column to be inserted between hh and mm in sy-uzeit can any solve this.

  • MEGA 180: A story of stupidity mixed up with bad product design

    This is more for a word of caution to Mega180 users and future owners. A bit angry as I managed to burn ( physically ) 2 harddrives  because of carefulness about 10 mins. Spend quite some time looking for a SATA to ATI power converter while looking f

  • Can I please get a Debug code compiles

    The code below is supposed to use threads to get the checksum of two files chosen for Jfilechoosers and then compare there checksums and tell whether they are equal or not. I have all working but the values for the files individual checksums are not

  • No luck installing Windows XP SP2 on Macbook hal.dll error

    1. I partitioned 45GB with Boot Camp Assistant. 2. Loaded Win XP SP2 CD and started installation. 3. Formatted BOOTCAMP partition on NTFS Quick (Also tried NTFS normal [slow]) 4. After it copies everything to the drive and reboots I get a hal.dll mis

  • Distribution Rule in Incoming Payment of Invoice

    Hello Experts, I'm running SAP B1 8.81 PL05 and I have the following problem. I issue an A/R Invoice + Payment  and I have in the "Payment Means" a discount. The final result is an issue of two different journal entries - one for the invoice and anot