Primary Keys and ADT

Hi,
For uniformity sake, I've created a new data type with one property in it (VARCHAR2(30)). Prior to this I had that data type in all of my tables and created primary keys on that. Now, I have replaced the old VARCHAR2(30) with this new data type YET I want to keep my primary key on it. When I do this I get an error indicating a primary key can NOT be on a user defined data type.
Am I missing something? Should I post code? Is this not possible?
Any advice would be GREATLY appreciated.

Steve,
Primary key columns cannot be an object type.
Regards,
Geoff

Similar Messages

  • Diff b/w primary key and unique key?

    what is the diff b/w primary key and unique key?

    Hi,
    With respect to functionality both are same.
    But in ABAP we only have Primary key for the Database tables declared in the Data Dictionary.
    Unique is generally is the term used with declaring key's for internal tables.
    Both primary and Unique keys can identify one record of a table.
    Regards,
    Sesh

  • Access path difference between Primary Key and Unique Index

    Hi All,
    Is there any specific way the oracle optimizer treats Primary key and Unique index differently?
    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 test data for Normal Index
    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> Sample test data when using Primary Key
    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 even though statistics were gathered,
         * In the 1st table T_TEST_TAB, the table is still using FULL table access after creation of index.
         * And in the 2nd table T_TEST_TAB1, table is using PRIMARY KEY as expected.
    Any comments ??
    Regards,
    BPat

    Thanks.
    Yes, ignored the NOT NULL part.Did a test and now it is working as expected
    SQL>  create table t_test_tab(col1 number not null, col2 number, col3 varchar2(12));
    Table created.
    SQL>
    create sequence seq_t_test_tab start with 1 increment by 1 ;SQL>
    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('GREP_OWNER','T_TEST_TAB',cascade => true);
    PL/SQL procedure successfully completed.
    SQL>  set autotrace traceonly
    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
           6912  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>  create index idx_t_test_tab on t_test_tab(col1);
    Index created.
    SQL>  exec dbms_stats.gather_table_stats('GREP_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: 4115006285
    | Id  | Operation            | Name           | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT     |                | 99999 |   488K|    63   (2)| 00:00:01 |
    |   1 |  INDEX FAST FULL SCAN| IDX_T_TEST_TAB | 99999 |   488K|    63   (2)| 00:00:01 |
    Statistics
              1  recursive calls
              0  db block gets
           6881  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>

  • Difference between primary key and primary index

    Dear All,
             Hi... .Could you pls tell me the difference between primary key and primary index.
    Thanks...

    Hi,
    Primary Key : It is one which makes an entry of the field unique.No two distinct rows in a table can have the same value (or combination of values) in those columns.
    Eg: first entry is 111, if you again enter value 111 , it doesnot allow 111 again. similarly for the strings or characters or numc etc. Remember that for char or numc or string 'NAME' is not equal to 'name'.
    Primary Index: this is related to the performance .A database index is a data structure that improves the speed of operations in a table. Indices can be created using one or more columns, providing the basis for both rapid random lookups and efficient ordering of access to records. The disk space required to store the index is typically less than the storage of the table (since indices usually contain only the key-fields according to which the table is to be arranged, and excludes all the other details in the table), yielding the possibility to store indices into memory from tables that would not fit into it. In a relational database an index is a copy of part of a table. Some databases extend the power of indexing by allowing indices to be created on functions or expressions. For example, an index could be created on upper(last_name), which would only store the uppercase versions of the last_name field in the index.
    In a database , we may have a large number of records. At the time of retrieving data from the database based on a condition , it is a burden to the db server. so whenever we create a primary key , a primary index is automatically created by the system.
    If you want to maintain indices on other fields which are frequently used in where condition then you can create secondary indices.
    Reward points if helpful.
    Thanks,
    Sirisha..

  • Is their a difference between primary key and unique key with not null valu

    What is the difference in having a column as primary key and having unique key with not null for the column.
    vinodh

    SBH wrote:
    For quick review, below is the link
    http://www.dba-oracle.com/data_warehouse/clustered_index.htm
    You appear to have stumbled on a site that is a mine of disinformation about Oracle.
    >
    It would be helpful, if you explain it too..thnx !!
    The site is wrong and makes up its own terminology as it goes along.
    If the value for clustering factor approaches the number of blocks in the base table, then the index is said to be clustered. http://www.oracle.com/pls/db112/search?remark=quick_search&word=clustered+index
    There is no create clustered index in Oracle.
    - Clustering factor affects the efficiency of an index.
    - There can be clustered tables that you can create indexes on.
    - An Index Organized table is a similar concept to the Microsoft SQL Server clustered index, but it isn't the same thing at all.

  • Difference between PRIMARY KEY and UNIQUE KEY with NOT NULL

    What is the difference between PRIMARY KEY and UNIQUE KEY with NOT NULL constraint?
    Message was edited by:
    Nilesh Hole

    Answer for the master!!!
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:8743855576462
    Thanks,
    Karthick

  • Primary keys and store generated pattern

    Hi,
    in my database first application (Firebird), the primary keys are not set to identity by default !
    any ideas why this ?

    Solved !
    put #PK_GEN# as comment for your primary key and now EF import primary keys columns as identity like expeted :)
    btw, fb 3.0 and up support identity columns .

  • Primary keys and constraints are gone....

    Hi Experts,
    I had a schema SchemaD with all primary keys and referential constraints. And i am a TOAD user. I had one more source schema SchemaS.
    In my destination schema all the tables has 2 extra columns for data warehouse purpose.
    I disabled all the constraints and i used toad utility "Copy Data to Another Schema" and i selected all the tables from Source SchemaS.
    After the completion of data copy i tried to enable all the constraints in SchemaD. But i found that there are no primary keys and referential integrates in that schema.
    Please help me in this issue.
    Thanks...
    Ray

    Check in the views "DBA_CONSTRAINTS" or ALL_CONSTRAINTS" with the condition owner='your_schema_name'
    If you are using toad to view the constraints, chances are high that there is a filter in the toad view and it is filtering the constraints...
    Edited by: Suchit on Feb 25, 2009 5:19 PM
    Edited by: Suchit on Feb 25, 2009 5:20 PM

  • Primary keys and foreign keys

    Hi,
    is there a script available for changing the value of a primary key which automaticly
    detect all foreigs keys refering to this primary key and change them as well?
    William Oorschot

    I don't have the script now. but you can make a procedure of ur own.
    using a join on user_constraints, and user_cons_columns you can find out all the columns in all the tables which are referencing the particular primary key. once you have the table and the referencing columns, you can change the value of those columns with the new value.
    you'll have to call this procedure from a before row level trigger.
    HTH
    Naveen

  • Primary Key and Foreign Key Constraints

    Hi All,
    I would like to know PRIMARY KEY and FOREIGN KEY constraints on existing oracle tables. Could any one suggest me how to find out.
    Thanks,
    RED

    You can query DBA_CONSTRAINTS to get a list of all the constraints on table A and/or table B. The documentation I linked to gives a full list of the data you can see in DBA_CONSTRAINTS, but it includes things like the referenced table name and referenced constraint name for a foreign key constraint. If A is a parent of B or B is a parent of A, you could match up the parent's primary key constraint to the child's foreign key constraint.
    More generally, though, if you don't know that one of the tables is a parent of the other, figuring out how to join the two tables is probably not something that can be done using just the Oracle data dictionary. You would probably need an understanding of the data model being used to figure out what intermediate table(s) needed to be joined in order to relate rows in A to rows in B.
    Justin

  • Primary key and WHO columns on EO

    We are trying to create a EO based on a database view. We do not have primary key and standard OA WHO columns but the OA framework is forcing us the have these columns. How do we go about this issue? Any suggestion will be appreciated.

    Oracle Apps mandates that you should have the Audit columns in the Applications tables.
    So you must have the 5 columns defined.
    I have created new tables for my application and need to populate them whenever user creates or modifies any row
    Jdeveloper/BC4J handles direct updates/inserts through default EO implementation, it would insert/update/delete from the base table via the EO, what is your qeustion then ? do you want to know how to perform DMLs in OA or something else ?
    Thanks
    Tapash

  • Primary key and Foreign key on same column

    Hi, I am able to create below tables , primary and foreign keys as below.
    But Is this valid design? Can I define a column (ckey2 in table "child") as
    primary key and as well as foreign key?
    CREATE TABLE parent (
    col1 NUMBER,
    col2 NUMBER
    CREATE TABLE child (
    ckey1 NUMBER,
    ckey2 NUMBER,
    ckey3 NUMBER
    alter table parent add constraint parent_pk primary key( col1 );
    alter table child add constraint child_pk primary key( ckey2 );
    alter table child add constraint child_fk foreign key( ckey2 ) references parent( col1);
    Thanks.

    Can I define a column (ckey2 in table "child") as primary key and as well as foreign key?You mean you want to define a one-to-one relationship between parent and child tables.. why would you want to do that ? You might as well merge the 2 tables into one.

  • Update a primary key and Fk

    Hello
    I have to update a primary key (PK) which is referenced by many foreign keys (FK).
    The primary key columns cannot be updated as this would orphan the dependant tables,
    and the dependant tables cannot be updated prior to the parent table as this would also make them orphans.
    I think this problem was solved by disabling the foreign key constraints or deleting the original records and recreating them.
    Since neither of these solutions is particularly satisfactory for me I read about 'deferred constraints'.
    My question is:
    Can I use(modify to) 'INITIALLY DEFERRED' keyword on constraints's table already created with The default, INITIALLY IMMEDIATE ,
    that is, update my primary key and foreign keys, and then re-set to
    'INITIALLY IMMEDIATE'? Or another trick exists ?
    Thanks in advance for your attention

    It is very popular the idea that the updates on primary key columns are a very bad thing.
    Oracle supports this idea and that's why they don't give the "on update cascade" clause on foreign keys.
    So in this case I suggest you to define a master table like this.
    create table master_table (
         key_id number primary key,
         your_primary_key varchar2 not null unique
    /Then you must use that key_id column as foreign key in place of your original primary key. In this way don't even need to update referencing rows when updating the original primary key because the foreign key value doesn't change and everything is always fine as before.
    So instead to lose time implementing some strange sort of cascade triggers plain to do something like this on your schema.
    insert into master_table (id_key,primary_key) (
         select rownum,primary_key
         from your_main_table
    alter table your_main_table add (
         id_key number,
    update your_main_table a
    set id_key = (
              select b.id_key
              from master_table
              where b.primary_key=a.primary_key
         Drops foreign keys
    alter table your_main_table drop primary key cascade
    alter table your_main_table add constraint pk
         primary key(id_key)
    alter table your_main_table add constraint fk
         foreign key(id_key) references master_table
    alter table your_main_table drop (
         your_primary_key
    alter table a_referencing_table add (
         id_key number,
    update a_referencing_table a
    set id_key = (
              select b.id_key
              from master_table
              where b.primary_key=a.primary_key
    alter table a_referencing_table add constraint fk_2
         foreign key(id_key) references master_table
    alter table a_referencing_table drop (
         your_primary_key
    /If you have many objects referencing those tables I suggest you to rename the tables and to create views with the original name of the renamed tables that show data as it was before with a join on master_table. in this way you don't need to change the code of the application referencing them but you just need to recompile invalidated objects.
    Bye Alessandro

  • Assigning primary key and index for a table

    I have a database consisting of only one table with 10 million rows which mostly looks like this:
    RECORDDATE                     ID     CLASS     VALUE
    24-JAN-12 10.52.47.000000 AM     96     3     0
    24-JAN-12 10.52.48.000000 AM     96     10     156
    24-JAN-12 10.52.48.000000 AM     96     3     0
    24-JAN-12 10.52.48.000000 AM     96     3     0
    24-JAN-12 10.52.48.000000 AM     96     3     0
    24-JAN-12 10.52.48.000000 AM     96     3     0
    24-JAN-12 10.52.48.000000 AM     96     10     156
    24-JAN-12 10.52.48.000000 AM     96     3     0
    24-JAN-12 10.52.48.000000 AM     96     3     0
    24-JAN-12 10.52.48.000000 AM     96     6     38
    24-JAN-12 10.53.05.000000 AM     253     16     197
    24-JAN-12 10.53.06.000000 AM     98     10     150
    24-JAN-12 10.53.06.000000 AM     98     0     0
    24-JAN-12 10.53.06.000000 AM     98     4     0
    24-JAN-12 10.53.06.000000 AM     98     11     33As you can see there are several entries that look exactly the same. Currently, I don't have primary key or index for any column and have a lot of performance issues. For example this query takes more than 10 seconds to run:
    select distinct      ID
    from      scdatabase4
    where ID < 253
    order by 1Since database is not my primary job and have no background of it, I'm really confused about what to do to fix my issues. Could someone please help me in assigning primary key and index if you agree that this is the problem?!

    Execute the query below to help decide what column to index:
    SELECT COLUMN_NAME, NUM_DISTINCT, NUM_NULLS, NUM_BUCKETS, DENSITY
    FROM DBA_TAB_COL_STATISTICS
    WHERE TABLE_NAME = 'your_table_name'
    ORDER BY COLUMN_NAME;
    The important columns are:
    1) NUM_DISTINCTS: Indicates the number of distinct values. If this number is very low for a column, it indicates that this column is not a very good candidate for a B-Tree index.
    2) NUM_NULL: Indicates the number of null values for each column. A column with few null values is a good candidate for a index
    But be aware, this is not a rule, it's just a method to help decide which column will have the most benefit of index creation.

  • How do I use Primary Key and RowID in Materialized View Logs and MVs

    How do I use Primary Key and RowID in Materialized View Logs and Materialized Views????
    I don’t understand in the Materalized View Logs the diference between Primary Key and RowID. Besides, I could choose both Primary Key and RowID.
    When I have to use RowID?? Why?? And Primary Key??? And both, Primary Key and RowID????
    Thank you very much!

    Yes, I have already read it...
    But for example I don’t Understand:
    This is the example 8-1
    CREATE MATERIALIZED VIEW LOG ON products
    WITH SEQUENCE, ROWID
    (prod_id, prod_name, prod_desc, prod_subcategory, prod_subcat_desc, prod_
    category, prod_cat_desc, prod_weight_class, prod_unit_of_measure, prod_pack_
    size, supplier_id, prod_status, prod_list_price, prod_min_price)
    INCLUDING NEW VALUES;
    But if I create a Materialized View with TOAD if I choose a KEY field I receive the error:
    ORA-12026: invalid filter column detected
    Then I have to take out the Key (in the above example prod_id)
    And then the script is
    CREATE MATERIALIZED VIEW LOG ON products
    WITH ROWID, SEQUENCE, PRIMARY KEY!!!!!!!!!!!!!!!!!!!!
    (prod_id, prod_name, prod_desc, prod_subcategory, prod_subcat_desc, prod_
    category, prod_cat_desc, prod_weight_class, prod_unit_of_measure, prod_pack_
    size, supplier_id, prod_status, prod_list_price, prod_min_price)
    INCLUDING NEW VALUES;
    I have PRIMARY KEY in the definition (I don’t choose it) and I don’t have the prod_id field
    Why is it????
    Note: If I execute the script to create the MV Log manually the PRIMARY KEY option NO IS in the script and the prod_id field either is in the script.
    And on the other hand,
    What is this:
    CREATE MATERIALIZED VIEW LOG ON sales
    WITH ROWID;
    CREATE MATERIALIZED VIEW LOG ON times
    WITH ROWID;
    CREATE MATERIALIZED VIEW LOG ON customers
    WITH ROWID;
    These MATERIALIZED VIEW LOG contain any fields????
    Or it contain the primary key fields of this tables (sales, times and customers)??? Then, Why is it ROWID instead of PRIMARY KEY????
    Thanks!

Maybe you are looking for