Making existing fields part of primary key

Hi,
There is a Z table(custom table), which has 3000 records. There are 12 fields in the table out of which 6 of them form the primary key. I need to make 2 more fields in the table part of primary key.
Is that possible? Will it affect the existing data in the table?
Please explain the possible ways of doing it.
Points will be given to all the helful answers.
Thanks- Nobin

Hi,
There can never be a possibility of Data issues. If a record in a table becomes unique by just the 6 fields , then the existing data will remain unique even if you add 2 more fields in the key.
Data issues can only come if you are reducing the key fields.
Take an example of a table with 2 fields and the data as show below
A1  B1
A1  B2
A2  B1
A2  B2 
Now in this case if you reduce the key fields and make the first column only as the key then there can be issues as the there will be multiple rows with the same key.
In case you increase the key fields , then since the data was unique, the data will remain unique now also.
A1 B1 C1
A1 B2 C1
A2 B1 C1
A2 B2 C1
Regards,
Aj

Similar Messages

  • Use of end-date as part of Primary key in SAP Tables

    All,
    Any ideas on the rationale behind SAPs use of end-date as part of Primary key in general, specifically on condition Tables(A9xx for example) instead of Start-date? appreciate any help!!
    Best Regards
    TRP

    Hmm, another example is CSKS, this logic was probably designed already in the 1980s...maybe it was seen beneficial to be able to select the currently valid record by using the primary key only (the first record where DATBI is larger than system date, not possible when DATAB is the key instead).
    Maybe there are better explanations. Why do you need to know this, just curious?
    Thomas

  • Null Field in Composite Primary Key

    Can you have a column be part of a primary key and be nullable?
    I have a table of three fields and I want them all to be part of a primary key, because I need all three columns to reference a unique row. However, one of the fields references a field in another table which can be null. Is there anyway I can achieve this?

    Any columns included in the primary key will be converted to not NULLable as necessary, so, no, you cannot have a NULLable column as part of a primary key.
    You can, however, create a unique constraint that includes a NULLable column as part of the composite key.

  • Foreign key as part of primary key - bad idea

    What are the pros and cons of using the primary key of the parent table as part of the primary key in the child tables versus just having it as a foreign key in the child tables?
    Please share your experience on this. Thanks in advance.
    Regards,
    Richard

    sb92075 wrote:
    but if the relacion is 0-1 to 1-1 ; better design 2 tablesWhy?
    Blank columns require no special accommodation.Like most things, there's usually a case (even if it's a small subset of all possible cases) where this makes sense.
    http://www.oracle.com/technology/oramag/oracle/09-mar/o29asktom.html “Wide Load Storage”
    Would be one such case.

  • How to specify multiple sequence for multiple fields in a primary key!

    Hi,
    i have a table which has about 15 fields, one of the field is primary key and i am able to specify the sequence for it using toplink and when the object is created through toplink the sequence get generated automatically, which is fine.
    Now i have to add another sequence generated field to the table this field is not nullable and
    i am looking for a way in toplink to specify the sequence for this field too, so that when we create objects through toplink the value for the field is automatically generated instead of us fetching the next value from sequence using a sql statement and then using the set method for the field.
    is there a way i can specify a sequence for another field through toplink, while keeping the sequence settings for the primary field untouched.
    thanks for your help!
    -

    TopLink only supports a single sequence field in its' mappings. There should be an API you can use to get another sequence number from an event, but I could not find an easy one (please log a bug for this on EclipseLink). The following code might work if you define the other sequence in TopLink, but you could also just execute the raw SQL as you are doing.
    i.e. something like,
    preInsert(DescriptorEvent event) {
    MyObject object = (MyObject) event.getObject();
    object.setOtherId(event.getSession().getDatasourcePlatform().getSequence("MY_OTHER_SEQ").getGeneratedValue(event.getSession().getAccessor(), event.getSession()));
    -- James : http://www.eclipselink.org

  • Adding 2 new fields as Primary Key field in a Z Table which is existing PRD

    Hi Friends,
    I have to add two new fields as primary key fields in a Z TABLE, which is existing in Quality and Production Systems with Data.
    If I incorporate these two new fields (Primary Key fields) in development and if the TR is moved to Quality and Production sytems, is there any possibility of loss in data will happen at Quality and Prd systems?
    At present, Table is having 20 fields with 2 primary key fields and i have to add 2 more primary key fields.
    I have checked in SCN and not find relevant threads.
    Please help me out.
    Regards,
    Suresh.

    NO . It wont be a problem .
    For ex :
    If you have VBELN  , POSNR are key fields now , you have an unique reord with that combination .
    If you add one other field in it  fo ex  VKBUR  then records will be like this
    VBELN     POSNR     VKBUR   MATERIAL   QTY
    10020      10                            abcxyz      1
    10020      10            1234        abcxyz     1
    So your previous records before adding new primary keys , will have new fields balnk , and the new records will have data filled up in all primary key fields .
    However , if you try to update the existing records that will be in existing PRIMARYKEY combination only .
    for example if you try update record 1 above with VKBUR value 85858 , it creates a new record , it wont be updated in existing record.
    Hope this helps , Pls let me know if u have any more doubts.

  • Overwriting a record with part of same primary key

    Hello Everyone,
    Could anyone please give a suggestion about how to overwrite the record with part of same primary key?
    I have  5 key fields.
    A1
    A2
    A3
    A4
    A5
    I have to overwrite the record if A5 changes with same A1 A2 A3 A4.
    I cannot take off A5 as part of primary key. If I use modify or insert, its creating a new record with the new A5. But I am still having the old record in the table (with old A5), which I don't want it to be there.
    Thank you,
    Rushi

    hi,
    That's right.
    u have to delete record from database table .....
    then u can add a new record...
    use delete <database_table> from table <internal_table>

  • Comp. Primary key class-field mapping to DB columns problem.(EJB 2.0 CMP)

    Hi!
    I have deal with EJB 2.0 CMP bean.
    I have a composite PK so use the java class to store it. And there is a corresponding field in the Entity Bean with its primary key class type.
    The problem is: when deployment tool creates sql query for the findByPrimaryKey(PKClass ck)
    where ck is an object with 3 fielde : a_id, b_id, c_id.
    it says:
    <sql>SELECT "ck" FROM "MyTable" WHERE "ck" = ? </sql>
    And it means by the "ck" simple a column in DB but NOT the composite key which has to be splited into 3 different fields. So the container can't do the proper mapping.
    Does anyone know solutions?

    I was wrong about primary key class fields, take a look at Ejb2.0 Specification (10.8.2):
    The primary key class must be public, and must have a public constructor with no parameters.
    All fields in the primary key class must be declared as public.
    The names of the fields in the primary key class must be a subset of the names of the container-managed
    fields. (This allows the container to extract the primary key fields from an instance�s container-managed
    fields, and vice versa.)
    Right now I'm using BMP and I don't have this problems. Primary keys, calculated fields and types not supported by the DB can be easily achieved. But I understand your interest on CMP, is clearly evolving!

  • Utilizing auto-increment/identity fields for primary key with "application" identity

    Is it possible to utilise an auto-increment (identity in MS SQL Server)
    field for the primary key field when using "application" identity?

    To the best of my knowledge, you cannot use auto-increment. Due to the
    differences in the way that identities are generated at the datastore
    (upon insert) vs. JDO (upon makePersistent), this feature of SQLServer is
    not supported yet.
    However, we do provide a variety of other ways of generating identity
    which may provide a closer fit to what you want, and
    our users may have some experience in solving your problem.
    On Tue, 28 Jan 2003 09:56:08 +0000, Sean Ryan wrote:
    Is it possible to utilise an auto-increment (identity in MS SQL Server)
    field for the primary key field when using "application" identity?--
    Stephen Kim
    [email protected]
    SolarMetric, Inc.
    http://www.solarmetric.com

  • Using CMR field as Primary Key in Entity Bean

    Hi, all!
    Can somebody tell me, is it possible to use CMR field as Primary Key field in Entity Bean?
    Thanks

    WebLogic Server supports mapping a cmr field to the primary key.

  • Null value in detail table's primary key

    I use Business Components Data Form to define a master-detail java panel.
    I don't display the primary key column in the detail grid control.
    Then I click on "+" to add a row, enter a value (the 2nd part of the detail table's primary key) and click commit.
    I get an error saying that the primary key column that's not displayed is null and the row cann't be committed.
    How do I fix this error?

    My fields are varchar2's.
    -- simplified to protect the guilty:
    -- (made up from memory, so sql keywords may --be misspelled, but you get the idea)
    create table proj (
    proj varchar2(10) not null,
    constraint proj_pk
    primary key(proj)
    insert into proj values ('abc');
    commit;
    -- this table has legal values for -- the master.legal field.
    -- in master, legal was changed to a -- ComboBoxControl control from -- TextFieldControl that the wizard -- generated.
    create table legal_values (
    proj varchar2(10) not null,
    legal varchar2(10) not null,
    display_order integer not null,
    constraint legal_values_pk
    primary key (proj, legal)
    insert into legal_values
    values ('abc', 'one', 1);
    insert into legal_values
    values ('abc', 'two', 2);
    insert into legal_values
    values ('abc', 'three', 3);
    commit;
    create table master (
    proj varchar2(10) not null,
    masterKey varchar2(15) not null,
    legal varchar2(10) not null,
    constraint master_pk
    primary key (proj, masterKey)
    create table detail (
    proj varchar(10) not null,
    masterKey varchar(15) not null,
    detailkey varchar(10) not null,
    display_order integer not null,
    status varchar2(12) not null, -- user can only update this field
    constraint detail_pk
    primary key(proj, masterkey, detailkey)
    -- legal rows for detail table
    create table detail_values (
    proj varchar2(10) not null,
    detailkey varchar2(10) not null,
    display_order integer not null,
    constraint detail_values_pk
    primary key(proj, detailkey)
    insert into detail_values values
    ('abc', 'status a', 1);
    insert into detail_values values
    ('abc', 'status b', 2);
    commit;
    -- if their is a foriegn key on details back
    -- to master, then you get the
    -- "mutating table" error when trigger
    -- occurs.
    create or replace trigger master_tr
    after insert on master
    for each row
    begin
    insert into detail
    (masterKey, detailKey, status, display_order, status)
    select :new.masterkey, detail_key, display_order, ' '
    from detail_values;
    end;
    -- detail.status is a comboboxControl getting --its values of of another db table too.
    -- there's also "after update" triggers on master and detail tables that copy the record to master_history and "detail_history" tables if the corresponding table is modified. Thus we have a history of the changes made to the records. The 2 history tables have 2 additional fields than their parents, "modified_date date default sysdate not null" and "modified_by varchar2(30) default user not null" that record when and who made the change. There's also a change type field that records where the change is an insert, delete or update (there 3 triggers per table , so we can correctly record change type as being insert, delete or update into the change_type field).
    If you want to make it more real to life, the status value is initially blank, then can be changed to a legal status value (complete or not complete), but can not be changed back to blank.
    ***P.S. I have to have this ready for production by monday.****
    P.P.S After you reply and change to ComboBoxControls in 2 places, try changing the table names and/or the column names (say to follow the DBA's naming convention) or add another field to the composite primary key (and unstated foriegn key) (using drop table/create table). Now try getting the existing code to run. No writing down the old/new table (or column) name pair names. Just run the code and try to fix the code based on the error messages. Are the error messages giving you adequate information to find the problem?

  • Help.......... required :Database table with no primary key

    Hi All,
    I have a table sponsor_logos whose structure is as follows:
    sl__sponsorid number,
    sl__clubid number,
    sl_hallno varchar2(7) not null,
    sl_logofilename varchar2(100) not null,
    sl_date_modified date not null
    Where in the sl__sponsorid and sl__clubid are foreign keys and I do not have any primary key for the table.
    I need to insert into and also delete records from the table.
    I have gone through various topics in the java forum for EJB's to find out what design strategy should I use?
    Some say that if a table does not have primary keys, and if the table is represented by a CMP entity bean all the fields of the table are considered as a part of primary key.In that case what would my code look like and what would my deployment descriptor contain?????
    According to the specification, the CMP or a BMP represents a unique record in a database.In that case should I be using a Session bean to handle insertions and deletions for the table?
    Since this is my first project with EJB's I am really confused as to what design should I be using for this situation. Since I have a time constraint I can't take a long time to decide on what strategy I should use.
    Suggestions regarding this are welcome .

    Hi Maris,
    I have my PK class ready with all the fields in it.
    Deployment descriptor ready with <prim-key-class>package.SponsorLogoPK</prim-key-class>
    . According to descriptor specification there is no need to have an entry for
    <primkey-field>bookingSlNo</primkey-field>
    in case of custom primary key .
    So I have omitted <primkey-field>bookingSlNo</primkey-field>
    I have used the verifier tool and verified the ejb , no errors with regards to this ejb, but , getting errors while deploying:
    An error has occurred.
    Deployment Error -- Error while running ejbc -- Fatal Error from EJB Compiler -- JDO74025: JDOCodeGenerator: Caught an Exception validating CMP bean 'SponsorLogoBean' in application 'resnet_ejb' module 'E:\Sun\AppServer\domains\domain1\applications\j2ee-modules\resnet': JDO72335: If the table SPONSOR_LOGOS for the bean corresponding to the generated class com.resnet.squash.api.entity.SponsorLogoBean483209734_JDOState is mapped as the primary table, it must have a primary key. Choose a different primary table or verify that the contents of the schema file are correct.
    Now what could the problem be . Do I need to do any other setting in the descriptor. I have the cmp-mapping also intact.

  • Change primary key in ztable

    Hello everyone
    I need some advice.
    I have transp. table ZINVOICE which have data in production system.
    field  of table are
    VBELN  Primary key
    KUNNR
    NAME
    FKART
    FKDAT
    NETWR
    STAT
    TAXINVNUM
    ZFKDAT
    ZNETWR
    now i want table ZINVOICE have 2 primary (VBELN + TAXINVNUM)
    when i activate system show
    Key is already defined; field TAXINVNUM cannot be in the key
    Message no. AD434
    Diagnosis
    When defining table fields, you added further key fields at the end after entering a block of key fields followed by a block of non-key fields.
    All the key fields of a table must be in a block at the beginning of the table.
    Procedure
    All key fields in a table should be entered in a single block.
    is it mean that primay key must be in beginning of the table ?
    can i delete field in table ZINVOICE and insert field and change position of fields to
    VBELN  Primary key
    TAXINVNUM Primary key
    KUNNR
    NAME
    FKART
    FKDAT
    NETWR
    STAT
    ZFKDAT
    ZNETWR
    can i do like this ?
    is it impact my existing data in SAP ?
    please advice.

    As you are adding a new key, you should not get problem with duplicate records.
    You should create two transport requests and activate/transport the table twice.
    - In the first request, change the order of fields in the database table, don't add primary key now, activate , if required adjust database table (should not be required), transport database table in target system.
    - In the second request, declare the second field as a primary key, proceed same way.
    DON'T TRANSPORT BOTH REQUESTS TOGETHER
    First step
    VBELN K
    TAXINVNUM
    KUNNR
    NAME
    Second step
    VBELN K
    TAXINVNUM K
    KUNNR
    NAME
    Question: Did you forget to add the client field, if yes you will have to adjust the table and the records will be copied in every client, you will have to create and execute a small cleanup program
    Third step
    MANDT K
    VBELN K
    TAXINVNUM K
    KUNNR
    NAME
    Regards,
    Raymond

  • Primary key  & foriegn key

    can i create more than one primary key in database table..?what is the function of primary key compare to foriegn key

    Hi
    Primary Key:
    it is useful to uniquely identify the rows in a table by one or more columns so that you can process them in a specified sequence, for example. You can do this by assigning a “primary key.” The column names that are to create the table key are represented by the keywords PRIMARY KEY. The input values of the key columns defined in this way must not be a NULL value.
    You can use the primary key to insert rows in a table in the same way as you insert rows in a base table when no primary key is defined. However, the system outputs an error message if you attempt to insert an existing value into the primary key column a second time, since the uniqueness of the column is ensured by defining the primary key.
    A primary key can consist of multiple columns. However, it is unusual for a key to be constructed from more than five columns, since this makes it difficult for users to enter unique values. The arrangement of the columns behind the keywords PRIMARY KEY defines the key sequence.
    Foreign Keys :
    You can define the relationships between tables in the ABAP Dictionary by creating foreign keys.
    Using foreign keys, you can easily create value checks for input fields. Foreign keys can also be used to link several tables in a  view or a  lock object.
    Reward Points if useful

  • Update primary key/delete and reinsert records

    Hi, I have been told to update some fields. The database is new to me, and now I see the field is the primary key (and it has child tables with that as foreign key). The person who told me isn't reachable until next week...
    ...wasn't a bad idea to update pk's? I see it's possible, deferring constraints...
    update primary key
    Re: Update Primary Key
    ...but it's better/safer the script deletes and later re-insert the records, right?
    Thanks

    Always is better be able to undo any change .
    But ¡, why would you update pk's? it's possible but you colud find few problems like:
    - many levels of foreign keys exists.
    - not validate pk
    Look at:
    Re: Novalidate primary key

Maybe you are looking for