Creation of primary keys, foreign keys and indexes

Hello

I created 60 new tables based on 60 existing tables.

The 60 current tables are named FY11_ACC1, FY11_ACC2, FY11_SALES1, FY11_SALES2..., but all of the 60 tables start with FY11. I created the same structured tables but with names like FY12_ACC1, FY12_ACC2, FY12_SALES1, FY12_SALES2 FY12...

I used the below SQL and generated SQL code.

Select 'create table ' | Replace (table_name, 11, 12).
' in select * from '. table_name | "where 1 = 0'.
from user_tables;

But this did not generate the PRIMARY KEYS, FOREIGN KEYS and INDEXES. How can I automatically or with similar like SQL above? _

Thanks for your time and your help.







How can I create primary keys, foreign keys and indexes for all

ssk1974 wrote:
Can you please provide me with more information or examples.

Something like:

SET SERVEROUTPUT ON FORMAT WORD
DECLARE
    h   NUMBER;
    th  NUMBER;
    ddl CLOB;
BEGIN
    h := DBMS_METADATA.OPEN('TABLE_EXPORT');
    DBMS_METADATA.SET_FILTER(h,'SCHEMA','SCOTT');
    DBMS_METADATA.SET_FILTER(h,'NAME','DEPT');
    DBMS_METADATA.SET_FILTER(h,'EXCLUDE_PATH_EXPR','=''TABLE_DATA''');
    DBMS_METADATA.SET_FILTER(h,'EXCLUDE_PATH_EXPR','=''STATISTICS''');
    th := DBMS_METADATA.ADD_TRANSFORM(h,'DDL');
    DBMS_METADATA.SET_TRANSFORM_PARAM(th,'PRETTY',false);
    DBMS_METADATA.SET_TRANSFORM_PARAM(th,'SQLTERMINATOR',true);
    LOOP
      ddl := DBMS_METADATA.FETCH_CLOB(h);
      EXIT WHEN DDL IS NULL;
      DBMS_OUTPUT.PUT_LINE (ddl);
    END LOOP;
    DBMS_METADATA.CLOSE(h);
