About Unique Key

Hi all,
I have a table with only one col..called...Rno...with unique..constraint.
In this table i can enter more than one null value...If i can enter more than one null value...the concept of unique may get false...
please explain whether a unique key accept more than one null value or not..
Thanks and regards
MKK

NULL = NULL is always false actually you mean
NULL = NULL is always null
add a constant to your index and enjoy unique nulls :-)
SQL> create table t(x number);
Table created.
SQL> create unique index i on t(x,1);
Index created.
SQL> insert into t values(1);
1 row created.
SQL> insert into t values(2);
1 row created.
SQL> insert into t values(2);
insert into t values(2)
ERROR at line 1:
ORA-00001: unique constraint (SCOTT.I) violated
SQL> insert into t values(null);
1 row created.
SQL> insert into t values(null);
insert into t values(null)
ERROR at line 1:
ORA-00001: unique constraint (SCOTT.I) violatedMessage was edited by:
Laurent Schneider
the technical reason why unique index i on t(x) is not unique is that nulls are not indexed

Similar Messages

  • 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.

  • Unique Key Violation error while updating table

    Hi All,
    I am having problem with UNIQUE CONSTRAINT. I am trying to update a table and getting the violation error. Here is the over view. We have a table called ActivityAttendee. ActivityAttendee has the following columns. The problem to debug is this table has
    over 23 million records. How can I catch where my query is going wrong?
    ActivityAttendeeID INT PRIMARY KEY IDENTITY(1,1)
    ,ActivityID INT NOT NULL (Foreign key to parent table Activity)
    ,AtendeeTypeCodeID INT NOT NULL
    ,ObjectID INT NOT NULL
    ,EmailAddress VARCHAR(255) NULL
    UNIQUE KEY is on ActivityID,AtendeeTypeCodeID,ObjectID,EmailAddress
    We have a requirement where we need to update the ObjectID. There is a new mapping where I dump that into a temp table #tempActivityMapping (intObjectID INT NOT NULL, intNewObjectID INT NULL)
    The problem is ActivityAttendee table might already have the new ObjectID and the unique combination.
    For example: ActivityAttendee Table have the following rows
    1,1,1,1,NULL
    2,1,1,2,NULL
    3,1,1,4,'abc'
    AND the temp table has 2,1
    So essentially when I update in this scenario, It should ignore the second row because, if I try updating that there will be a violation of key as the first record has the exact value. When I ran my query on test data it worked fine. But for 23 million records,
    its going wrong some where and I am unable to debug that. Here is my query
    UPDATE AA
    SET AA.ObjectID = TMP.NewObjectID
    FROM dbo.ActivityAttendee AA
    INNER JOIN #tmpActivityMapping TMP ON AA.ObjectID = TMP.ObjectID
    WHERE TMP.NewObjectID IS NOT NULL
    AND NOT EXISTS(SELECT 1
    FROM dbo.ActivityAttendee AA1
    WHERE AA1.ActivityID = AA.ActivityID
    AND AA1.AttendeeTypeCodeID = AA.AttendeeTypeCodeID
    AND AA1.ObjectID = TMP.NewObjectID
    AND ISNULL(AA1.EmailAddress,'') = ISNULL(AA.EmailAddress,'')

    >> I am having problem with UNIQUE CONSTRAINT. I am trying to update a table and getting the violation error. Here is the over view. We have a table called Activity_Attendee. <<
    Your problem is schema design. Singular table names tell us there is only one of them the set. Activities are one kind of entity; Attendees are a totally different kind of entity; Attendees are a totally different kind of entity. Where are those tables? Then
    they can have a relationship which will be a third table with REFERENCES to the other two. 
    Your table is total garbage. Think about how absurd “attendee_type_code_id” is. You have never read a single thing about data modeling. An attribute can be “attendee_type”, “attendee_code” or “attendee_id”but not that horrible mess. I have used something like
    this in one of my busk to demonstrate the wrong way to do RDBMS as a joke, but you did it for real. The postfix is called an attribute property in ISO-11179 standards. 
    You also do not know that RDBMS is not OO. We have keys and not OIDs; but bad programmers use the IDENTITY table property (NOT a column!), By definition, it cannot be a key; let me say that again, by definition. 
    >> ActivityAttendee has the following columns. The problem to debug is this table has over 23 million records [sic: rows are not records]<<
    Where did you get “UNIQUE KEY” as syntax in SQL?? What math are you doing the attendee_id? That is the only reason to make it INTEGER. I will guess that you meant attendee_type and have not taken the time to create an abbreviation encoding it.
    The term “patent/child” table is wrong! That was network databases, not RDBMS. We have referenced and referencing table. Totally different concept! 
    CREATE TABLE Attendees
    (attendee_id CHAR(10) NOT NULL PRIMARY KEY, 
     attendee_type INTEGER NOT NULL  --- bad design. 
        CHECK (attendee_type BETWEEN ?? AND ??), 
     email_address VARCHAR(255), 
    CREATE TABLE Activities
    (activity_id CHAR(10) NOT NULL PRIMARY KEY, 
    Now the relationship table. I have to make a guess about the cardinally be 1:1, 1:m or n:m. 
    CREATE TABLE Attendance_Roster
    (attendee_id CHAR(10) NOT NULL --- UNIQUE??
       REFERENCES Attendees (attendee_id), 
     activity_id Activities CHAR(10) NOT NULL ---UNIQUE?? 
      REFERENCES Activities (activity_id)
     PRIMARY KEY (attendee_id, activity_id), --- wild guess! 
    >> UNIQUE KEY is on activity_id, attendee_type_code_id_value_category, object_id, email_address <<
    Aside from the incorrect “UNIQUE KEY” syntax, think about having things like an email_address in a key. This is what we SQL people call a non-key attribute. 
    >> We have a requirement where we need to update the ObjectID. There is a new mapping where I dump that into a temp table #tempActivityMapping (intObjectID INTEGER NOT NULL, intNewObjectID INTEGER NULL) <<
    Mapping?? We do not have that concept in RDBMS. Also putting meta data prefixes like “int_” is called a “tibble” and we SQL people laugh (or cry) when we see it. 
    Then you have old proprietary Sybase UODATE .. FROM .. syntax. Google it; it is flawed and will fail. 
    Please stop programming until you have a basic understanding of RDBMS versus OO and traditional file systems. Look at my credits; when I tell you, I think I have some authority. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Problems Engineering Surrogate Primary Key with Unique Key

    SDDM 3.3.0.747 with 2 problems (at least so far).  I am hoping that the problem is with this SDDM rookie and I have overlooked some setting. PROBLEM 1 I don’t want to start a religious debate about surrogate vs. natural keys but I am having a problem engineering both correctly from the logical model.  I am a rookie when it comes to SDDM but have many years of experience with Designer. By default I like to have both a natural UID  (UK) and a surrogate key based primary UID (PK) which is used for foreign keys.  The problem I am having with engineering is I can successfully engineer the surrogate PK’s, engineer the FK’s using the PK’s but cannot get the unique key to contain the surrogate keys in the child table.  If I check the identifying property in the relations, the PK columns and the UK columns are included in the child PK and the UK contains no columns. The Setup I have defined two reference entities, PROBABILITY and SEVERITY with natural unique keys defined.  I also have a child entity RISK_ASSESMENT with relationships back to the PROBABILITY and SEVERITY entities and both have the “Use surrogate keys:”: check box checked.  The unique key for the RISK_ASSESMENT entity includes the relationships back to PROBILITY and SEVERITY.  None of the entities have a PK or surrogate key defined and they all have the “Create Surrogate Key” check box checked.  In addition the following preferences are set: Data Modeler/Model/Logical   NOT Checked - Use And Set First Unique Key As Primary Key   NOT Checked – Name – Keep as the name of the Originating attribute   Checked – Entity Create Surrogate Key   Checked – Relationship Use Surrogate Key PROBLEM 2 When the foreign key columns are engineered I want the names to have a prefix “FK_” but they don’t.  Templates are set as follows: Data Modeler/Naming Standard/Templates   Foreign Key:  FK_{child}{parent}   Column Foreign Key:  FK_{ref column} Engineer to Relational Model/General Options   Checked - Apply name translation Marcus Bacon

    I have been switching between SD 4 EA1 and SDDM 3.3 trying to get things to work and trying out the template table for adding audit columns (really nice!).
    Concerning Problem1.  No matter what settings I use and whether I use SDDM 3.3 or SDI cannot get the FK columns to be included in the UK even though the relations are included in the UID in the entitty.  When I open the properties of the child table and click on the naming standards button and click ok it complains that the UK is not complete.  I add the FK columns to the UK and all is well including the naming standards.
    Concerning Problem 2.  Sometimes it engineers the names for FK's from the template and sometimes it doesn't.  Didn't see a pattern.  Gave up trying and used Naming Standards button.  I still had to change a few.
    The good new is, that after make changes needed in UK's and Column names of 18 tables, I know have everything deployed to Test except FK Indexes.  I think I have to do those by hand.
    Marcus Bacon

  • Urgent expalantion reqired about foreign keys

    we are doing data migration project and we have get data from different regions data in flat files, but we have problem below like:
    i am facing a problem to declare unique constraints, because in some files column should be in number data type and same file from some other region is varchar2 but these two columns are unique ,these two columns don't having the any duplicate values.
    can i take this column data type in varchar2?
    why because if i am taking number type it cant accept varchar2
    any suggestions.................
    Regards,
    sh

    sh wrote:
    we are doing data migration project and we have get data from different regions data in flat files, but we have problem below like:
    i am facing a problem to declare unique constraints, because in some files column should be in number data type and same file from some other region is varchar2 but these two columns are unique ,these two columns don't having the any duplicate values.
    can i take this column data type in varchar2?
    why because if i am taking number type it cant accept varchar2
    any suggestions.................
    Regards,
    shNot really sure i understand your question. If you have 2 data sources and 2 different data types for the same type of data then you'd want to ensure you do a TO_NUMBER on the character representation of the data to ensure you strip out any non-printing characters like tabs or spaces.
    If that's not your problem, please try to be a little more clear. Your subject mentions you have an urgent problem about foreign keys and i find nothing to support your claim of urgency, nor foreign keys, within the subject of your question.
    Cheers,

  • Some basic questions about foriegn key , and relationships.

    Hi
    Thank you for reading my post
    I read some documents about foreugn key and tables relation ships.
    but i still can not understnad some stuff.
    1-when we have a foreign key , we have two tables that we want to relate them together
    in a way that one of ? table columns forced to be a value from ?? table column.
    what is name of those two tables , i saw , child-parent , ..... which confuse me.
    can some one please tell me correct name of those two tables ?
    2-some times we need some kind of master details relation like :
    one-to-many : i this case MANY table will have a column to point a record in ONE table , can this relation be a foreign key relation ?
    3-we can achieve many-to-many relation only by using a helper table to host both tables primary keys in a record to relate them together.
    can you point me to some resources that help me to find answers to this questions ?
    or explain them to me ?
    thank you for your time.

    These are critical database basics that you need to understand. I would seriously recommend getting some study in, because proper relational database design relies on the basic principle of data and relationships and a process called normalization.
    In reality, you only really need one gigantic table to host data. It would include everything you would want to know about something - let's take a sales order for example. You would have to record the customer's name, address, etc. along with every item they ordered, etc. You would have a HUGE table full of data that appeared over and over and over again. This is bad design for two basic reasons: it is difficult to query, and it is very easy to have minor mistakes like capitalization or alternate spellings that prevent things from matching up properly. For example, let's say Bob orders 40 widgets and 40 digits. In our hypothetical table, we could put it in as Bob - 40 widgets and Robert - 40 digits. See how confusing this can get even in a simple example? And let's say you wanted to correct all of Robert's orders to say Bob and you found out there were 40 orders from "Robert" How would you know which ones to change?
    The process of normalization helps to reduce the chance for these types of errors in addition to creating a good basis for indexes. You normalize the data by creating sets of parent/child tables with a "key" value to match them. In our hypothetical situation, you could create a table for orders and a table for customers. In the customers table you give all the detail for the customer in one place, and you assign each customer a unique number or ID. In the orders table we add the customer ID (NOT the name) and we ensure that we are getting the customer we want, in addition to saving a lot of space and eliminating redundancy. In our example, the customers table is the "parent" table and the orders table is the "child" table. The child table references the unique entries in the parent table via that id. That reference is referred to as a foreign key. The foreign key in the child table points back to the original and complete record in the parent table and eliminates the redundancy of keeping all that extra data for every order. Foreign keys in child tables always refer to a primary/unique key in the parent field.
    That help?

  • Unique key violation i.e. primary key violation in JSF page

    Hi, I am using Jdeveloper 11.1.1.5.0 and working with adf fusion web application. I have created entity object and view object. In view object I have primary key and I have set it's type to DB sequence. THe problem is though the attribute is DB sequence. IN JSF page it show unique key violation i.e. primary key violation. Please help me

    So, do you have a trigger in the database that updates the value of the primary key? Or do you assign the value in some other way?
    You can check [url http://download.oracle.com/docs/cd/E16162_01/web.1112/e16182/toc.htm]the docs for information about the ways it can be done.

  • Java OracleXML putXML & non-unique keys

    I am using the XML SQL Utility for java on the client (NT) to insert multi-row XML documents into an ORACLE table. Everything works fine until I hit a row with a non-unique key. It appears insertXML throws an error and the insert stops at that point. Rows after the non-unique key row are not processed.
    Is there any way to process all rows of an XML document, telling me how many read, how many inserted, how many not processed??
    Also, what about update capabilities? Presently I am not needing to update from XML into ORACLE, all I can do now is insert.
    Thanks in advance,
    Rick

    One way to make this work would be to take advantage of Oracle8i's INSTEAD OF triggers on views.
    Basically, you would:
    (1) CREATE VIEW someview
    AS SELECT * FROM sometable;
    (2) CREATE TRIGGER someview_trig
    INSTEAD OF INSERT ON someview
    DECLARE
    BEGIN
    -- Check for existence of
    -- row using the value of
    -- :NEW.pk_column_name
    IF (you-found-an-existing-one) THEN
    -- Do something here like
    -- NULL; to ignore the insert altogether
    -- or possible an INSERT into
    -- and EXCEPTIONS table...
    ELSE
    INSERT INTO sometable
    VALUES (:NEW.column1, ..., :NEW.columnn);
    END IF;
    END;
    (3) Then point XML SQL Utility at someview
    instead of sometable
    and you'll be in business, as they say.

  • Assign unique key

    Hi,
    we have the requirment to add an unique key to each position in the planing item. The idea is now, to define a number range object to get a unique number. When the user is adding an new position in his planning sheet an InfoObject should get get this number. But how can I fill this this InfoObject with a number from number range object. I was thinking about useing a Fox-Formula and calling a function modul, but I has no idea how to fill a InfoObject in the planning layout. Maybe someone of you has an idea?
    Thanks,
    Thomas

    Hello Thomas,
    I had done it for a layout, but not for a single line.
    I had a ztable with columns counter &  username.
    Call a Fox function which has a Call function, which in turn reads the ztable and increments it by 1
    and
    SAVE_DATA.
    Hope it helps,
    Krishna

  • Cannot create DDL for Unique Key

    I have a relational model with a unique key constraint. When I go to Export -> DDL File for my model, and look at the PK and UK constraints tab for "DDL Generation Options", the UK is checked. But upon inspecting the generated DDL file, it is not being generated! The target database in Oracle 11.1 and I am using DM 4.0.3.853.

    Hi,
    Very strange.  Is there anything unusual about the Table or its Unique Key column(s)?
    Is everything else being generated as expected?
    Are there any relevant error messages in the log?  (You can use External Log on the View menu to display the log.)
    David

  • Listener for Unique Key in coherence Cache

    Hi Experts,
    I am using Oracle Coherence in one of my project and I am facing a Performance issue .Here is my scenario,
    Thie is my Coherence cache structure
    UniqueKey         <Hive data>
    D1                     Hive Data1         
    D2                     Hive Data2
    D3                     Hive Data3
    Each Unique Key is for user Session. My application is a single Sign on with multiple applications involved.
    The Coherence cache can be updated by any application/sub applications. When ever there is a change in my a user hive Data I need to update. My current implementation is
    I get all the data (Map) from the Coherence Cache (Named Cache).
    Look for the specific user's key
    Hence there is a performance issue when ever i retrieve/set the hive data
    Is there a default Listener/methodology which I can use in Oracle Coherence ?

    Thanks Jonathan for your timely response will look into the Map event, but just a quick question
    Map<Object, Map<Object, Object>> updateUserData = (HashMap) namedCache.get(uniqueKey);
    So this is how i retrieve the user data from the NamedCache. What it returns is a Map .....and any change to this current daykey is what the user is worry about.
    The addListener() on the ObservableMap will  start to listen on any event happening at the all key in the namedCache.I am looking for something like a listener/logic which looks only the for this uniqueKey for this user session.
    Will look into the Map Event in detail.
    Thanks Again,
    Sarath

  • Primary/Unique key for GL_IMPORT_REFERENCES

    Hi all,
    We are on EBS11.5.10. I have the following requirement. I need to put a snapshot log on GL_IMPORT_REFERENCES which we will use to interface data to out reporting environment. Therefore i need to set a primary key on GL_IMPORT_REFERENCES, this is required for creating the snapshot log.
    Can anyone suggest what combination of fields would be unique for this table, as no unique key is set.
    TIA

    mma,
    but do you tie them in with ETL? or they're simply uniqe auto-number-like?
    Thanks
    I just found this:
    http://datawarehouse.ittoolbox.com/groups/technical-functional/informatica-l/re-about-oracle-bi-and-fact-tables-and-image-tables-1515935
    Looks like there's a new methodology for extending the DWH. I'm still looking into this, but I still think auto-numbering ROW_WID is a good idea.
    Mma, perhaps - could you provide me with an example or two to present this change. Thanks

  • Rich/Narendran - uh oh!! Does the shared buffer require unique key per id??

    Rich/Narendran -
    Something just occurred to me:
    Does "shared buffer" mean that more than one user can be sharing the same buffer, or is the buffer unique to each user session and is merely "shared" between work processes?
    If multiple users are sharing the same "shared buffer", then I can assign a unique key when I export the data in the first exit.
    But short of using a custom z table, how can I figure out what this key is in the second exit?  I can't "save" the key anywhere, because that's the problem in the first place ...
    I'm hoping that you'll tell me that the "shared buffer" is shared between different work processes for the same user, and not among different users as well !!
    Thanks for whatever you can tell me about this.
    djh

    Hi Naren -
    I've worked on DBMS's in the past where you could pick up a user's thread # in addition to his or her ID - if SAP had anything like that then that would do the job.  Maybe there's a "hidden" sy-something that actually gives you the unique thread ID ... ????
    djh

  • JSP unique key exception error

    hi guys,
    plz help me, i have small pblm in my jsp page,
    I made 2 columns as unique key and 1 column as primary key in my database(mySQL)....
    Unique Keys are Username and email...Wen I enter same username the db throws error...but I have to show this same error in the alert box on my insertion jsp page,
    How do I go about it????

    In java code:
    You catch the exception.
    You get the message from the exception.
    You save the message somewhere - eg in a request attribute.
    Forward to a JSP page to render the response
    The JSP page should check for the existence of the "error" request attribute, and produce javascript code on the page that will alert it when the page is loaded.

  • 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

Maybe you are looking for