How to modify a CHECK constraint.

We need to modify a check constraint to allow new values. Is there a way we can modify the existing constraint or should we drop and recreate including new values.
Example:
We have a table SLOG and SNO is a column accepting numeric values. Currently there is a constraint on this column so that it accepts values of 1,2,3,4. Now I want to insert a value of 5 to this column. Since there is a CHECK constraint on this column it prevents the value of 5.
So the constraint needs to be modified. Is there a way we can modify the constraint using a DDL command (like ALTER TABLE) or should I drop and re create the constraint.
Thanks in advance.
Balaji

Hello,
Is there a way we can modify the constraint using a DDL command You can just MODIFY the state of your constraint ( constraint_state ).
So, if you want to modify the definition of your constraint you have to drop and create the CHECK constraint with its new definition.
Sorry, when I was writing my post, I didn't see the question was already answered.
Best regards,
Jean-Valentin
Edited by: Lubiez Jean-Valentin on Jul 11, 2010 11:04 AM

Similar Messages

  • 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

  • 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

  • How to create this check constraint

    create table emplt
    ( emplt_pk number,
    indvl_pk number,
    start_dt date,
    end_dt date,
    lct_fl char(1),
    sup_fl char(1),
    br_pk number,
    nro_pk number,
    default_fl char(1) default 'N' );
    INSERT INTO emplt
    values(
    1001, 101, to_date('01-01-2005', 'MM-DD-YYYY' ), NULL, 'Y','N',123,NULL,NULL );
    INSERT INTO emplt
    values(
    1002, 101, to_date('02-01-2005', 'MM-DD-YYYY' ), NULL, 'Y','N',NULL,0001,NULL );
    INSERT INTO emplt
    values(
    1003, 102, to_date('02-01-2005', 'MM-DD-YYYY' ), NULL, 'Y','N',NULL,0001,NULL );
    Is it possible to create a check constraint on this table that enforces that for a given indvl_pk, br_pk and nro_pk
    there is only one row with dflt_fl = 'Y'?
    Thanks in advance!

    Say,
    SQL> create unique index empli_ui on emplt(case default_fl when 'Y' then indvl_pk end,
      2  case default_fl when 'Y' then br_pk end,
      3  case default_fl when 'Y' then nro_pk end
      4  )
      5  /
    &nbsp
    Index created.
    &nbsp
    SQL> insert into emplt (indvl_pk,br_pk,nro_pk,default_fl)
      2  values(1,2,3,'J');
    &nbsp
    1 row created.
    &nbsp
    SQL> insert into emplt (indvl_pk,br_pk,nro_pk,default_fl)
      2  values(1,2,3,'J');
    &nbsp
    1 row created.
    &nbsp
    SQL> insert into emplt (indvl_pk,br_pk,nro_pk,default_fl)
      2  values(3,2,1,'A');
    &nbsp
    1 row created.
    &nbsp
    SQL>
    SQL> insert into emplt (indvl_pk,br_pk,nro_pk,default_fl)
      2  values(3,2,1,'A');
    &nbsp
    1 row created.
    &nbsp
    SQL> insert into emplt (indvl_pk,br_pk,nro_pk,default_fl)
      2  values(3,2,1,'Y');
    &nbsp
    1 row created.
    &nbsp
    SQL>
    SQL> insert into emplt (indvl_pk,br_pk,nro_pk,default_fl)
      2  values(3,2,1,'Y');
    insert into emplt (indvl_pk,br_pk,nro_pk,default_fl)
    ERROR at line 1:
    ORA-00001: unique constraint (SCOTT.EMPLI_UI) violated
    &nbsp
    SQL> insert into emplt (indvl_pk,br_pk,nro_pk,default_fl)
      2  values(1,2,3,'Y');
    &nbsp
    1 row created.
    &nbsp
    SQL> insert into emplt (indvl_pk,br_pk,nro_pk,default_fl)
      2  values(1,2,3,'Y');
    insert into emplt (indvl_pk,br_pk,nro_pk,default_fl)
    ERROR at line 1:
    ORA-00001: unique constraint (SCOTT.EMPLI_UI) violatedRgds.

  • How do I modify a check constraint?

    Alter table test modify constraint Constraint_name check(a in ('a','b','c'));
    Doesn't seem to work. I tried many things, any help?

    Hi,
    Why can not disable/drop the constraint and recreate new constraint with requirements?
    1. alter table test modify/drop a number drop constraints x;
    2. alter table test add constraint b check(x in(1,2));
    With regards,
    Boby Jose Thekkanath,
    Dharma Computers(P) Ltd.
    Bangalore-India.
    www.dharma.com

  • How to modify authorization check for tcode pa30

    Hi all,
    To execute pa30 tcode the auth object p_orgin is required.
    The auth object p_orgin contains the following fields:
    AUTHC Authorization level
    INFTY Infotype
    PERSA Personnel Area
    PERSG Employee Group
    PERSK Employee Subgroup
    SUBTY Subtype
    VDSK1 Organizational Key
    Our requirement is to add another field to the above object ie P_ORGIN
    BTRTL Personnel Subarea, so that the restriction can be imposed on sub area basis without writing an additional z report or adding a z table.
    I have added the same to P_ORGIN via su24 but the it is not working.
    Pl guide if it is possible to do so and how.
    Thanks in advance.
    Regards

    Hi Manas,
    Not possible as of now  though it is an intutive idea from your side )
    This is because when introducing authority check using function modules Authority_Check a lot of times you would also give the value that should be present in user profile in order to validate the check .Now I dont think even with present levels of AI it is possible to do that because no system will be able to dynamically guage what exactly is in the mind of the user.
    And additionally P_ORIGIN will be actually used in several reports where requirements will be different!!
    Regards.
    Ruchit.

  • How to modify a column name & How to modify a constraint name

    How to modify a column name?
    How to modify a primary key constraint name if the pk has been referenced by another foreign key?
    Thanks.

    Hi,
    What version of oracle are you using? If it is 9i,
    then you can the command
    alter table <table_name> rename column <column_name> to <new_column>;
    if it is 8i or earlier, you can create a view with the required names.
    hth
    Always post the oracle version and the platform you are using to get better response.

  • How do you add a CONSTRAINT for a VARCHAR(10) column to checks the Date format as yyyy/mm/dd

    I have tried:
    ALTER TABLE dbo.tablename
    ADD CONSTRAINT DF_Date_format
    check (SDate LIKE '%[1-2][0-9][0-9][0-9]/[0-1][0-9]/[0-3][0-9]%')
    ******But this does not work for VARCHAR data type ********
    and
    I also tried creating a function as shown below but I got an error when trying to add a constraint with this function.
    (error is:
    'The ALTER TABLE statement conflicted with the CHECK constraint "DF_Date_format". The conflict occurred in database " databasename ", table "dbo.tablename", column 'Date'.)
    Create FUNCTION [dbo].[CheckDateFormat]
    (@Date varchar(10))
    Returns BIT
    AS
    BEGIN
    Declare @RETURN BIT
    SELECT @Return =
    Case when (substring (@Date, 5, 1) + substring (@Date, 8, 1)) = '//'
    then 0
    else 1
    end
    Return @Return
    END
    ALTER TABLE dbo.tablename
    ADD CONSTRAINT DF_Date_format
    check
    ( dbo.CheckDateFormat(SDate) = 0 )

    As noted above, be mindful of the performance implications of UDF CHECK constraints:
    http://www.sqlusa.com/bestpractices/udf-check-constraint/
    The following logic works:
    Create FUNCTION [dbo].[CheckDateFormat]
    (@Date varchar(10))
    Returns BIT
    AS
    BEGIN
    Declare @RETURN BIT
    SELECT @Return =
    Case when (substring (@Date, 5, 1) + substring (@Date, 8, 1)) = '//'
    then 0
    else 1
    end
    Return @Return
    END
    GO
    CREATE TABLE Orders (ID INT IDENTITY(1,1),
    OrderDate varchar(10),
    Amount money
    GO
    ALTER TABLE Orders
    ADD CONSTRAINT DF_Date_format
    check
    ( dbo.CheckDateFormat(OrderDate) = 0 )
    GO
    As noted above, DATE is a better choice for column data type.
    Kalman Toth Database & OLAP Architect
    SELECT Video Tutorials 4 Hours
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • 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

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

  • DB Diagram: Modality Difference between NOT NULL and check constraint

    Hi,
    I am using jdev 11g (11.1.1.10) I am trying to create a db diagram from two tables. I have a FK that is NOT NULL (defined on the column). When i try to display these two tables modality, it does not show up in the diagram. I noticed that there are two ways NOT null can be defined on a table (right click on the db object to edit it; a) under column definitions there is a check box for not null, b) there is a check constraint that one can add to do not null.
    I am confused and was wondering whether I must I have check constraints on the database in order to display modality (optional versus mandatory). Logically speaking it does not make any sense though.

    Hi Susan,
    Thanks for your email. I understand that in order to show modality under
    UML notation, one must define a COLUMN being NOT NULL instead of defining a check constraint.
    I still do not understand how modality (optional versus mandatory) is shown in ERD notation in JDev. I tried flipping ERD/UML notations and made sure icons for tables were showing, but no MODALITY is shown in ERD notation ( an '0" icon or a "|" icon for optional and mandatory). Is it the solid line versus dotted line in the ERD diagram? I am confused because generally under Crawfoot ERD notation '0" icon or a "|" icon is shown for modality.
    Modality gets picked up in jdev diagram when COLUMN not null is specified and UML notation is used
    ALTER TABLE DETAILAJ MODIFY EMPID not null;
    Modality does not get picked up in jdev db diagram when check constraint is specified and UML notation is used
    ALTER TABLE DETAILAJ
    ADD CONSTRAINT CK_NN_DETAILAJ__EMPID CHECK(EMPID IS NOT NULL) ;
    Another question i have related to the matter mentioned above is as follows. Since I want to see modality in db diagram, it follows that I must define a column as not null instead of a check constraint. I must also use NO VALIDATE on NOT NULL column because i have prior data that does not meet the new restriction. I noticed that if i use the following syntax to define a NOT NULL column, two things happen.
    a) A constraint is defined as not null automatically and a system generated name is given to the constraint.
    b) DB diagram in Jdev does not show the modality.
    My question is whether there is a way to see modality in this case.
         alter table DETAILAJ
         MODIFY EMPID NOT NULL ENABLE NOVALIDATE ;
    Edited by: user11219846 on Nov 19, 2009 11:07 AM

  • How to modify the blob size, or how to set the size?

    i want to know how to modify the blob size, or how to set the size?
    what's the default size of blob?
    Thanks in advance.

    Blob datatype can contain binary data with a maximum size of 4 GB.
    when you enter 10kb file, the database will only use 10kb to store the file (depending on block size etc)
    if you want to modify the blob size, you may do like this:
    SQL> create materialized view t_mv refresh fast on commit
    2 as select id, dbms_lob.getlength(x) len from t;
    Materialized view created.
    SQL> alter table t_mv add constraint t_mv_chk check (len < 100);
    Table altered.

  • 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 modify a lookup field-type to use checkbox instead of radiobutton?

    How to modify a lookup field-type to use checkbox instead of radiobutton?
    I would like to modify the behavior for the lookup field.
    Normally you get a screen where it is possible to search through a lookup. The items resulted from the search are listed as radiobutton items. Therefore you can select only one at the time to be added.
    Is it possible to have the items to be listed as checkbox instead? So that you can check multiple items and therefore be able to add multiple items at the time?
    For example:
    To add the user to 10 different groups on MS-AD.
    It is desired to have the ability to check multiple groups to be added instead only one at the time.
    My client would like to use this feature in many other situations.

    Displaying will not be a big deal but with that you have to customize the action class and its working as well.

  • How to modify Logical database Selection screen

    I am using PNP logical database , it is giving one selection screen ,
    after executioni can able to change the selection screen but i want to change default selection screen so that when i execute i want specific fields in selection.
    How to modify it?

    Hi,
    You need to use report category.In the attributes,click HR report category and select or create the selection screen you need.
    Check this link.
    http://www.sapdevelopment.co.uk/hr/hr_repcat.htm
    Kindly reward points by clicking the star on the left of reply,if it helps.

Maybe you are looking for

  • Can you tell me how to displays my browser based help?

    I am using RH8, generating Browser based Air, and have windows 7. This is a continuation of my previous discussion. I was able to generate browser based air help for my merged projects just once.But I just tried it again and it won't work. Here is wh

  • Issue for Cash Discount

    Dear All I have an issue for Customer Cash Discount. Suppose a customer sales order has been generated for Rs 100. Now in our sales order pricing procedure, we have created a discount of 2%, which would generate a net value of 98 on which sales tax i

  • How can one actually see their keychain passwords?

    Is it possible to acually see your keychain passwords?

  • Organizing trouble

    Im having some trouble organizing music from cds on my ipod. When i import a cd to the library, and then transfer to the ipod.. everything is fine. Then i look at my ipod and i go to albums.. epecting to see album titles but i see song titles, so i g

  • Delivery for Subcontracting Orders - SC

    Hi, I have create a subcontracting PO. I would like to ask which should be the proper way of creating the outbound delivery? I've seen that in a ME2O there is a button to make the post Good Issue and another to create the delivery, but as the transac