When I change a column is a primary key the associated non-unique index to become unique?

So basically I already tried this and it shows me that the associated index is not unique.

create table employees2 in select * from employees;

create index emp_idx on employees2 (employee_id);

ALTER employees2 table add primary key (employe_id) using index emp_idx;

Select * from user_indexes where index-name = "EMP_IDX";

I was wondering if I right assuming that when you change a column to a primary key or unique while using a given index that does not have the respective index become unique.

The textbooks I use are sometimes a little hard to understand because of the wording, also, I want to just ask someone with a little more experience than me.

Thank you.

your test did give the correct answer: the index is not unique if it serves to bear a unique or primary key constraint. Indeed, it is one of the benefits of the use of no unique indexes in support of UK/PK constraints (since it allows to set the unusable index before to make bulk loads; and, of course, they have also some disadvantages - for example, they need an additional logical reading to reach a line). Richard Foote explains the details in https://richardfoote.wordpress.com/2008/06/04/primary-keys-and-non-unique-indexes-whats-really-happening/ (and other items).

Tags: Database

Similar Questions

  • Accompanied by primary key to a non-unique index?

    Met a weird situation today. A utility, we set up which allows analysts to restore the data in their paintings, started failed when it attempted to drop an index. The index supported a primary key. Makes sense. But our script was supposed to be only an attempt to drop/recreate the nonunique indexes. It turns out that supported on the primary key index was not unique and to the best of my knowledge has emerged as follows:
    SQL> create table junk (f number(1));
    
    Table created.
    
    SQL> create index junk_ix on junk(f);
    
    Index created.
    
    SQL> select UNIQUENESS from DBA_INDEXES where index_name = 'JUNK_IX';
    
    UNIQUENES
    ---------
    NONUNIQUE
    
    SQL> alter table forbesc.junk add constraint junk_pk primary key (f) using index junk_ix;
    
    Table altered.
    
    SQL> select UNIQUENESS from DBA_INDEXES where index_name = 'JUNK_IX';
    
    UNIQUENES
    ---------
    NONUNIQUE
    
    SQL> insert into junk values (1);
    
    1 row created.
    
    SQL> insert into junk values (1);
    insert into junk values (1)
    *
    ERROR at line 1:
    ORA-00001: unique constraint (FORBESC.JUNK_PK) violated
    
    
    SQL> select index_name from dba_constraints where constraint_name = 'JUNK_PK';
    
    INDEX_NAME
    ------------------------------
    JUNK_IX
    What I can't understand, is how an index is not unique is to apply oneness. I thought it was the key to this process. I thought that perhaps an index with the 'SYS_123456' has be created, perhaps, but I couldn't find a:
    SQL> select object_name, object_type from dba_objects order by created desc;
    
    
    OBJECT_NAME   OBJECT_TYPE
    -------------------------------------------     
    JUNK_IX     INDEX
    JUNK     TABLE
    ...
    How the uniqueness is get applied in this case? It comes in Oracle 11.1.0.7

    Thank you
    -= Chuck

    It has always been like that. Oracle can and will use a non-unique index to apply a constraint to PK, the existing index just needs to have the columns PK as the leader or the columns in the index:

    SQL> create table t (id number, id1 number, descr varchar2(10));
    
    Table created.
    
    SQL> create index t_ids on t(id, id1);
    
    Index created.
    
    SQL> select index_name from user_indexes
      2  where table_name = 'T';
    
    INDEX_NAME
    ------------------------------
    T_IDS
    
    SQL> alter table t add constraint t_pk
      2  primary key (id);
    
    Table altered.
    
    SQL> select index_name from user_indexes
      2  where table_name = 'T';
    
    INDEX_NAME
    ------------------------------
    T_IDS
    
    SQL> insert into t values (1, 1, 'One');
    
    1 row created.
    
    SQL> insert into t values (1, 2, 'Two');
    insert into t values (1, 2, 'Two')
    *
    ERROR at line 1:
    ORA-00001: unique constraint (OPS$ORACLE.T_PK) violated
    

    John

  • changing column addition of primary key constraint

    How to change a table and edit a column and add a primary key constraint?

    987018 wrote:
    can add us a primary key constraint by using the command Edit?

    If the column already exists, and there is no existing primary key, then

    SQL> create table t (id number, descr varchar2(10));
    
    Table created.
    
    SQL> alter table t modify (id not null primary key);
    
    Table altered.
    

    If the column does not exist yet and there is no primary key, then:

    SQL> create table t1 (descr varchar2(10));
    
    Table created.
    
    SQL> alter table t1 add (id number not null primary key);
    
    Table altered.
    

    John

  • Not Null on the column of a primary key constraint

    I came across a table defined in the same way to...

    create table t (t_id int constraint nn_t_id not null constraint pk_t primary, data key number);

    Of course, the primary key is the is not null, then is there a reason to add the redundant constraint not null?

    There are two parts to your question, I think:

    (1) why add a NOT NULL if a primary key is also reported.
    (2) why is null is NOT a name defined by the user (in this case nn_t_id).

    1 > I think you are right: there is no difference in behavior in the way that Oracle is going to reject the creation of NULL in this column (whether through the direct insert or update with a NULL value). I personally always declares the NOT NULL for columns, I know to never have null, regardless of whether the column is (member of) a PK.

    It's pretty funny, btw, the SQL standard as chosen able to be the NULL default value. I think that we all type much less, if the SQL standard chose NOT NULL default value. But that's another story.

    2 > I don't see given nullability defined by the user of the explicit names now and then, because of some "coding guideline' which dictates that constraint names must never be generated System. This guideline is often presented as a result of the exception handling of "client-side", where the constraint name is filtered SQLERRM and then more personalized to be displayed to the end user. However for NOT NULL constraint violations, I think (does not fully to check) that you are always thrown an ORA-01400 is an ORA-01407. Who nowadays both will tell you exactly (in SQLERRM) which column of this table is currently in violation of a NOT NULL constraint.

    Toon

  • When I try to go on "fullscreen" while watching the screen tube u develops and becomes empty. The sound still works. I have Firefox. Can someone help plse?

    I can't watch any of the programs in U tube on change too many full-screen. yesterday everything was ok. I tried a restore of the system without result.

    Hello

    · Is the behavior even with Internet explore?

    If Yes, then you can follow the procedure:

    a. Click Start, click Run, type desk.cpl and then click OK.

    b. click on the settings tab and then click Advanced.

    c. on the performance tab or on the Troubleshooting tab, move the hardware acceleration all the way to the right (Full position).

    d. click OK and then click Close.

    e. If you are prompted to restart your computer, click Yes.

    If the problem is only with Firefox, you can post your request in the support forum of Mozilla for assistance: http://support.mozilla.com/en-US/questions

  • Change of primary key on the Table clears the other columns

    Preliminary info/Installation
    JDeveloper 11 g 11.1.1.6.0
    We have a table (object view or entity) that has 8 columns. The primary key is composed of 4 1 columns.
    The table is displayed in a page fragment.
    2 of the 4 non-primary key columns are LOV.
    All the 8 columns are needed.
    The table is editable including 2 of primary key columns.

    Question
    Assume that the table displays the 3 lines. If we change a rank 1 non-primary key column and a primary key in row 2 column, everything works well when we are committed to the database
    If, however, we first change a primary key column, then a primary key on a different line column, then the column/row primary key that changed us first, gets annihilated and the other columns LOV on this same line. The 2 columns that are not LOV keep data as it should. We then get a validation error because the required data are not present. All this happens before we try all commit to the database. If debug us and look the iterator, it has the old data in this document, before and after any performance on the binding.
    If we look at and update the data via the App Module, everything works well. We have tried to update the view, etc. through valueChangeListener also with no luck.

    If you change the primary key value, it should not be the primary key.

    This is true in the design of database relational regardless of how access you the data. In addition, EO don't like if you change the primary key value.

    Have you considered adding a surrogate key (use a sequence) and make your PK course a unique key?

    John

  • When you change an item type only display in hidden element its value changes from any value in value null. Why?


    Dear reading

    When to change a display one item type in the hidden element its value changes from null value any value . Why?

    I would like to use the result of the query in the hidden item, as well as to display it in report footer.

    shortly the displayed element can read footer bu area hidden point cannot be viewved in the footer box. Why?

    footer

    & P11_DISPLAY_ONLY_ITEM.

    footer

    & P11_HIDDEN_ITEM.  )

    (site of apex.oracle.com Application Express 4.2.5.00.08)

    concerning

    Enformatik wrote:

    in the part of the properties point setting its source type as query retune unique value;

    but when you set its value to the calculation (before header) it works correctly.

    It is the expected behavior. The values defined in the properties of the Source element / by default are only put in the controls of the page displayed in the browser, not in session state. To refer to a session-state item value (as in a & P11_HIDDEN_ITEM. substitution of static text) then the value must be set in session state in a calculation or process that runs before the substitution reference is returned.

    Setting the value using a calculation is the right way to do it.

  • FM 10 crashes when you change an equation index

    Get the following error message when you change a clue in an equation:

    fmError10024.gif

    The dump of the error is:

    = Begin header =.

    Internal error: 10024, 7687848, 7688138, 10076935

    FrameMaker 10.0.2 for Intel

    Build: 10.0.2.419

    Window system: MSWindows

    Operating system: Windows NT 6.1 (major.minor.build: 6.1.7601 Service Pack 1)

    Generated on: March 6, 2012 11:34:15

    File: [REMOVED]\AppData\Roaming\Adobe\FrameMaker\10\FrameLog_12.03.06_11.34.15.txt

    = End of the header.

    [Deleted by the host details]

    Does anyone have an idea on how to fix this?

    Uninstalled SDL AuthorAssistant: this fixes the problem!

  • MySQL Insert with autoincremented primary key

    I did not before MySQL.  I try and hit a roadblock soon enough.

    I would like to insert new records and have the auto-generated primary key / auto-increment.

    So, I have attached a few screenshots.  The first is a screenshot of the MySQL settings for the table that I'm writing.  The second is the Labview code that I threw as well as I am trying to run.

    The complete of the error I get is:

    > Database Connection.viADO error: 0x80004005
    Exception occurred in the Microsoft OLE DB provider for ODBC drivers: [MySQL] [ODBC 3.51 Driver] [mysqld - 5.7.11 - log] field 'techniciansID' didn't is not a default value to create a NI_Database_API.lvlib:Rec - Command.vi-> NI_Database_API.lvlib:Cmd Execute.vi-> NI_Database_API.lvlibData.vi B tools insert-> Connection.vi in the database

    I know that this error indicates that the techniciansID has no default value and he won't write because of it... but since it is an AutoIncrement field, it seems like it should work.

    Any help would be appreciated.  Thank you

    Thad

    Setting to 0 did not work, but I understand it.  For some reason any when I was refreshing my tables in MySQL server and using the "Forward Engineer" feature, the changes were not multiplication.  I had to drop the schema of the database (attached image) and then do an "engineer forward."  I made the changes, but the tables and the columns still had the attributes of origin... guess they cannot be updated by the script during execution.

    After doing this and the original settings I had (autoincremented primary key), the insert works in MySQL and Labview.

    Thanks for all the answers.  They made me think and check some things I didn't have before.

    -Thad

  • 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')



  • modify a primary key constraint

    Hello

    I start with oracle, and I have two doubts which cannot handle after a search on the internet.

    1. it is possible to do an ALTER TABLE for a DEFAULT CONSTRAINT?. Maybe you think that the question should be in a different way like this: oracle database takes the default condition as a constraint?. As far as I know, not done that.

    2. it is possible, with an ALTER TABLE to CHANGE a CONSTRAINT of a PRIMARY KEY, to add another field more?

    I searched the internet, but I have not found a clear answer. I use oracle 10g express edition.


    Thank you very much.

    P.D.:sorry for my English, it is not very good.

    #2-you can not 'add a column to the primary key of a table constraint' with a single ALTER, but you can delete and re-create the constraint primary key (including the additional column).

    13:25:26> create table t1 (a number primary key, b number, c number );
    
    Table created.
    
    Elapsed: 00:00:00.09
    13:25:46> alter table t1 drop primary key;
    
    Table altered.
    
    Elapsed: 00:00:00.06
    13:25:47> alter table t1 add primary key (a,b);
    
    Table altered.
    
    Elapsed: 00:00:00.09
    

    But you will not be able to drop the primary key of a table index.

    13:25:47> create table t2 (a number primary key, b number, c number ) organization index;
    
    Table created.
    
    Elapsed: 00:00:00.03
    13:25:59> alter table t2 drop primary key;
    alter table t2 drop primary key
    *
    ERROR at line 1:
    ORA-25188: cannot drop/disable/defer the primary key constraint for
    index-organized tables or sorted hash cluster
    
    Elapsed: 00:00:00.00
    13:25:59> 
    

    #1-I'm not sure I understand your question, but you can change a table column to have a default value. This isn't a "constraint", but a default value. It has an effect when you perform an insert which does not include this column.

    13:31:23> alter table t1 modify (c default 3.14);
    
    Table altered.
    
    Elapsed: 00:00:00.04
    13:31:24> insert into t1 (a,b,c) values (1,2,3);
    
    1 row created.
    
    Elapsed: 00:00:00.01
    13:31:24> insert into t1 (a,b,c) values (4,5,NULL);
    
    1 row created.
    
    Elapsed: 00:00:00.00
    13:31:24> insert into t1 (a,b) values(6,7);
    
    1 row created.
    
    Elapsed: 00:00:00.01
    13:31:24> select * from t1;
    
             A          B          C
    ---------- ---------- ----------
             1          2          3
             4          5
             6          7       3.14
    
    3 rows selected.
    
    Elapsed: 00:00:00.18
    
  • 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

  • How to create an entity with more than one primary key.

    Hello

    JDeveloper Version 11.1.2.4.0

    I am trying to create an entity object based on a table with 5 columns. The combination of them is unique.

    I do the five columns of primary keys, but when I delete a line I: RowAlreadyDeletedException, although always the line exists in the database.

    Also displaying the view sometimes I get Houston-25019: line entity oracle.jbo.Key [1 key 2 null null NULL].



    How to create an entity based on one object several columns in the primary key?

    I don't want to add an additional column to a primary key, because this table is used in many PL/SQL procedures, and I'm not sure that this will not affect the.

    Also using Rowid as a primary key should be avoided.

    Kind regards

    Pamela.

    As I said, the framework is not like that

    Check this old (but still relevant) blog of Sung Im on Table Whose Primary Key entity object can be NULL

    describing the reason behind the behavior you're seeing and the way around.

    Or you use the secondary key rather as described here Wael Abdeen Blog, how to look at the views - part 2 | Oracle ADF as a secondary key composed of more then one column can have null values.

    Timo

  • Update a primary key of type char data

    Hello
    Not a guy to oracle technology. but am forced to work on a query that is a basic requirement.

    I have a table that has a composite primary key values (6 columns).
    Of these, I've updated 1 specific column, which is a char data type.

    I tested after writing my logic as a query, threw it [the Unique constraint violated schema.tablename];

    So I gave it a query simple base to test it yet, still get the same error.

    Query such as:

    Update table_name set Column1 = "100000" where column2 = 'BOMBAY '; (Column1 is the primary key of type char)

    Even if it did not work.
    Now a doubt arises, a column is a primary key of type Char can be modified? or is it not possible at all to do?

    Note: I made sure only am not updated with a duplicate value;


    Thank you.

    Published by: 966353 on October 18, 2012 12:01

    While you never need to update a primary key (regardless of the type of data), it is possible to do. If you get an error ORA-00001 indicating that a unique constraint has been violated and the unique constraint that is violated is associated with the primary key of the table (I'm guessing that this is the case according to your description of the error), implying strongly that the update would result in duplicate rows. Your UPDATE statement updates more than 1 row? If so, how do you determine when the update is complete there will be no duplicate lines?

    Justin

  • What is the use of the associated columns?

    In the model business, logical columns are associated with a dimension level. But the columns are nether primary key or used for display. What is the purpose of these related columns?

    To expand our example a little more.

    You have one day sun, as well as a month Dim. Your month logical name column is mapped to two tables through sources different logical table. Your levels of content is defined accordingly for these LTS.

    You have a grain day fact table and a grain months aggregated fact table. You have a measure ($ quantity, no matter) mapped to two physical tables through two LTS with levels of content defined (as the time Dimension).

    So when you query the name of the month and in Dollars, the BI server uses the global table as it can serve both the attribute of the dimension and the measure of the global table. He knows its more effective because the ratio between the number of items that you have defined in the hierarchy told him about 30 times less data on the whole of the month, by the ratio of 365 days 12 months ago.

    So far so good.

    Allows to introduce more dimensions, a.n.other dimension is attached to the base of fact table but NOT in the whole month. You model everything as per normal, when you drop this dimension in your report, the BI server recognizes that there is no comprehensive source that can give the right answer in all the areas required in the report falls to the next best form requested in the report, grain in this case simple, it would default to the base's table because it is only capable of serving the month and all fact table the attributes of the other dimension. In more complex models, you may have a few tables of aggregation with two more high grain (high) or less dimensionality (fewer lines). Setting levels LTS the existence of physical layer Joins tell the BI server which can be attached to the dimensioning, it tells what tables of aggregation would be more effective.
    Not to be confused with the establishment of a limit on a measure - it's something different (level total function, % of the year etc etc.)

    I have it?

    These might help:
    http://gerardnico.com/wiki/dat/OBIEE/fragmentation_level_based
    http://www.rittmanmead.com/2006/11/aggregate-navigation-using-Oracle-BI-server/
    http://obiee101.blogspot.com/2008/11/OBIEE-making-it-aggregate-aware.html

    Let us know if any more Q

Maybe you are looking for