Large table, primary key constraint

I have migrated a table from 8i to 9i that is over 300 million rows. I migrated the the table to a 9i database without constraints or indexes.
I have successfully created a composite index of two columns, t1 varchar2(512), t2 varchar2(32). This index took nearly 16 hours to create.
I am now trying to create a primary key based on that index with the following sql:
alter table table1
add constraint table1_t1_t2_pk primary key(t1,t2)
using index table1_t1_t2_idx
nologging
This process has taken over 24 hours and is well into the second day. Studio reports it will take an additional 15 hours to create.
My questions are these?
1. Is my syntax okay?
2. I thought that by creating a primary key on an existing index, that another index is not being created. I thought it would be faster this way. Why is it taking a lot longer to create then the index it is based upon?
3. Is there a more efficient method (other than parallel query) to create this index/constraint on such a large table? What happens when I go production and need to recreate this index if I have a failure. I have never had to do this before. I can't be down for 48 hours to create an index. What other alternatives do I have?
The table is partit[i]Long postings are being truncated to ~1 kB at this time.

Is INDEX table1_t1_t2_idx UNIQUE? If it's not that might explain why building the primary key constraint takes longer.
I think the USING INDEX clause with an existing index is intended mainly for different UNIQUE constraints to share the same index. In your situation I think you would be better off just building the primary key constraint.
Cheers, APC