END;
/

  CREATE TABLE "SCOTT"."DEPT" ("DEPTNO" NUMBER(2,0), "DNAME" VARCHAR2(14),
"LOC" VARCHAR2(13),  CONSTRAINT "PK_DEPT" PRIMARY KEY ("DEPTNO") USING INDEX
PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS  STORAGE(INITIAL 65536
NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1
FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE
DEFAULT) TABLESPACE "USERS"  ENABLE) SEGMENT CREATION IMMEDIATE PCTFREE 10
PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE(INITIAL 65536 NEXT
1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST
GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "USERS" ;

  CREATE UNIQUE INDEX "SCOTT"."PK_DEPT" ON "SCOTT"."DEPT" ("DEPTNO") PCTFREE 10
INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS  STORAGE(INITIAL 65536 NEXT 1048576
MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE
"USERS" ;

  ALTER TABLE "SCOTT"."DEPT" ADD CONSTRAINT "PK_DEPT" PRIMARY KEY ("DEPTNO")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE
DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "USERS"  ENABLE;

PL/SQL procedure successfully completed.

SQL>  

SY.

Published by: Solomon Yakobson January 5, 2012 16:22

Tags: Database

Similar Questions

  • Problem with the primary key and indexes

    Hi all

    I'm looking a mess on one of our main tables.
    One of the developers here added an index on 3 columns in the table, thinking that it would speed up (not noticing that it had not a PK).

    Subsequently another developer has noticed there do not have a primary on key. So they added a touch of primry on the single column.

    The problem is that now the index created on 3 columns is bein used as the primary key index. As when the primary key is created a new index was not created.

    Is there anyway to get rid of this index/change it correct?

    This table is related to many many other tables, so when we tried to remove the index we could not due to the primary key and foreign key violations with other tables.

    Thanks in advance

    Oracle, as you found, is quite capable to use a column enformce multi index a single column primary key, as long as the pk column is the leader in the index. This should not cause performance issues for a search of PK and if the three indexed columns are often selected only may benefit from these types of queries.

    The only way to change that now, would be to drop all CF, drop and add the PK constraint and then add all the FK constraints. A long time and potentially dangerous (if you miss to add back of the FKs) endeavour. Certainly not worth the risk in my opinion.

    John

  • Difference of path between primary key and a Unique Index

    Hi all

    Is there a specific way the oracle optimizer to treat differently the Primary key and Unique index?

    Oracle Version
    SQL> select * from v$version;
    
    BANNER
    --------------------------------------------------------------------------------
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE    11.2.0.3.0      Production
    TNS for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production
    
    SQL> 
    Sample data test for Index Normal
    SQL> create table t_test_tab(col1 number, col2 number, col3 varchar2(12));
    
    Table created.
    
    SQL> create sequence seq_t_test_tab start with 1 increment by 1 ;
    
    Sequence created.
    
    SQL>  insert into t_test_tab select seq_t_test_tab.nextval, round(dbms_random.value(1,999)) , 'B'||round(dbms_random.value(1,50))||'A' from dual connect by level < 100000;
    
    99999 rows created.
    
    SQL> commit;
    
    Commit complete.
    
    SQL> exec dbms_stats.gather_table_stats(USER_OWNER','T_TEST_TAB',cascade => true);
    
    PL/SQL procedure successfully completed.
    
    SQL> select col1 from t_test_tab;
    
    99999 rows selected.
    
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 1565504962
    
    --------------------------------------------------------------------------------
    | Id  | Operation         | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
    --------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT  |            | 99999 |   488K|    74   (3)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| T_TEST_TAB | 99999 |   488K|    74   (3)| 00:00:01 |
    --------------------------------------------------------------------------------
    
    
    Statistics
    ----------------------------------------------------------
              1  recursive calls
              0  db block gets
           6915  consistent gets
            259  physical reads
              0  redo size
        1829388  bytes sent via SQL*Net to client
          73850  bytes received via SQL*Net from client
           6668  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
          99999  rows processed
    
    SQL> create index idx_t_test_tab on t_test_tab(col1);
    
    Index created.
    
    SQL> exec dbms_stats.gather_table_stats('USER_OWNER','T_TEST_TAB',cascade => true); 
    
    PL/SQL procedure successfully completed.
    
    SQL> select col1 from t_test_tab;
    
    99999 rows selected.
    
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 1565504962
    
    --------------------------------------------------------------------------------
    | Id  | Operation         | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
    --------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT  |            | 99999 |   488K|    74   (3)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| T_TEST_TAB | 99999 |   488K|    74   (3)| 00:00:01 |
    --------------------------------------------------------------------------------
    
    
    Statistics
    ----------------------------------------------------------
              1  recursive calls
              0  db block gets
           6915  consistent gets
              0  physical reads
              0  redo size
        1829388  bytes sent via SQL*Net to client
          73850  bytes received via SQL*Net from client
           6668  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
          99999  rows processed
    
    SQL> 
    Examples of test when using primary key data
    SQL> create table t_test_tab1(col1 number, col2 number, col3 varchar2(12));
    
    Table created.
    
    SQL> create sequence seq_t_test_tab1 start with 1 increment by 1 ;
    
    Sequence created.
    
    SQL> insert into t_test_tab1 select seq_t_test_tab1.nextval, round(dbms_random.value(1,999)) , 'B'||round(dbms_random.value(1,50))||'A' from dual connect by level < 100000;
     
    99999 rows created.
    
    SQL> commit;
    
    Commit complete.
    
    SQL> exec dbms_stats.gather_table_stats('USER_OWNER','T_TEST_TAB1',cascade => true);
    
    PL/SQL procedure successfully completed.
    
    SQL> select col1 from t_test_tab1;
    
    99999 rows selected.
    
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 1727568366
    
    ---------------------------------------------------------------------------------
    | Id  | Operation         | Name        | Rows  | Bytes | Cost (%CPU)| Time     |
    ---------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT  |             | 99999 |   488K|    74   (3)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| T_TEST_TAB1 | 99999 |   488K|    74   (3)| 00:00:01 |
    ---------------------------------------------------------------------------------
    
    
    Statistics
    ----------------------------------------------------------
              1  recursive calls
              0  db block gets
           6915  consistent gets
              0  physical reads
              0  redo size
        1829388  bytes sent via SQL*Net to client
          73850  bytes received via SQL*Net from client
           6668  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
          99999  rows processed
    
    SQL> alter table t_test_tab1 add constraint pk_t_test_tab1 primary key (col1);
    
    Table altered.
    
    SQL> exec dbms_stats.gather_table_stats('USER_OWNER','T_TEST_TAB1',cascade => true); 
    
    PL/SQL procedure successfully completed.
    
    SQL> select col1 from t_test_tab1;
    
    99999 rows selected.
    
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 2995826579
    
    ---------------------------------------------------------------------------------------
    | Id  | Operation            | Name           | Rows  | Bytes | Cost (%CPU)| Time     |
    ---------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT     |                | 99999 |   488K|    59   (2)| 00:00:01 |
    |   1 |  INDEX FAST FULL SCAN| PK_T_TEST_TAB1 | 99999 |   488K|    59   (2)| 00:00:01 |
    ---------------------------------------------------------------------------------------
    
    
    Statistics
    ----------------------------------------------------------
              1  recursive calls
              0  db block gets
           6867  consistent gets
              0  physical reads
              0  redo size
        1829388  bytes sent via SQL*Net to client
          73850  bytes received via SQL*Net from client
           6668  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
          99999  rows processed
    
    SQL> 
    If you see here the same even as the statistics were gathered,
    * In the 1st table T_TEST_TAB, table always use FULL table access after creating indexes.
    * And in the 2nd table T_TEST_TAB1, table uses PRIMARY KEY as expected.

    Any comments?

    Kind regards
    BPat

    >
    * In the 1st table T_TEST_TAB, table always use FULL table access after creating indexes.
    * And in the 2nd table T_TEST_TAB1, table uses PRIMARY KEY as expected.
    >
    Yes - for the first table a full table scan will be used as the currently selected column is nullable and indexes do not include null values.

    The index can be used for the second query, since all the data (first column) is available between the index and there may be no NULL values because of the primary key. If you check constraints, you find that the there is now a CHECK constraint to ensure that the first column cannot be null.

    For a full and interesting discussion see the explanation of this and a related issue on the question I ask in this thread
    What SYS tables (not seen) contain the value NULL spec /not/ column definition? and my response he posted: 23 April 2012 09:02

    I ask the question is based on a question here which is similar to yours
    Columns becoming nullable after a fall of primary key?

  • manually assign primary key and copy to the detailed form

    Hi experts,

    Oracle Apex 4.2, 11g database, using windows 7.

    I created a form and created automatic product no. (not only sequence) with logic and SQL. SQL query produced good wise exercise, and exercise begin from 01 July and ends 30 June each year. This means if the 07/01/2015 start it will create a new voucher No.

    The main Table name is GL_PV and the columns are:

    Number of PV_No

    Date of PV_Date

    Number of CC_code

    number amount

    Remarks varchar2 (100)

    Created a process to submit before the calculations and validations.

    The codes are

    NVL SELECT (MAX (to_number (nvl(pv_no,0))) + 1, 1) AMENDMENTS

    IN: P15_pv_no

    OF GL_PV

    WHERE pv_date

    BETWEEN to_date (' 01-07-' |) (extract (year from to_date (: P15_pv_date, "dd-mm-yyyy")))

    + case when extracted (month of to_date (: P15_pv_date, "dd-mm-yyyy")) < = end of another 0, then 6-1), "dd-mm-yyyy")

    AND to_date (30 - 06-' |) (extract (year from to_date (: P15_pv_date, "dd-mm-yyyy")))

    (+ case when extracted (month of to_date (: P15_pv_date, "dd-mm-yyyy")) < = 6 then 0 otherwise 1 end), "dd-mm-yyyy")

    and cc_code =: P15_cc_code;

    and press the button when Conditions = Generate_Button

    In the form of master I put the data and click on create button is working well and generating good can result.

    Now that I've created a detail of my detail table is pv_detail and the columns are

    pv_voucher_no

    pv_date

    account_code

    Remarks

    amount

    I want to create the relationship of the master / detail form.

    I tried:

    • primary key and foreign key, but does not. column GL_PV table primary key (PV_NO, PV_DATE), PV_DETAIL (pv_voucher_no, pv_date) foreign key table columns: -.
    • has created one for master and 2nd 2 form for details, good master shape generates but not detail of.

    I want to assign pv_no, pv_date in both value table (master / detail), in other words copy value pv_no and pv_date of main table in detail table pv_voucher_no and pv_date.

    Please advise how I can solve this problem.

    Thank you forum oracle to solve my problems.


    error report: ORA-01790: expression must have the same type of data, matching expression

    Find the solution on this forum

    Solution:

    Attributes and the tabular form:

    Change the default type = PL/SQL Expression on the function

    Default = to_date(:P15_PV_DATE,'DD-MON-YYYY')



  • Primary key and unique key not Null

    Hello gurus,

    Asked in an interview about the difference between primary and unique keys.
    I talked Unique keys can accept null values, but they are unique through should have the table. So, the next question asked me was "a Unique key NOT NULL can be treated as the primary key?

    Tricky question! :)
    I said yes! that it meets the requirement to be a primary key for this particular table, but since this isn't really a primary key, that it can't be covered in the foreign keys.

    The interviewer wanted just a Yes or no.

    Can someone please put some of this?

    Thanks in advance!

    Two things.
    1. unique can also be referenced as a foreign key. If your statement "but because this isn't really a primary key may not be seized key foreign." is not true.
    2. primary key and Unique key are different (for example you can have more than one UK in a table but PK's alone) and to know the difference, read some RDBMS concepts.

    I'm curious to know what is the outcome of your interview? ;)

  • What is the difference between primary key and unique indexes with forced not null?

    Primary key is = unique index + not null?

    The short answer is Yes.

    However, even if the primary key, applying both uniquness and not null, there is a notion of "special".

    You can only have one primary key in tables, but you can have multiple unique indexes and constraints not null.

    See: https://asktom.oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:8743855576462

  • Primary key and foreign key between the different schemas

    Hi all;

    SCOTT user have a 'rank' of table-> it contains the primary key-> users tablespace

    The U1 user have a 'emp' table-> it contains the foreign key-> test tablespace

    U1 > select constraint_name, constraint_type, r_owner, owner, r_constraint_name of all_constraints where table_name = 'EMP ';

    OWNER CONSTRAINT_NAME C R_OWNER R_CONSTRAINT_NAME

    ------------ ------------------------------ - -------------------------- ----------------------- -----------------------------------------------------

    U1              EMP_EMPLEV_C12_FK R SCOTT GRADE_GRL_C1_PK

    If I have connection U1, no possibility to find the name of the primary key without connection scott table?

    Thank you

    Hello

    So, you want to know what picture of the SCOTT schema has the constraint that is named "GRADE_GRL_C1_PK." Isn't it?

    If so,.

    SELECT table_name

    Of all_constraints

    Owner WHERE = 'SCOTT '.

    AND the argument constraint_name = 'GRADE_GRL_C1_PK. '

    ;

  • Primary key and foreign key

    Hi all

    I'm confused. If I create a primary key of table constraints, it willl create a unique index by default. If I create a foreign key, it also creates an index? of any kind?


    Thank you very much

    Kinz

    Laughing out loud. foreign key does not have a unique index on the table.

  • View of Materlized primary key and primary key in the master tables

    We use the Oracle 11 g 2 and I created a view on several paintings of master materlized. The paintings of masters all have the primary key, but I understand not all primary key columns in the query definition.
    According to Oracle manual e10592
    Specify WITH PRIMARY KEY to create a primary key materialized view. This is the default ....
    The master table must contain an enabled primary key constraint, and the defining query of the materialized view 
    must specify all of the primary key columns directly.
    My MV created OK and works. My question is what can be the impact on my MV? Could he hit to performance. It takes 40 minutes to the MV should be created and 5 minutes to refresh the one line insert in each table of mater. I would like to see it refresh in a few seconds.

    Retrieve the lines of the mview is purely a function of the number of lines and indexing on the mview himself. Mview refreshing at the time of the wall depends on the quality of the query used to refresh the mview. If you include the PKs of the source table in the mview matter or not, here. What matters is the execution of the refresh request path. Is it okay to indexation on the underlying tables to support the joints. Did you use mlog$ _s to allow a quick refresh - mlog$ _s are still usable for your mview. There are a number of possible causes for your problem and we do not have enough information to make an estimate of the problem.

    BTW, if the mview could refresh in a few seconds without mlog$ _s, probably unnecessary a mview.

  • Updating related Records primary key and FK dependencies

    (1) how can I found the name of all the tables that use my primary key as a foreign key? The primary key is of type varchar and used in many other paintings. Now PK records must be changed by the customer's request, so it will affect obviously all of my dependent tables.
    (2) which corresponds to the PL/SQL script more efficient to perform this procedure?
    All suggestions will be useful.

    To test, I think I want a list of all tables in followed by a list of all affected records. This report must show registration PK & all records in dependence requiring an update. Is this reasonable?

    user10998542 wrote:
    (1) how can I found the name of all the tables that use my primary key as a foreign key? The primary key is a varchar and used in many other paintings. Now PK records must be changed by the customer's request, so it will affect obviously all of my dependent tables.

    Discover the view USER_CONSTRAINTS. You could do something like this:

    SELECT     UC.OWNER
    ,     UC.TABLE_NAME
    ,     UC.R_OWNER
    ,     RUC.TABLE_NAME
    ,     UC.R_CONSTRAINT_NAME
    ,     RUC.CONSTRAINT_TYPE
    FROM     USER_CONSTRAINTS UC
    ,     USER_CONSTRAINTS RUC
    WHERE     UC.R_OWNER          = RUC.OWNER
    AND     UC.R_CONSTRAINT_NAME     = RUC.CONSTRAINT_NAME
    AND     UC.CONSTRAINT_TYPE     = 'R'
    

    If you need names of columns, you can use the USER_CONS_COLUMNS view also.

    (2) which corresponds to the PL/SQL script more efficient to perform this procedure?
    All suggestions will be useful.

    [Tom Kyte: package Cascade | http://tkyte.blogspot.com/2009/10/httpasktomoraclecomtkyteupdatecascade.html]

  • Potential problems for tables without primary keys and unique keys

    GoldenGate 11.2.1.0.3/Solaris 10
    DB: Oracle for Oracle (Source and target is 11.2.0.3)
    Topology: unidirectional


    In our one-way configuration GG, little of the tables being replicated is not a primary key or a Unique key.

    Last week when we have implemented GG for the test, we received warnings for these table below.
    GGSCI > add trandata WMHS_UD.crtn_dtl
    
    2013-01-12 11:34:33  WARNING OGG-00869  No unique key is defined for table 'CRTN_DTL'. All viable columns will be used to represent the key, but may not guarantee uniqueness.  KEYCOLS may be used to define the key.
    
    Logging of supplemental redo data enabled for table WMHS_UD.crtn_dtl.
    Replication seems to work very well for these tables.

    Googling, I think that there may be performance degradation when you replicate tables without PK or the United Kingdom.

    But are there other potential problems such as data of a certain kind not replicated to the lack of PK/UK?

    It really depends on the data.

    By default, GG is combining all columns as a virtual primary key but don't no conflict control by default. So when you can be sure that the record you insert into the table is unique, then it will work.
    BUT as soon as you insert the same record, which is already inserted, then you will encounter problems.

    Let me show what happens when you use an initial charge because it makes it easier to describe:
    We start at 10:00 the capture for a table. Now, you insert a record at 10:00 in the tables. When you now start an initial charge to 10.02, then check you have inserted in the database to 10.01 will be repeated two times. During the IPL as the initial charge is made to 10.02 and it includes data of 10.01 AND it will be replicated again through the process of capture/replicate.

  • Primary key question

    Hello

    database version is GR 11, 2; We moved a large table of 12 million records from database 1 database 2. That's how the developers moved:

    create the table temp_engine in select * engine;

    Then re-named table temp_engine of the engine; but with this method, the primary key and the markings on table engine not copied. If we lose primary key and indexes on table engine. We want to add primary key and indexes, while the application is running. It's high system, busy with many inserts/updates / select on table engine; data are entered into the engine table every 10 minutes;

    Issues related to the:

    1 - the addition of pk would take time and can slow down the database?
    2 - what kind of locks, if any, we will have when adding the primary key and index?
    3. in the case, we will have the locks when adding the index/pk; the inserts will not happen until the locks to be released just?


    Thank you very much
    Diego

    Published by: Diego 16 April 2012 07:19

    In your first post, you said that your developer have moved (basically it's not moving, rather a copy) by:
    create the table temp_engine in select * engine; the first second db db and now wish you that this new temp_engine has same constraint, privileges, statistics as well as the right table engine? At the same time table is very used in the comic book then, it must avoid any lock or lack of temp straight segment like that?

    So, please check the example below, where you can use EMP as temp_engine and INT_TAB as table of this db engine... after the end of the process, you can simply file temp_engine, rename INT_TAB as an engine.

    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    
    SQL> create table int_tab as select * from emp where 1=2;
    
    Table created.
    
    SQL> select grantee,privilege from user_tab_privs where table_name='EMP';
    
    GRANTEE                        PRIVILEGE
    ------------------------------ ----------------------------------------
    HR                             SELECT
    HR                             UPDATE
    
    SQL> begin
      2  DBMS_REDEFINITION.CAN_REDEF_TABLE('scott','emp',
      3  DBMS_REDEFINITION.CONS_USE_PK);
      4  end;
      5  /
    
    PL/SQL procedure successfully completed.
    
    SQL> alter session force parallel dml parallel 4;
    
    Session altered.
    
    SQL> alter session force parallel query parallel 4;
    
    Session altered.
    
    SQL> BEGIN
      2  DBMS_REDEFINITION.START_REDEF_TABLE(
      3  uname       => 'SCOTT',
      4  orig_table  => 'EMP',
      5  int_table   => 'INT_TAB');
      6  END;
      7  /
    
    PL/SQL procedure successfully completed.
    
    SQL> DECLARE
      2  num_errors PLS_INTEGER;
      3  BEGIN
      4  DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS(
      5  'SCOTT','EMP','INT_TAB',DBMS_REDEFINITION.CONS_ORIG_PARAMS,
      6  TRUE, TRUE, TRUE, FALSE, num_errors, TRUE);
      7  END;
      8  /
    
    PL/SQL procedure successfully completed.
    
    SQL> BEGIN
      2  DBMS_REDEFINITION.SYNC_INTERIM_TABLE('SCOTT', 'EMP', 'INT_TAB');
      3  END;
      4  /
    
    PL/SQL procedure successfully completed.
    
    SQL> BEGIN
      2  DBMS_REDEFINITION.FINISH_REDEF_TABLE('SCOTT', 'EMP', 'INT_TAB');
      3  END;
      4  /
    
    PL/SQL procedure successfully completed.
    
    SQL> select grantee,privilege from user_tab_privs where table_name='INT_TAB';
    
    GRANTEE                        PRIVILEGE
    ------------------------------ ----------------------------------------
    HR                             SELECT
    HR                             UPDATE
    
    SQL> select constraint_name,constraint_type,table_name from user_constraints where table_name in ('EMP','INT_TAB');
    
    CONSTRAINT_NAME                C TABLE_NAME
    ------------------------------ - ------------------------------
    PK_EMP                         P EMP
    FK_DEPTNO                      R EMP
    TMP$$_PK_EMP0                  P INT_TAB
    TMP$$_FK_DEPTNO0               R INT_TAB
    

    So, at this point, my INT_TAB is just a clone of the EMP table. Even statistics, the privileges and the constraints of the EMP have been applied to INT_TAB. Now, at this point you can drop temp_engine table and can use INT_TAB as an engine.

    Hope I am clear in my answer, if it is not then please keep also close the message.

    Concerning
    Girish Sharma

  • by specifying the index tablespace in to disable the primary key constraint

    Hello
    during the ETL I want to disable constraints PK/UK to speed up the load;
    on activation of the constraint, the corresponding indices are created in a different tablespace while they were initially on the creation of the table itself
    I tried to disable PK / UK with the option 'keep the index', the index value corresponding to the status of "unusable" and use ' alter session set skip_unusable_indexes = true', but then I can't insert rows with the error.
    Error: ORA-01502: index 'xxx' or partition of such index is in unusable state
    can anyone tell if there is a way to allow the PK/UK constraint and specify the storage space for the corresponding indices, or keep the index and inserts works?
    I'd like to avoid to drop constraints / indexes and re-create them both from scratch after the load
    Thank you for the advice
    Thank you
    Rgds

    >
    can anyone tell if there is a way to allow the PK/UK constraint and specify the storage space for the corresponding indices, or keep the index and inserts works?
    I'd like to avoid to drop constraints / indexes and re-create them both from scratch after the load
    >
    Have you tried specifying the table space in the USING clause when you activate the constraint?

    ALTER TABLE emp ENABLE PRIMARY KEY USING INDEX TABLESPACE myTS;
    

    See DBA guide
    http://docs.Oracle.com/CD/B28359_01/server.111/b28310/indexes003.htm
    >
    Creating an Index associated with a constraint

    Oracle database applies a UNIQUE key or a constraint integrity PRIMARY KEY on a table by creating a unique index on the unique key or primary key. This index is created automatically by the database when the constraint is enabled. No action is required by you when you run the CREATE TABLE or ALTER TABLE statement to create the index, but you can optionally specify an ESCALATION using clause to exercise control over his creation. This includes them when a constraint is defined and enabled, and when a constraint defined but disabled is selected.
    >
    Note the last sentence two sentences:
    >
    You can optionally specify an ESCALATION using clause to exercise control over his creation. This includes them when a constraint is defined and enabled, and when a constraint defined but disabled is selected.
    >
    You realize, I hope, that the only way can Oracle KNOWS that the index contains valid values is to rebuild?

  • type of index on a primary key

    HI.i want to know the type of index that is automatically created by oracle on primary key and foreign key. Please rpely as soon as possible.

    Hello

    This means that it is a B * Tree rather than the Bitmap index.

    Mike

  • How can I make sure that changes in a primary key (in the parent table) would also appear directly in the FOREIGN KEY in the child table?

    Forgive my question. I am very new to Oracle.

    How can I make sure that changes in the key primary supplier_id (concerning the supplier table) would also appear directly in the FOREIGN KEY (supplier_id) in the products table?

    Is that not all the primary key and FOREIGN KEY on?

    My paintings:

    I created 2 tables and connect to apply in the data base referential integrity, as I learned.

    CREATE TABLE - parent provider

    (the numeric (10) of supplier_id not null,)

    supplier_name varchar2 (50) not null,

    Contact_Name varchar2 (50).

    CONSTRAINT supplier_pk PRIMARY KEY (supplier_id)

    );

    CREATE TABLE - child products

    (the numeric (10) of product_id not null,)

    supplier_id numeric (10) not null,

    CONSTRAINT fk_supplier

    FOREIGN KEY (supplier_id)

    REFERENCES beg (supplier_id)

    );

    I inserted the following text:

    INSERT INTO provider

    (supplier_id, supplier_name, contact_name)

    VALUES

    (5000, 'Apple', 'first name');

    I expect that the supplier_id (5000) to the provider of the table also appears in the products table under key supplier_id having the same value which is 5000. But this does not happen.

    How to get there?

    Thanks in advance!

    Hello

    What is a foreign key in Oracle?

    A foreign key is a way to ensure referential integrity in your Oracle database. A foreign key means that the values of a table must appear also in another table.

    Ok!??

    What is now the right way to implement referential integrity in your Oracle database that the values of a table must also be included in another table?

    A foreign key referential integrity indeed enfore in ensuring that the value in the child table must have a corresponding parent key (otherwise you will encounter an error, as evidenced by "SomeoneElse"). However, it will never automatically insert a row in the other table.

    If you are looking for a solution that automatically inserts a record in the other table, maybe you should go for triggers:

    See:

Maybe you are looking for

  • TrueSuite Access manager needs fingerprints - Satellite U400 driver

    Hello Whenever I start my new Satellite U400, TrueSuite Access manager says that the drivers are not installed for the fingerprint reader and try to install them again. Even after I install TrueSuite Access Manager, he asks me to reinstall the driver

  • My UK Touchsmart 300 will work in the United States?

    I bought my Touchsmart 300 at the United Kingdom 2 years ago.  Now, I'm moving back to the United States and bring it with me.   I have an adapter for it and if so, what kind?

  • My Ibook G3 is cutting

    Hello guys,. My Apple Ibook G3 (not sure if it's a G3, but the model number is A1007 and is since 2002) has not worked for quite awhile and I recently came across it and wanted to remedy. I heard that my problem happened many models of Ibook G3 and G

  • LabVIEW data Plugin SDK

    Is - this Labview Data Plugin SDKis always running on LV2009? I installed it but have no idea how to do to work with. I can not even find the mentioned help file LV_DataPlugin_SDK.pdf after installation. I wanted to use it to write a Plugin to G data

  • starts Windows HELP!

    Hi, I bought an ideapad y410p of the Web page and it was delivered to a member of the family, so she could bring here in the Dominican Republic where I live... But to my surprise it didn't have the operating system installed, when I turned on it, he