Column check constraint cannot reference other columns  !????

Hello,
why it don't work?
I have read that Check Constraint must work with other columns. What is the Problem here (KK_ID)?
DROP TABLE Pat CASCADE CONSTRAINTS;
CREATE TABLE Pat
PAT_ID           NUMBER(12) NOT NULL
          CONSTRAINT pat_id PRIMARY KEY initially immediate,
NAME           VARCHAR2(50)NOT NULL initially immediate,
date_b          DATE NOT NULL initially immediate,
PRIVAT_KNZ VARCHAR2(20)
          CONSTRAINT PRIVAT_KNZ_ CHECK (UPPER(PRIVAT_KNZ) in ('Y','N')) initially deferred,
KK_ID           NUMBER(10)
          CONSTRAINT KK_ID CHECK      ((UPPER(PRIVAT_KNZ) in ('N')) AND KK_ID is NOT NULL) OR ((UPPER(PRIVAT_KNZ) in ('Y')),
          CONSTRAINT REF_KEY_KK FOREIGN KEY (KK_ID)
          REFERENCES Tab2 (KK_ID) initially deferred          
The field KK_ID must became a value if PRIVAT_KNZ has a 'N'. If PRIVAT_KNZ has a value 'Y' then can KK_ID have a NULL or a value.
ERROR__________________________________________________________________
DROP TABLE Patient CASCADE CONSTRAINTS
ERROR at line 1:
ORA-00942: table or view does not exist
          CONSTRAINT KK_ID CHECK      ((UPPER(PRIVAT_KNZ) in ('N')) AND KK_ID is NOT NULL) OR ((UPPER(PRIVAT_KNZ) in ('J')),
ERROR at line 12:
ORA-02438: Column check constraint cannot reference other columns
Thank you in advance!!!!
Andrej

Thank You very much!
It works great!
But i don't understand why i must put coma, after
KK_ID                NUMBER(10) NUll REFERENCES KRANKENKASSE ,
And then follows the contstraint? How can i see, that constraint KK_ID belongs to column KK_ID?
How can i make,than the constrain belongs to definition of Columns KK_ID?
Thank you in advance!
DROP TABLE Krankenkasse CASCADE CONSTRAINTS;
CREATE TABLE Krankenkasse
KK_ID                NUMBER(10)
                    CONSTRAINT KK_id_PR PRIMARY KEY,
BEZEICHNUNG          VARCHAR2(20)
INSERT INTO Krankenkasse VALUES(1, 'AOK');
INSERT INTO Krankenkasse VALUES(2, 'Techniker');
INSERT INTO Krankenkasse VALUES(3, 'Barmer');
DROP TABLE Patient CASCADE CONSTRAINTS;
CREATE TABLE Patient
PATIENTEN_ID           NUMBER(12) NOT NULL
     CONSTRAINT pat_id PRIMARY KEY initially immediate,
NACHNAME           VARCHAR2(50)NOT NULL initially immediate,
VORNAME           VARCHAR2(20)NOT NULL initially immediate,
ADRESSE           VARCHAR2(100)Null,
GEB_DATUM           DATE NOT NULL initially immediate,
PRIVAT_KNZ           VARCHAR2(20)
               CONSTRAINT PRIVAT_KNZ CHECK (UPPER(PRIVAT_KNZ) in ('J','N'))
               initially deferred,
KK_ID                NUMBER(10) NUll REFERENCES KRANKENKASSE,
               CONSTRAINT KK_ID CHECK
               ((Upper(PRIVAT_KNZ) in ('N') AND KK_ID is NOT Null) OR (UPPER(PRIVAT_KNZ)in ('J')))
INSERT INTO PATIENT VALUES(1,'Schmidt','Bernd','Adresse1', TO_DATE('01101965', 'DDMMRRRR'),'N',1);
INSERT INTO PATIENT VALUES(2,'Mueller','Heiko','Adresse2', TO_DATE('15061955', 'DDMMRRRR'),'N',1);
INSERT INTO PATIENT VALUES(3,'Becker','Josef','Adresse3', TO_DATE('03101947', 'DDMMRRRR'),'J',2);
INSERT INTO PATIENT VALUES(4,'Winter','Paul','Adresse4', TO_DATE('01051933', 'DDMMRRRR'),'J',Null);
INSERT INTO PATIENT VALUES(5,'Winter','Paul','Adresse4', TO_DATE('01051933', 'DDMMRRRR'),'N',Null);
commit;
__________________________________________________________________________

Similar Messages

  • Using a CHECK constraint to check for minimum age

    Is it possible to use a check constraint in a table to check whether a person meets a minimum age? For example, if a person is registering as a member, I want to make sure the person is at least 18 years old (contract age), so that a minor doesn't try to register as an adult.
    From what I understand, I can't use SYSDATE in a check statement. Is there another way? What about using CURRENT_DATE and FLOOR to form a statement for this check?
    Here's the DDL for the table (table is not fully decomposed to keep it simple; "dob" represents "Date of Birth" and "zipcode" is a FK to this table):
    CREATE TABLE member     (
    member_id     VARCHAR2(10)     NOT NULL,
    fname          VARCHAR2(30)     NOT NULL,
    lname          VARCHAR2(30)     NOT NULL,
    address1     VARCHAR2(50),
    address2     VARCHAR2(25),
    zipcode     NUMBER(5)     NOT NULL,
    phone          VARCHAR2(15)     NOT NULL,
    dob          DATE          NOT NULL,
    gender     CHAR(1)          NOT NULL,
    CONSTRAINT ck_gender     gender IN ('M','F'),
    CONSTRAINT pk_member     PRIMARY KEY (member_id),
    CONSTRAINT fk_member_zipcode (zipcode) REFERENCES zipcode)
    Thanks for your help.

    Like SYSDATE, CURRENT_DATE is a non-deterministic function and so cannot be used in this context.
    From the manual:
    Restrictions on Check Constraints
    You cannot specify a check constraint for a view. However, you can define the view using the WITH CHECK OPTION clause, which is equivalent to specifying a check constraint for the view.
    The condition of a check constraint can refer to any column in the table, but it cannot refer to columns of other tables.
    Conditions of check constraints cannot contain the following constructs:
    Subqueries and scalar subquery expressions
    Calls to the functions that are not deterministic (CURRENT_DATE, CURRENT_TIMESTAMP, DBTIMEZONE, LOCALTIMESTAMP, SESSIONTIMEZONE, SYSDATE, SYSTIMESTAMP, UID, USER, and USERENV)
    Calls to user-defined functions
    Dereferencing of REF columns (for example, using the DEREF function)
    Nested table columns or attributes
    The pseudocolumns CURRVAL, NEXTVAL, LEVEL, or ROWNUM
    Date constants that are not fully specified
    To achieve this sort of checking you will need to use a trigger

  • How to Disable check constraint in cronacle

    Hi All,
    We found that one job failed in cronacle with the following error
    *ORA-20800: JCS-02138: problem with parameter "PRINT_BANNERPAGE"
    SAP recommended the soultion saying
    Disable the "Check Constraints" that are being used in the scripts currently in Cronacle or apply some patch.So we want to explore the first option i.e check constraint
    Can any one help me in Regarding the check constraints.
    Thanks in advance
    shylaja

    Hi,
    Scripts can have check constraints and reference contraints, you will find these under the script properties when you edit the script.
    I would set the constraint to optional, meaning that you still have the dropdown available but it no longer complains if it does not like the chosen value.
    Regards,
    Anton.

  • Domain check constraint using column name

    Hello,
    in the domain administration of Data Modeler, I defined a domain "age",
    and set it to logical type "Integer". Now I want to define a check constraint
    for that domain, saying, that every attribute of domain "age" must have
    values greater than 18.
    But how should I specify the column name for that check-constraint, since
    I cannot know now, to which columns this domain will be applied to, and
    these columns could have different names!
    I tried {column} > 18 and hoped that {column} might be substituted by
    the appropriate column name when generating DDL but it was not,
    the DDL contained "check ( {column} > 18 ) which did of course not work.
    Does anybody have an idea?

    Thanks a lot, that solved the problem. I noticed additionally, that %COLUMN% is case sensitive, so %COLUMN% gets substituted by the column name in the DDL, while %column% does not.

  • Tabular Form Validation: Comparing Two Columns vs Check Constraint

    What is the best approach for validating that one column needs to be greater than another column in a tabular form when attempting to save. (E.g. An effective date and expirey date column. The expirey date column >= effective date column)
    At the moment I have a check constraint on the two columns at the database level which is fine but it returns and passes up a pretty cryptic (from a business user perspective) unfriendly message to the user as follows:
    Error in mru internal routine: ORA-20001: Error in MRU: row= 1, ORA-02290: check constraint (IDMTC.ADDRESS_TYPE_CON) violated, update "IDMTC"."ADDRESS_TYPE" set "ID" = :b1, "CODE" = :b2, "NAME" = :b3, "LOV_SORT_ORDER" = :b4, "DESCRIPTION" = :b5, "EFFECTIVE_DATE" = :b6, "EXPIRY_DATE" = :b7 where "ID" = :p_pk_col
    Unable to process update.
    Is there a way to inject, detect and/or replace this with a friendlier business user message? I have confirmed that the "Unable to process update." text at the bottom below the MRU Internal routine error raised from my check constraint is the process error message for my Apply MRU process.
    I was hesitating going down a larger page level validation where I loop through the tabular form array and/or inject some client side Javascript.
    Any advice? Have I simply overlooked some tabular form options for validating using cross column values?
    Thanks,
    Jeff

    Jeff..Thanks for the response.
    However because I am working in a tabular form at design time I don't know which controls I can reference in a dynamic action, or custom Javascript routine other than selecting all elements in a column using JQuery, etc.
    I have decided to go with for the time being an approach I found here: doing validation on tabular form
    My code ended up looking something like and was entered into a page level validation as a PL/SQL function body returning error text.:
    DECLARE
    l_error VARCHAR2 (4000);
    BEGIN
    FOR i IN 1 .. apex_application.g_f02.COUNT
    LOOP
    --If Expiry date is older then effective date
    IF nvl(apex_application.g_f08 (i), to_date('31-DEC-9999', 'dd-mon-yyyy')) < apex_application.g_f07 (i) THEN
    l_error :=
    l_error
    || '</br>'
    || 'Row '
    || i
    || ': Expiry date must be greater than effective date '
    || ' for maintenance item name: '
    || apex_application.g_f03 (i);
    END IF;
    END LOOP;
    RETURN LTRIM (l_error, '</br>');
    END;
    I had been hoping with Apex 4+ that there was additional native functionality to do this type of validation or somehow be able to reference a column or control name instead of a generic array column so that my code was better self documenting.
    It works for now...but would love to revisit with maybe a cleaner client side solution that does the validation and highlights the invalid element since I still maintain data integrity at the db with the check constraint.
    Thanks,
    Jeff

  • How to add a check constraint to a column to accept values in the following format: "L214"?

    All I could come up with is this:
    check (column_name like '____');
    But That doesn't enforce the first character to be a letter and the other three to be numbers.

    Hi,
    "PS: Why the f***you have so many subforums here?"
    Because it is much easier to seperate and let experts answer to specific details of SQL Server. SQL Server is not a small product as many people think ;-)
    Here is the solution:
    CREATe table SampleA (A INT, B VARCHAR(MAX) CHECK (B LIKE '[A-Z][0-9][0-9][0-9]'))
    INSERT INTO SampleA VALUES (1,'0000')
    Msg 547, Level 16, State 0, Line 2
    The INSERT statement conflicted with the CHECK constraint "CK__SampleA__B__38B96646". The conflict occurred in database "master", table "dbo.SampleA", column 'B'.
    The statement has been terminated.
    INSERT INTO SampleA VALUES (1,'L000')
    --(1 row(s) affected)
    INSERT INTO SampleA VALUES (1,'L0001')
    Msg 547, Level 16, State 0, Line 2
    The INSERT statement conflicted with the CHECK constraint "CK__SampleA__B__38B96646". The conflict occurred in database "master", table "dbo.SampleA", column 'B'.
    The statement has been terminated.
    -Jens
    Jens K. Suessmeyer http://blogs.msdn.com/Jenss

  • EA2: Code is generated for only one column with Domain check constraint.

    I created a Domain with a Value List (Y or N - Yes or No) and used that domain for two columns in the same table. But for only one column (the last one) the check appears in the generated DDL.
    After I enabled the "Use Domain Constraints" both checks appear in the DDL, but one as an inline check constraint and one as an "Alter table add contraint.."
    Once I changed the naming Template for the check constraint, both constraints are generated as an Alter table clause. The inline check constraint is only generated when the name of the constraint (according to the template) is too long. It would be nice if I could choose if I want an inline or a separate check constraint definition.
    Edited by: Roel on Nov 23, 2010 11:55 AM
    Edited by: Roel on Nov 23, 2010 12:02 PM

    I logged ER for that
    Philip

  • Max number of CHECK constraints on a column in Oracle9i?

    What is the maximum number of CHECK constraints that can be defined on a column when creating a table in Oracle 9i database?
    Also could some one tell me what are the limitations on CHECK constraints?

    Well, in Oracle 8.1.7 documentaion it is stated that number of constraints is also unlimited. I haven't such a database now to test but here is a little test for Oracle 9iR2
    SQL> drop table test;
    Table dropped.
    SQL> create table test (a number
      2   check (a > 1)
      3   check (a > 2)
      4   check (a > 3)
      5   check (a > 4)
      6   check (a > 5)
      7   check (a > 6)
      8   check (a > 7)
      9   check (a > 8)
    10   check (a > 9)
    11   check (a > 10)
    12   check (a > 11)
    13   check (a > 12)
    14   check (a > 13)
    15   check (a > 14)
    16   check (a > 15)
    17   check (a > 16)
    18   check (a > 17)
    19   check (a > 18)
    20   check (a > 19)
    21   check (a > 20)
    22  )
    23  /
    Table created.

  • Column check constraint

    Hello,
    if I update a record that has an invalid column (check constraint not met) the record is not updated, but I also do not get a forms error popup. Is that normal? Or do I have to use the on-update trigger to catch the error?
    Thanks
    Frank

    Hello,
    if I update a record that has an invalid column (check constraint not met) the record is not updated, but I also do not get a forms error popup. Is that normal? Or do I have to use the on-update trigger to catch the error?
    Thanks
    Frank

  • Primary key and relevant not null check constraints....

    Hi ,
    There are some constraints of primary key type and not null check constraints on columns which constitute each primary key....
    Should I/Do I have to drop them....????
    Do they burden the db at the time of data validation....????
    Thanks...
    Sim

    Hi,
    >>There are some constraints of primary key type and not null check constraints on columns which constitute each primary key..
    In fact, a column that constitutes a primary key, by default cannot accept NULL values. In this case, defines a PK column as NOT NULL would not be necessary.
    LEGATTI@ORACLE10> create table x (id number constraint pk_x primary key);
    Table created.
    LEGATTI@ORACLE10> desc x
    Name                  Null?    Type
    ID                    NOT NULL NUMBER
    LEGATTI@ORACLE10> select constraint_name,constraint_type,table_name,search_condition from user_constraints where table_name='X';
    CONSTRAINT_NAME                C TABLE_NAME      SEARCH_CONDITION                
    PK_X                           P X
    LEGATTI@ORACLE10> create table y (id number not null constraint pk_y primary key);
    Table created.
    LEGATTI@ORACLE10> desc y
    Name                  Null?    Type
    ID                   NOT NULL NUMBER
    LEGATTI@ORACLE10> select constraint_name,constraint_type,table_name,search_condition from user_constraints where table_name='Y';
    CONSTRAINT_NAME                C TABLE_NAME      SEARCH_CONDITION
    SYS_C006327381 C Y "ID" IS NOT NULL 
    PK_Y                           P Y
    LEGATTI@ORACLE10> alter table y drop constraint SYS_C006327381;
    Table altered.
    LEGATTI@ORACLE10> desc y
    Name                                      Null?    Type
    ID                                        NOT NULL NUMBER
    LEGATTI@ORACLE10> insert into y values (NULL);
    insert into y values (NULL)
    ERROR at line 1:
    ORA-01400: cannot insert NULL into ("LEGATTI"."Y"."ID")
    LEGATTI@ORACLE10> insert into y values (1);
    1 row created.
    LEGATTI@ORACLE10> insert into y values (1);
    insert into y values (1)
    ERROR at line 1:
    ORA-00001: unique constraint (LEGATTI.PK_Y) violated
    >>Should I/Do I have to drop them....????
    I don't see any problem, otherwise, drop the NOT NULL constraint is the same with alter the column table like below:
    LEGATTI@ORACLE10> create table z (id number not null constraint pk_z primary key);
    Table created.
    LEGATTI@ORACLE10> select constraint_name,constraint_type,table_name,search_condition from user_constraints where table_name='Z';
    CONSTRAINT_NAME                C TABLE_NAME                     SEARCH_CONDITION
    SYS_C006328420 C Z "ID" IS NOT NULL
    PK_Z                           P Z
    LEGATTI@ORACLE10> desc z
    Name                                      Null?    Type
    ID                                        NOT NULL NUMBER
    LEGATTI@ORACLE10> alter table z modify id NULL;
    Table altered.
    LEGATTI@ORACLE10> select constraint_name,constraint_type,table_name,search_condition from user_constraints where table_name='Z';
    CONSTRAINT_NAME                C TABLE_NAME                     SEARCH_CONDITION
    PK_Z                           P Z
    LEGATTI@ORACLE10> desc z
    Name                                      Null?    Type
    ID                                        NOT NULL NUMBERCheers
    Legatti

  • How to use external functions in check constraints

    I created my own function:
    create or replace
    function if_num_get_num (inval in varchar2)
    return number
    is
    dummy number;
    Begin
    dummy := to_number(inval);
    return dummy;
    exception
    when others then return null;
    end;Can I use it in table check constraint?
    When I use standard function INSTR everything is OK.
    ALTER TABLE A_S
    ADD CONSTRAINT A_S_CHK1 CHECK
      (INSTR(NAZWA_ZA, ':') > 0)
    ENABLE;but when I try to create it with my function:
    ALTER TABLE A_S
    ADD CONSTRAINT A_S_CHK1 CHECK
      (IF_NUM_GET_NUM(INSTR(NAZWA_ZA, ':')) > 0)
    ENABLE;I get a message "Invalid column IF_NUM_GET_NUM"

    Read the restrictions.
    >
    Restrictions on CHECK Constraints
    A CHECK constraint requires that a condition be true or unknown for every row of the table. If a statement causes the condition to evaluate to false, then the statement is rolled back. The condition of a CHECK constraint has these limitations:
    * The condition must be a boolean expression that can be evaluated using the values in the row being inserted or updated.
    * The condition cannot contain subqueries or sequences.
    * The condition cannot include the SYSDATE, UID, USER, or USERENV SQL functions.
    * The condition cannot contain the pseudocolumns LEVEL or ROWNUM.
    * The condition cannot contain the PRIOR operator.
    ** The condition cannot contain a user-defined function.*
    >
    http://download.oracle.com/docs/cd/E11882_01/appdev.112/e17125/adfns_constraints.htm#ADFNS282

  • Is it possible to create a dynamic(with a select) check constraint?

    create table a (col_to_be_coded_fora number);
    create table b (col_to_be_coded_forb number);
    create table c (col_name varchar2(20), col_code number, col_desc varchar2(20));
    insert into c values ('col_to_be_coded_fora', 1, 'active');
    insert into c values ('col_to_be_coded_fora', 2, 'de-active');
    insert into c values ('col_to_be_coded_fora', 3, 'pending');
    insert into c values ('col_to_be_coded_forb', 10, 'school');
    insert into c values ('col_to_be_coded_forb', 20, 'hospital');
    insert into a values ( 1); -- meaning 'active' for table a, column col_to_be_coded_fora, can go in
    insert into a values (10); -- meaning nothing for table a, column col_to_be_coded_fora, must give error
    insert into b values ( 1); -- meaning nothing for table b, column col_to_be_coded_forb, must give error
    insert into b values (10); -- meaning 'school' for table b, column col_to_be_coded_fora, can go in
    I know i can handle this problem with dividing table c into to tables and creating foreign key relationship.
    in this demo case i have only a and b, 2 tables but i want to encode thousands of tables with a table like c.
    &#304;s it possible to create a dynamic check constraint on a table which selects c table for the inputs that have permision?
    Or do i have to use after insert, update triggers on table a and b to ensure this functionality?
    Is there a smarter implementation for this need, may be a design change?
    Thank you,
    Kind regards.
    Tonguç

    Hi Tonguç,
    A small design change makes it possible to do this with simple foreign key constraints.
    I would do something like:
    ual303@ORKDEV01> CREATE TABLE c (
      2    col_name VARCHAR2(20),
      3     col_code NUMBER,
      4     col_desc VARCHAR2(20),
      5     PRIMARY KEY (col_name, col_code)
      6  );
    Tabel is aangemaakt.
    ual303@ORKDEV01> CREATE TABLE a (
      2    col_to_be_coded_fora NUMBER PRIMARY KEY,
      3     col_name VARCHAR2(20) DEFAULT 'col_to_be_coded_fora' CHECK (col_name = 'col_to_be_coded_fora'),
      4     FOREIGN KEY (col_name, col_to_be_coded_fora) REFERENCES c
      5  );
    Tabel is aangemaakt.
    ual303@ORKDEV01> CREATE TABLE b (
      2    col_to_be_coded_forb NUMBER PRIMARY KEY,
      3     col_name VARCHAR2(20) DEFAULT 'col_to_be_coded_forb' CHECK (col_name = 'col_to_be_coded_forb'),
      4     FOREIGN KEY (col_name, col_to_be_coded_forb) REFERENCES c
      5  );
    Tabel is aangemaakt.
    ual303@ORKDEV01> insert into c values ('col_to_be_coded_fora', 1, 'active');
    1 rij is aangemaakt.
    ual303@ORKDEV01> insert into c values ('col_to_be_coded_fora', 2, 'de-active');
    1 rij is aangemaakt.
    ual303@ORKDEV01> insert into c values ('col_to_be_coded_fora', 3, 'pending');
    1 rij is aangemaakt.
    ual303@ORKDEV01> insert into c values ('col_to_be_coded_forb', 10, 'school');
    1 rij is aangemaakt.
    ual303@ORKDEV01> insert into c values ('col_to_be_coded_forb', 20, 'hospital');
    1 rij is aangemaakt.
    ual303@ORKDEV01> -- meaning 'active' for table a, column col_to_be_coded_fora, can go in
    ual303@ORKDEV01> insert into a(col_to_be_coded_fora) values ( 1);
    1 rij is aangemaakt.
    ual303@ORKDEV01> -- meaning nothing for table a, column col_to_be_coded_fora, must give error
    ual303@ORKDEV01> insert into a(col_to_be_coded_fora) values (10);
    insert into a(col_to_be_coded_fora) values (10)
    FOUT in regel 1:
    .ORA-02291: integrity constraint (UAL303.SYS_C0033537) violated - parent key not found
    ual303@ORKDEV01> -- meaning nothing for table b, column col_to_be_coded_forb, must give error
    ual303@ORKDEV01> insert into b(col_to_be_coded_forb) values ( 1);
    insert into b(col_to_be_coded_forb) values ( 1)
    FOUT in regel 1:
    .ORA-02291: integrity constraint (UAL303.SYS_C0033540) violated - parent key not found
    ual303@ORKDEV01> -- meaning 'school' for table b, column col_to_be_coded_fora, can go in
    ual303@ORKDEV01> insert into b(col_to_be_coded_forb) values (10);
    1 rij is aangemaakt.
    ual303@ORKDEV01>Cheers,
    Colin

  • Using a function in a check constraint

    Hi,
    I created a domain table(id, code, domain_code, description) and foreign keys to this table. To ensure that a valid domain is put in the column I created a function that returns a boolean and has two parameters (id and domain_code). It returns true if the id and domain belong together.
    I want to know if it is possible to create a check constraint which validates the data in the refering table with the data in the domain table.
    Does anyone know if this is possible? Or do I have to use a db-trigger?
    Regards,
    Romano

    It still sounds like all you need is a foreign key constraint. Please see the example below, based on your revised criteria.
    scott@ORA92> create table domain
      2    (id         number,
      3       code         number,
      4       domain_code number,
      5       constraint  domain_pk primary key (id),
      6       constraint  domain_uk unique (code, domain_code))
      7  /
    Table created.
    scott@ORA92> insert into domain values (1, 10, 2)
      2  /
    1 row created.
    scott@ORA92> create table domain_values_table
      2    (id         number,
      3       domain_code number,
      4       constraint domain_values_table_uk unique (id, domain_code))
      5  /
    Table created.
    scott@ORA92> insert into domain_values_table values (1, 2)
      2  /
    1 row created.
    scott@ORA92> commit
      2  /
    Commit complete.
    scott@ORA92> create table referring
      2    (id         number,
      3       domain_code number,
      4       status         number,
      5       constraint  referring_fk foreign key (status)
      6                references domain (id),
      7       constraint  referring_fk2 foreign key (id, domain_code)
      8                references domain_values_table (id, domain_code))
      9  /
    Table created.
    scott@ORA92> insert into referring values (1,  2, null)
      2  /
    1 row created.
    scott@ORA92> insert into referring values (3, 4, null)
      2  /
    insert into referring values (3, 4, null)
    ERROR at line 1:
    ORA-02291: integrity constraint (SCOTT.REFERRING_FK2) violated - parent key not found

  • How can i modify the check constraint   in the table

    How can i modify the check constraint in the table. This table containts check constraint, condition is code_value between 1 and 4. codevalue is column name.
    Please suggest me.

    Go to tahiti.oracle.com, pick version browse reference manual and see the alter table statement
    Also read the goal of this forum.
    Your question is more appropriate to Database general forum
    General Database Discussions
    Gints Plivna
    http://www.gplivna.eu

  • Difference between a check constraint and a trigger

    Hi, I wanted to know the exact usage of a trigger within a database.
    Suppose I want to have a restriction on an insert into a Employees table that provides a check on the time that a particular employee signs in,
    I could do that with the help of a before insert trigger that prevents certain values fgrom being inserted.
    But cant I do the same thing with the help of a simple check constraint?
    Where exactly does the distincton lie between a constraint and a trigger?
    Edited by: user8680847 on Sep 24, 2009 11:55 PM

    A trigger is fired due to DML operations(Insert,Update,Delete) ot on Database events like startup, shutdown etc. You can write your piece of logic into the trigger to do the necessary operations when the event occurs.
    For example, if you want you track the changes made to +(emp)+ table data you can place a before update trigger on the table and place your code inside the triiger to insert the old values into an audit table +(emp_audit)+. Everytime an update is made on the table data the trigger will get fired and will insert the old values of the record into the audit table and the new value in the +(emp)+ table.
    A constraint is completely different from a trigger. A constraint is like a validation on the data to be inserted. There are different types of constraints.
    I will give you a simple example.
    You place the not null constraint on the dept column of the emp table. While you try to insert a new record into the emp table the the dept value cannot be null. Oracle will validate the data you are trying to insert into the table with the constraint and will give you an error if the validation fails.
    There are other constraints like:
    unique key
    foreign key
    etc.
    Precisely a constraint does not handle a database event as a trigger rather it validates the column data.
    Edited by: Priyabrat on Sep 25, 2009 12:27 AM

Maybe you are looking for

  • Error msg "package org.apache.xmlrpc does not exist ... "

    Hi everybody, I am new to java. While creating build through cruise control Error Msg comes BUILD FAILED Ant Error Message:      C:\Program Files\CruiseControl\projects\Myproject\build.xml:47: Compile failed; see the compiler error output for details

  • How to change MM/DD/YYYY to DD/MM/YYYY

    hi i have a requirement.   CONCATENATE SY-DATUM TEXT-T01 SY-UNAME INTO V_TEXT. here sy-datum is in the format of MM/DD/YYYY now i have to replace sy-datum with DD/MM/YYYY. Thanks, Maheedhar.T

  • Is there a way to see what eventListeners currently exist?

    I've currently got a function in which a event listener is added (addEventListener(Event.ENTER_FRAME, create Animation) but I am calling the function repeatedly in my program it is giving me an error: ArgumentError: Error #1063: Argument count mismat

  • Winmail.dat

    Why are my attachements only recently coming in as winmail.dat? I have never had issues opening word, pdf or excel docs on iphone or ipad in the past. I have the doc 2 go app as well so I don't know why suddenly they don't open??

  • How to rectify blocked plug-ins

    I am trying to send an E Card but no matter what site I use i get blocked plug-in message.  I have downloaded the latest Adobe Flash but it hasn't fixed the problem.  Any advice?