Similar Messages

  • Create a materized view without primary key constraint on the base table?

    Hi
    I tried to create a materized view but I got this error:
    SQL> CREATE MATERIALIZED VIEW TABLE1_MV REFRESH FAST
    START WITH
    to_date('04-25-2009 03:00:13','MM-dd-yyyy hh24:mi:ss')
    NEXT
    sysdate + 1
    AS
    select * from TABLE1@remote_db
    SQL> /
    CREATE MATERIALIZED VIEW TABLE1_MV REFRESH FAST
    ERROR at line 1:
    ORA-12014: table 'TABLE1' does not contain a primary key constraint.
    TABLE1 in remote_db doesn't have a primary key constraint. Is there anyway that I can create a materized view on a base table which doesn't have a primary key constraint?
    Thanks
    Liz

    Hi,
    Thanks for your helpful info. I created a materialized view in the source db with rowid:
    SQL> CREATE MATERIALIZED VIEW log on TABLE1 with rowid;
    Materialized view log created.
    Then I created a MV on the target DB:
    CREATE MATERIALIZED VIEW my_schema.TABLE1_MV
    REFRESH FAST
    with rowid
    START WITH
    to_date('04-25-2009 03:00:13','MM-dd-yyyy hh24:mi:ss')
    NEXT
    sysdate + 1
    AS
    select * from TABLE1@remote_db
    SQL> /
    CREATE MATERIALIZED VIEW my_schema.TABLE1_MV
    ERROR at line 1:
    ORA-12018: following error encountered during code generation for
    "my_schema"."TABLE1_MV"
    ORA-00942: table or view does not exist
    TABLE1 exists in remote_db:
    SQL> select count(*) from TABLE1@remote_db;
    COUNT(*)
    9034459
    Any clue what is wrong?
    Thanks
    Liz

  • Can we have more than one primary key constraint to a Oracle Table?

    Hi,
    Can we have more than one primary keys to a single table in oracle? ( Not the composite key)
    Please somebody answer..
    Regards,
    Alaka

    811935 wrote:
    Can we have more than one primary keys to a single table in oracle? ( Not the composite key)
    In principle a table can have multiple keys if you need them. It is a very strong convention that just one of those keys is designated to be "primary" but that's just a convention and it doesn't stop you implementing other keys as well.
    Oracle provides two uniqueness constraints for creating keys: the PRIMARY KEY constraint and the UNIQUE constraint. The PRIMARY KEY constraint can only be used once per table whereas the UNIQUE constraint can be used multiple times. Other than that the PRIMARY KEY and UNIQUE constraints serve the same function (always assuming the column(s) they are applied to are NOT NULL).

  • Primary key constraint for index-organized tables or sorted hash cluster

    We had a few tables dropped without using cascade constraints. Now when we try to recreate the table we get an error message stating that "name already used by an existing constraint". We cannot delete the constraint because it gives us an error "ORA-25188: cannot drop/disable/defer the primary key constraint for index-organized tables or sorted hash cluster" Is there some sort of way around this? What can be done to correct this problem?

    What version of Oracle are you on?
    And have you searched for the constraint to see what it's currently attached to?
    select * from all_constraints where constraint_name = :NAME;

  • ORA-12014: table 'DBA' does not contain a primary key constraint

    Hai
    when implementing basic replication i got the below error.
    ORA-12014: table 'DBA' does not contain a primary key constraint
    I was wondering primary key is enable at remote table
    Any idea about this
    Regards
    mohan
    I am giving below example
    AT master site
    global_names=false in init.ora file
    sql>create table dba(no number primary key);
    table created
    and create snapshot log
    sql>create snapshot log on m1;
    materilized view created
    AT SNAPSHOT SITE
    1.Create service using net8 stiring name like n1
    2.create database link
    sql>create public database link m3 connect to system identified by manager using 'n1';
    Database link created.
    3.when creating snapshot site i got below error
    SQL> create snapshot snap1 refresh fast start with sysdate next sysdate+1/(24*60
    *60) as select * from dba@m3;
    create snapshot snap1 refresh fast start with sysdate next sysdate+1/(24*60*60)
    as select * from dba@m3
    ERROR at line 1:
    ORA-12014: table 'DBA' does not contain a primary key constraint

    Hello,
    Please repost this question in the appropriate section of the Discussion Forum.
    This forum is for general suggestions and feedback about the OTN site.
    You can also use our new offering called OTN Service Network:
    For Oracle Advice/Minimal Support (fee based) on the Oracle Database Server, Oracle9i Application Server Containers for J2EE (OC4J), Oracle9i JDeveloper, Reports, Forums, SQL*Plus, and PL/SQL, please go to: http://www.oracle.com/go/?&Src=912386&Act=45
    For customers with paid support (Metalink) please go to:
    http://www.oracle.com/support/metalink
    Regards,
    OTN

  • ORA-12014 table does not contain a primary key constraint

    Hi
    I have some existing Materialised Views I am trying to redeploy through OWB as its now our standard tool.
    The existing code has
    CREATE MATERIALIZED VIEW .......
    .REFRESH ON DEMAND WITH ROWID AS
    SELECT *
    FROM apps.fafg_assets
    When I create in OWB you only put the select statement, there is nowhere to put the 'with rowid ' part hence I get the following error on deployment;
    ORA-12014: table 'FAFG_ASSETS' does not contain a primary key constraint
    I cannot put a primary key on this table though so how do I get around this in OWB? Like I say writing the MV in PL/SQL putting the 'with rowid' bit makes it work?
    Thanks

    Hi...
    I believe you'll need a PK so Oracle will know how to update the MV. Is there any particular reason for you not having a PK in FAFG_ASSETS table? As an alternative, you may want to create a new column in this table and having a table trigger/sequence populating this column.
    But It looks like you are using EBS, so, I don't know if you can add new columns to tables.
    See if this thread can help you:
    Re: ORA-12014: table 'XXX' does not contain a primary key constraint
    Regards,
    Marcos

  • How add primary key constraint to already existing table with data

    I want apply primary key constraint to already existing table with data
    is there any command or way to do

    Alternatively, assuming you want to ensure uniqueness in your primary key column you can do this:
    alter table <table name> add constraint <cons name> primary key (col1,col2) exceptions into <exception_table>
    If the altter table statement fails this will populate the EXCEPTIONS table with the rows that contain duplicate values for (col1,col2).
    You will need to run (or get a DBA to run) a script called UTLEXCPT.SQL (which will be in the $ORACLE_HOME/rdbms/admin directory) if you don't already have an EXCEPTIONS table.
    Cheers, APC

  • Altering Primary Key constraint on a table i Oracle 10G

    Hi All,
    Can anyone tell me how to alter a primary key constraint on any table. My concern is that, suppose i have a table called 'Employee' where only 'EmployeeName' is added as a primary ket constaint. Now i want to alter this P.K. constarint to add 'EmployeeName' and 'DateOfBirth' as a primary key. Can anyone suggest me how can i achieve that? Any help will be highly appreciated.

    hi,
    you need to drop the constraint and recreate it.
    SQL> conn scott/tiger@alpspso
    Connected.
    SQL> create table test (id number constraint id_pk primary key,name varchar(30));
    create table test (id number constraint id_pk primary key,name varchar(30))
    ERROR at line 1:
    ORA-00955: name is already used by an existing object
    SQL> create table test_table (id number constraint id_pk primary key,name varchar(30))
    Table created.
    SQL> alter table test_table modify constraint id_pk primary key(id,name);
    alter table test_table modify constraint id_pk primary key(id,name)
    ERROR at line 1:
    ORA-00933: SQL command not properly ended
    SQL> alter table test_table modify constraint id_pk(id,name);
    alter table test_table modify constraint id_pk(id,name)
    ERROR at line 1:
    ORA-00933: SQL command not properly ended
    SQL> alter table test_table modify primary key(id,name);
    alter table test_table modify primary key(id,name)
    ERROR at line 1:
    ORA-00933: SQL command not properly ended
    SQL> alter table drop constraint id_pk;
    alter table drop constraint id_pk
    ERROR at line 1:
    ORA-00903: invalid table name
    SQL> alter table test_table drop constraint id_pk;
    Table altered.
    SQL> alter table test_table add constraint id_pk primary_key(id,name);
    alter table test_table add constraint id_pk primary_key(id,name)
    ERROR at line 1:
    ORA-00902: invalid datatype
    SQL> alter table test_table add constraint id_pk primary key(id,name);
    Table altered.
    Regards.
    Navneet

  • Alter primary key constraint - efficient way

    Please let me know the efficient way to alter the primary key constraint in a table(it has millions of records).
    Thanks.

    Do you want to have a NCI on PK instead of CI? You have to drop a constraint.. You know , a  constraint is a logical component  but the index (unique) that SQL Server creates behind the scene is a physical implementation...
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Getting error message when passing data into table: Primary Key

    Getting an error in a process that is feeding the invoice creation in SAP, violation of PRIMARY KEY constraint 'INV1_Primary', cannot insert duplicate key in object 'INV1'. I assume this is due to duplicate key values being passed into the table INV1, however I get this error even when I am passing unique record combinations of the key fields docentry and linenum. This is on 2005A SP01.
    Thanks

    Hi Peter,
    Could you provide a code sample of the routine that is causing the error please?
    It sounds like a data corruption issue (though it could possibly be a bug in the DI API). I recommend you speak to SAP support. There is a utility that can validate the document numbering but you'll need to speak to SAP support before you run this as it can have other negative effects, depending on the state of your data. They may ask for a copy of your database to test.
    Kind Regards,
    Owen

  • Materialized View - does not contain a primary key constraint

    I am trying to create materialized view. I gone through the MV wizard creation. Added 2 columns (foo_column, foo_pk) of the table and have a simple select statement (Select foo_column from foo_dim). Also created a primary key contrainst and refencing the primary key (FOO_PK) of the dimension.
    I am getting the following error:
    ORA-12014: table 'FOO_DIM' does not contain a primary key constraint

    It was solved. The table that I am querying has to have a primary key defined before creating a materialized view.

  • Primary key constraint firing when there's no need

    Hi All,
    I've got a very weird problem.
    I've written a PL/SQL procedure to insert addresses into a tabel. The adresses are assigned an unique number by means of a sequence. This unique number is the primary key of the table and has to be unique.
    The following thing occurs: The primary key constraint fires whenever i try to insert a record and i can't figure out why.
    I use the following code
    PROCEDURE mk_adr(klant NUMBER, receiver NUMBER) IS
    oidtje NUMBER DEFAULT 0;
    BEGIN
    BEGIN
    SELECT lea_adr_seq.NEXTVAL INTO oidtje
    FROM dual
    INSERT INTO lea_adr (
    oid, object, streetname,
    housenumber, housealpha, ponumber,
    postcode, cityname, locationdesc,
    province, kind, country_id,
    relation_id, offerrec_id,
    h_trans_van,
    h_geldig_van,
    h_gebruiker
    SELECT oidtje, oidtje, streetname,
    housenumber, housealpha, ponumber,
    postcode, cityname, locationdesc,
    province, kind, country_id,
    null, receiver,
    To_Date('01-01-2000'),
    To_Date('01-01-2000'),
    'conv'
    FROM lea_adr
    WHERE relation_id = klant
    EXCEPTION
    WHEN Others THEN
    conv_algemeen.debugMessage('mk_adr :: '||SQLERRM);
    END;
    END;
    as you can see the very first thing i'm doing is selecting a new unique number into oidtje from the sequence which provides the numbers. Then i use it to insert the record. The insert fails with the primary key constraint firing saying that oid is not filled with an unique number.
    When i do "select max(oid) from lea_adr;" I get a number lower than the number the i get when doing "select lea_adr_seq.nextval from dual;"
    So am i overseeing something or is something very obvious going wrong ?
    Patrick

    Write your procedure like the following and it will work.
    PROCEDURE mk_adr(klant NUMBER, receiver NUMBER) IS
    BEGIN
    INSERT INTO lea_adr (
    oid, object, streetname,
    housenumber, housealpha, ponumber,
    postcode, cityname, locationdesc,
    province, kind, country_id,
    relation_id, offerrec_id,
    h_trans_van,
    h_geldig_van,
    h_gebruiker
    SELECT lea_adr_seq.NEXTVAL, lea_adr_seq.NEXTVAL, streetname,
    housenumber, housealpha, ponumber,
    postcode, cityname, locationdesc,
    province, kind, country_id,
    null, receiver,
    To_Date('01-01-2000'),
    To_Date('01-01-2000'),
    'conv'
    FROM lea_adr
    WHERE relation_id = klant
    EXCEPTION
    WHEN Others THEN
    conv_algemeen.debugMessage('mk_adr :: '||SQLERRM);
    END;
    Using the lea_adr_seq.NEXTVAL more then once in the SAME select will return the same value for both calls.
    SQL> create sequence test
    2 ;
    Sequence created.
    SQL> select test.nextval,test.nextval from dual;
    NEXTVAL NEXTVAL
    1 1
    SQL>

  • Unable to enforce Primary Key constraint with my code

    Hi Guys
    I have a table that contains 2 columns: code and description (defined as not null). I am using oracle forms 10g, if I inset a new row both the columns: code and description should have data e.g. code: 001 and description: Main Store...
    So on forms I have an on-update trigger on block level that handles the error messages but if the user has to update the description this trigger blocks him because the value for the code i.e. 001 is already on the database but if I remove the piece of code (the first IF block on my code together with a cursor and the entire declaration section)then the primary key constraint is violated: the code is as follows:
    declare
    v_store_code store_types.code%type;
    cursor store_codes is
    select a.code
    from store_types a
    where a.code = :b1.code;
    begin
    open store_codes;
    fetch store_codes into v_store_code;
    if ( store_codes%found ) then
    Message('The Store Code you have entered already exists on the Store_Types table, please enter another code!');
    Message('The Store Code you have entered already exists on the Store_Types table, please enter another code!');
    close store_codes;
    raise form_trigger_failure;
    end if;
    close store_codes;
    if :b1.code is not null and :b1.description is null then
         message('If the Store Code has been captured, then the Store Description must be captured!');
         message('If the Store Code has been captured, then the Store Description must be captured!');
    raise form_trigger_failure;
    end if;
    if :b1.description is not null and :b1.code is null then
         message('If the Store Description has been captured, then the Store code must be captured!');
         message('If the Store Description has been captured, then the Store code must be captured!');
         raise form_trigger_failure;
    end if;
    exception
              when others then
                   message(sqlerrm);
                   raise form_trigger_failure;
    end;
    My main intention here is: the user should be able to update the description field and save the changes without violating primary key on the column: code ...... please help me guys...

    ICM
    Sir as far I could understand , your problem is that your wanna allow the end users to update the Store_description , and Store_code..
    So on forms I have an on-update trigger on block level that handles the error messages but if the user has to update the description this trigger blocks him because the value for the code i.e. 001 is already on the databaseif it's right then why don't you have unique key constraints Store_description?
    alter the tables and apply unique key constraint...
    and no need to write this code
    f :b1.code is not null and :b1.description is null then
    message('If the Store Code has been captured, then the Store Description must be captured!');
    message('If the Store Code has been captured, then the Store Description must be captured!');
    raise form_trigger_failure;
    end if;because as you mentioned
    code and description (defined as not null)if they are already under not null constraints then no need to handle this in coding..
    he/she must be able to change the description and save the changes without affecting the code i.e.:Sir I think updation in records can only be performed when the forms is in query mode e.g execute query, have all/desired records and then make changes
    (1)description is in unique key constraint it can't be duplicated ..
    (2)code is PK it can never be duplicated...
    for this I would suggest you to have a update button on forms , when-button-pressed trigger sets property of block (update_allowed, property_true);
    and check the code of unique key violation code from oracle form's help , when that error code raise up you can show those message
    Message('The Store Code you have entered already exists on the Store_Types table, please enter another code!');
    Message('The Store Code you have entered already exists on the Store_Types table, please enter another code!');I hope it could do something for you
    thanks
    regards:
    usman noshahi

  • IDOC to MSsql,  error in mapping(Violation of PRIMARY KEY constraint)

    Hi All,
    I'm working with MATMAS IDOC  to MSSql. My SQL structure is of 8 tables(multiple statements) with primary key. In mapping i have used UPDATE_INSERT in action field for all the tables but still im getting "Violation of PRIMARY KEY constraint" for the last table structure. first 7 tables are single occurances but the 8th structure data is coming multple times from IDOC(E1MARMM).
    my 8th table structure is :
    STATEMENT8                                IDOC(MAPPED)
    TABLE8
    ACTION                                      UPDATE_INSERT
    TABLE                                           TABLENAME
    ACCESS     0 to Unbounded            MAPPED with E1MARMM
    Item_CD                                used oneasmany +splitbyvalue with MATNR
    Plant_ID                                  used oneasmany +splitbyvalue with WERKS  
    EAN_CAT                                 used oneasmany +splitbyvalue with NUMTP
    EAN                                             used oneasmany +splitbyvalue with EAN11
    Numerator_For_Conversion_To_BaseUOM
    Display_UOM
    Denominator_for_conversion_To_baseUOM
    KEY           0 to Unbounded                 MAPPED with E1MARMM
    Item_CD                                used oneasmany +splitbyvalue with MATNR
    Plant_ID                                  used oneasmany +splitbyvalue with WERKS  
    EAN_CAT                                 used oneasmany +splitbyvalue with NUMTP
    EAN                                             used oneasmany +splitbyvalue with EAN11
    Display_UOM
    in test tab its fine and fetching number of times according to MARMM segments  but in END to END testing its triggering an error stating that
    ""Message processing failed. Cause: com.sap.engine.interfaces.messaging.api.exception.MessagingException: Error processing request in sax parser: Error when executing statement for table/stored proc. 'MM_EAN' (structure 'STATEMENT8'): com.microsoft.sqlserver.jdbc.SQLServerException: Violation of PRIMARY KEY constraint 'PK_MM_EAN'. Cannot insert duplicate key in object 'dbo.MM_EAN'.  ""
    Plz help me regarding this..

    Hi team,
    How resolve the below error 
    Violation of PRIMARY KEY constraint 'PK_test'. Cannot insert duplicate key in object 'dbo.test'. The duplicate key value is (12610). (Source: MSSQLServer, Error number: 2627) ?
    Thanks,
    Ram
    RAM
    There can be two reasons
    1. The insert script used is having multiple instances of the records with Key as 12610 returned from the source query. If this is the issue add a logic to include only the unique set of id values for records by avoiding duplicates. There are several approaches
    for this like using ROW_NUMBER with PARTITION BY, using a join with derived table etc
    2. The record with Key 12610 already exist in your destination table and your script is again trying to insert another instances of record with same key. This can be avoided by adding a NOT EXISTS condition with a subquery which will check and return only
    those records which doesnt already exist in the source
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • [SQL Server]Violation of PRIMARY KEY constraint 'DeploymentSummary_PK'. Cannot insert duplicate key in object 'dbo.DeploymentSummary'. The duplicate key value is

    I have migrated my SCCm 2007 environment to SCCM 2012 SP1 CU4.
    I noticed in the System Status\Component Status\SMS_STATE_SYSTEM a lot of errors like the one below:
    Microsoft SQL Server reported SQL message 2627, severity 14: [23000][2627][Microsoft][SQL Server Native Client 11.0][SQL Server]Violation of PRIMARY KEY constraint 'DeploymentSummary_PK'. Cannot insert duplicate key in object 'dbo.DeploymentSummary'. The duplicate key value is (1, 0, S0220438, 0). : spUpdateClassi
    Please refer to your Configuration Manager documentation, SQL Server documentation, or the Microsoft Knowledge Base for further troubleshooting information.
    When looking up the deployment ID and recreate the Deployment the problem is solved. But I have 700 packages and don't want to manually do this action on all packages. I think it is related to the migration i did and something went wrong there :-(
    Besides it will retriggers the deployment to the clients which is also not preferred.
    Is there another way to solve this by e.e.g do something directly in the SQL database tables ?

    Hi,
    It is not supported by Microsoft that do something directly in SQL database.
    If you want to do that, you could make a call to CSS.
    Best Regards,
    Joyce
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

Maybe you are looking for

  • Only can see controls when dropping quicktime

    Never had this problem before. All of a sudden I cannot see the movie I drop into the template, only the movies controls. When published, the movie is there. Help? Thank you very much. Best, Tom

  • Using BT vision in a second location

    I have two BT internet accounts at separate locations. I have BT vision on one account for one property, and both properties have BT phone and internet from the same online BT account and pay both the bills. Am I able to take the BT vision box from t

  • New macbook pro 15 screen issue (blue-ish)

    hi just got a brand new mbp from apple store...got it friday everything is great but the screen is slightly on the blue tint side i tried the calibration but it only makes it worse i also downloaded all the updates from apple i'm going to an apple st

  • Changing Oracle Apps. host name

    Hi, I would like to know if it is possible to change a hostname of an Oracle Applications server (11.5.9 / 11.5.10). If so, what is the procedure? Thank you, Yaniv

  • Automatic calculation of numeric value enter in Survey

    while creating Survey in Survey Suit we enetr numeric value in field . my requirement is that can we do automatic calculation of these numeric values in Survey its self Regards, Anup Reche 9268133864