Constraint

Hi there.
We have to tables AA (colA1, colA2) and BB (colB1, colB2).
Table AA is parent to BB.
BB.colB1 has a FK reference constraint to AA.colA1.
The problem is that the relation is a many-to-many, so a value in BB.colB1 can actually be inserted if the referencing value just exists (one or more times) in AA.colA1. The constraint I have used so far doesn't permit that (constraint fk_gasforecast_enhplads references op_kvvenergianlaeg(enhedsplads) not null).
How do I create a reference constraint with a many-to-many relation?
Thanks
(sorry for my limited imagination, mrs. Garcia !)
chr

I'm not sure what your problem is here-- foreign key relationships already allow for the 1-to-many relationship you seem to be describing
  1* create table parent( key NUMBER PRIMARY KEY, value VARCHAR2(100) )
scott@jcave > /
Table created.
Elapsed: 00:00:00.02
scott@jcave > create table child( pk NUMBER PRIMARY KEY,
  2                               fk NUMBER REFERENCES parent( key ),
  3                               value VARCHAR2(100) );
Table created.
Elapsed: 00:00:00.01
scott@jcave > insert into parent( key, value ) values ( 1, 'First parent' );
1 row created.
Elapsed: 00:00:00.00
scott@jcave > ed
Wrote file afiedt.buf
  1* insert into parent( key, value ) values ( 2, 'Second parent' )
scott@jcave > /
1 row created.
Elapsed: 00:00:00.00
scott@jcave > insert into child( pk, fk, value ) values ( 1000, 1, 'First child of first parent'
1 row created.
Elapsed: 00:00:00.01
scott@jcave > ed
Wrote file afiedt.buf
  1* insert into child( pk, fk, value ) values ( 1001, 1, 'Second child of first parent' )
scott@jcave > /
1 row created.
Elapsed: 00:00:00.00
scott@jcave > ed
Wrote file afiedt.buf
  1* insert into child( pk, fk, value ) values ( 1002, 2, 'First child of second parent' )
scott@jcave > /
1 row created.
Elapsed: 00:00:00.00
scott@jcave > ed
Wrote file afiedt.buf
  1* insert into child( pk, fk, value ) values ( 1003, 2, 'Second child of second parent' )
scott@jcave > /
1 row created.
Elapsed: 00:00:00.00If you need many-to-many relationships, you need to create a mapping table.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC

Similar Messages

  • Error while adding Image: ORA-00001: unique constraint

    Dear all,
    I have an error while adding images to MDM I can´t explain. I want to add 7231 images. About 6983 run fine. The rest throws this error.
    Error: Service 'SRM_MDM_CATALOG', Schema 'SRMMDMCATALOG2_m000', ERROR CODE=1 ||| ORA-00001: unique constraint (SRMMDMCATALOG2_M000.IDATA_6_DATAID) violated
    Last CMD: INSERT INTO A2i_Data_6 (PermanentId, DataId, DataGroupId, Description_L3, CodeName, Name_L3) VALUES (:1, :2, :3, :4, :5, :6)
    Name=PermanentId; Type=9; Value=1641157; ArraySize=0; NullInd=0;
    Name=DataId; Type=5; Value=426458; ArraySize=0; NullInd=0;
    Name=DataGroupId; Type=4; Value=9; ArraySize=0; NullInd=0;
    Name=Description_L3; Type=2; Value=; ArraySize=0; NullInd=0;
    Name=CodeName; Type=2; Value=207603_Img8078_gif; ArraySize=0; NullInd=0;
    Name=Name_L3; Type=2; Value=207603_Img8078.gif; ArraySize=0; NullInd=0;
    Error: Service 'SRM_MDM_CATALOG', Schema 'SRMMDMCATALOG2_m000', ERROR CODE=1 ||| ORA-00001: unique constraint (SRMMDMCATALOG2_M000.IDATA_6_DATAID) violated
    Last CMD: INSERT INTO A2i_Data_6 (PermanentId, DataId, DataGroupId, Description_L3, CodeName, Name_L3) VALUES (:1, :2, :3, :4, :5, :6)
    Name=PermanentId; Type=9; Value=1641157; ArraySize=0; NullInd=0;
    Name=DataId; Type=5; Value=426458; ArraySize=0; NullInd=0;
    Name=DataGroupId; Type=4; Value=9; ArraySize=0; NullInd=0;
    Name=Description_L3; Type=2; Value=; ArraySize=0; NullInd=0;
    Name=CodeName; Type=2; Value=207603_Img8085_gif; ArraySize=0; NullInd=0;
    Name=Name_L3; Type=2; Value=207603_Img8085.gif; ArraySize=0; NullInd=0;
    I checked all data. There is no such dataset in the database. Can anybody give me a hint how to avoid this error.
    One thing I wonder: The PermanentId is allways the same but I can´t do anything here.
    BR
    Roman
    Edited by: Roman Becker on Jan 13, 2009 12:59 AM

    Hi Ritam,
    For such issues, can you please create a new thread or directly email the author rather than dragging back up a very old thread, it is unlikely that the resolution would be the same as the database/application/etc releases would most probably be very different.
    For now I will close this thread as unanswered.
    SAP SRM Moderators.

  • Dynamic Creation of constraints.   Suggestion rqd

    Hai
    CREATE TABLE TDA
    ( PKNODAVE VARCHAR2(7 BYTE) NOT NULL ENABLE,
    DTCREATION DATE,
    DAVETRANSFERT VARCHAR2(7 BYTE),
    PKPARC NUMBER(5,0)
    ALTER TABLE TDA ADD CONSTRAINT PK_TDAV8 PRIMARY KEY (PKNODAVE)
    ALTER TABLE TDA ADD CONSTRAINT FK_TDA1 FOREIGN KEY (DAVETRANSFERT)
    REFERENCES TDA (PKNODAVE) ENABLE
    i have a requirement to create a child table constraints with on delete cascade.
    So i just did dynamic sql like this.
    DECLARE
    CURSOR tcur
    IS
    SELECT DISTINCT primary.table_name PARENT_TABLE ,
    foreign.table_name CHILD_TABLE ,
    foreign.constraint_name CHILD_CONSTRAINT ,
    col.column_name FOREIGN_COLUMN ,
    col1.column_name PRIMARY_COLUMN
    FROM all_constraints PRIMARY,
    all_constraints FOREIGN ,
    all_cons_columns col ,
    all_cons_columns col1
    WHERE foreign.constraint_type = 'R'
    AND foreign.R_OWNER = foreign.OWNER
    AND foreign.R_CONSTRAINT_NAME = primary.CONSTRAINT_NAME
    AND foreign.CONSTRAINT_NAME = col.CONSTRAINT_NAME
    AND foreign.OWNER = col.OWNER
    AND primary.CONSTRAINT_NAME = col1.CONSTRAINT_NAME
    AND primary.OWNER = col1.OWNER
    AND col.POSITION = col1.POSITION
    AND primary.owner ='LOCAL'
    AND primary.table_name ='TDA';
    v_drop_sql VARCHAR2 (300);
    v_create_sql VARCHAR2 (300);
    v_count NUMBER;
    v_t_name VARCHAR2 (30);
    v_t_child_constraint VARCHAR2(100);
    v_t_child_col_name VARCHAR2(100);
    v_t_parent_col_name VARCHAR2(100);
    v_t_child_table VARCHAR2(100);
    BEGIN
    FOR cur IN tcur
    LOOP
    v_t_name := NULL;
    v_create_sql := NULL;
    v_drop_sql := NULL;
    v_count := 0;
    v_t_child_table :=cur.child_table;
    v_t_child_col_name :=cur.foreign_column;
    v_t_parent_col_name :=cur.primary_column;
    v_t_name :=cur.child_table;
    v_t_child_constraint := cur.CHILD_CONSTRAINT;
    --v_drop_sql           := 'ALTER TABLE ' ||v_t_name||' drop constraint  '||v_t_child_constraint;
    -- EXECUTE IMMEDIATE v_drop_sql;
    v_create_sql := 'ALTER TABLE '||v_t_child_table|| ' ADD CONSTRAINT ' ||v_t_child_constraint||' FOREIGN KEY( '||v_t_child_col_name||')
    REFERENCES '||v_t_child_col_name||'('||v_t_parent_col_name||') ENABLE ON DELETE CASCADE';
    dbms_output.put_line(v_create_sql);
    EXECUTE IMMEDIATE v_create_sql;
    END LOOP;
    EXCEPTION
    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE(v_create_sql);
    END;
    the pl/sql preocedure executes successfullly. but there is not constaint created why...?
    Pls give your suggestions
    S

    Oracle beginner wrote:
    EXCEPTION
    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE(v_create_sql);
    END;
    the pl/sql preocedure executes successfullly. but there is not constaint created why...?Are you sure it's executing successfully? You are capturing all exceptions with your WHEN OTHERS clause and ignoring any errors.

  • Duvida Sobre Tabela Constraints de Muitos para Muitos

    Bom dia, Pessoal.
    Tenho a seguinte duvida.
    Quando você tem uma tabela de muitos para muitos e parte das constraints das 2 FK contem o mesmo campo que é referencia a uma terceira tabela.
    Por exemplo:
    Tempos uma tabela cupom e uma tabela de documento financeiro. Para unir as 2 tenho uma tabela cupom_documento.
    Nesta tabela cupom_documento tenho uma fk com empresa, filial, ecf e sequencial do cupom.
    e nesta mesma tabela tenho uma fk com documento que contem empresa, filial, sequencial do documento.
    Empresa, filia estão nas 2 fk's
    Minha duvida é em questão de performance e índice por fk é mais performático que não tenha o mesmo campo como fk para esta tabela.
    Obs: Esta empresa e filiais são tabelas que referencia usada sem quase todas as tabelas..
    Jonas B.

    Olá, Jonas B.
    Quanto mais seletivo é o índice, melhor será a sua performance. Seletividade é a quantidade de valores distintos que uma coluna pode ter. Para o seu cenário, tente não construir uma grande PK (composta pelas FKs das tabelas cupom e documento) na tabela cupom_documento. Lembre-se que quanto menor for a busca/varredura pela chave no íncide, melhor será sua performance.
    Abraços.
    caadecarvalho

  • How to find the table name on which integrity constraint not found

    Hi All
    How to acheive this
    I have a lot of tables with lot of primary key - foreign key
    relationship.
    In plsql
    when any inserts happen in the child table & the corresponding row is not present in the parent table, we get an exception
    ORA-02291: integrity constraint (user1.ppk) violated - parent key not found
    On this exception , in the exception block i want to trap teh name of the parent table on which the primary key for the particular child table was not there
    Is it possible to retrieve the parent table in this way. I am looking for a generic plsql code block which can help to acheive this
    Regards

    scott@ORA92> SET SERVEROUTPUT ON
    scott@ORA92> DECLARE
      2    e_no_parent_key EXCEPTION;
      3    PRAGMA            EXCEPTION_INIT (e_no_parent_key, -2291);
      4    v_fk_cons       VARCHAR2 (61);
      5    v_owner            VARCHAR2 (30);
      6    v_parent_table  VARCHAR2 (61);
      7    v_pk_cons       VARCHAR2 (30);
      8    v_parent_column VARCHAR2 (30);
      9  BEGIN
    10    INSERT INTO emp (empno, deptno) VALUES (99, 60);
    11  EXCEPTION
    12    WHEN e_no_parent_key THEN
    13        -- extract schema.constraint_name from sqlerrm:
    14        v_fk_cons:= SUBSTR (SQLERRM,
    15                      INSTR (SQLERRM, '(') + 1,
    16                      INSTR (SQLERRM, ')') - (INSTR (SQLERRM, '(') + 1));
    17        DBMS_OUTPUT.PUT_LINE ('Foreign key constraint violated: ' || v_fk_cons);
    18        -- extract parent schema.table and parent key:
    19        SELECT owner, table_name, constraint_name
    20        INTO     v_owner, v_parent_table, v_pk_cons
    21        FROM     user_constraints
    22        WHERE     (owner, constraint_name) =
    23            (SELECT r_owner, r_constraint_name
    24             FROM     user_constraints
    25             WHERE     owner || '.' || constraint_name = v_fk_cons);
    26        DBMS_OUTPUT.PUT_LINE ('Parent table: ' || v_owner || '.' || v_parent_table);
    27        DBMS_OUTPUT.PUT_LINE ('Parent key: ' || v_owner || '.' || v_pk_cons);
    28        -- extract parent table columns:
    29        FOR rec IN
    30          (SELECT column_name
    31           FROM   user_cons_columns
    32           WHERE  owner = v_owner
    33           AND    table_name = v_parent_table
    34           AND    constraint_name = v_pk_cons)
    35        LOOP
    36          DBMS_OUTPUT.PUT_LINE
    37            ('Parent table column: ' || rec.column_name);
    38        END LOOP;
    39  END;
    40  /
    Foreign key constraint violated: SCOTT.FK_DEPTNO
    Parent table: SCOTT.DEPT
    Parent key: SCOTT.PK_DEPT
    Parent table column: DEPTNO
    PL/SQL procedure successfully completed.

  • Difference between unique constraint and unique index

    1. What is the difference between unique constraint and unique index when unique constraint is always indexed ? Which one is better in this case for better performance ?
    2. Is Composite index of 3 columns x,y,z better
    or having independent/ seperate indexes on 3 columns x,y,z is better for better performance ?
    3. It has been very confusing for me to decide which columns to index, I have indexed most foreignkey columns, is it a good idea ? We do lot of selects and DMLS on most of our tables. Is there any query that I can run and find out if indexes are really being used and if they are improving any performance. I have analyzed and computed my indexes using ANALYZE index index_name validate structure and COMPUTE STATISTICS;
    null

    1. Unique index is part of unique constraint. Of course you can create standalone unique index. But is is no point to skip the logical view of business if you spend same effort to achive.
    You create unique const. Oracle create the unique index for you. You may specify index characteristic in unique constraint.
    2. Depends. You can't utilize the composite index if the searching condition is not whole or front part of the indexing key. You can't utilize your index if you query the table for y=2. That is.
    3. As old words in database arena, Index may be good or bad for a table depending on the size of table, number of columns in the table... etc. It is very environmental dependent. In fact, It is part of database nomalization. Statistic is a way oracle use to determine the execution plan.
    Steve
    null

  • Difference Between Unique Index vs Unique Constraint

    Can you tell me
    what is the Difference Between Unique Index vs Unique Constraint.
    and
    Difference Between Unique Index and bitmap index.
    Edited by: Nilesh Hole,Pune, India on Aug 22, 2009 10:33 AM

    Nilesh Hole,Pune, India wrote:
    Can you tell me
    what is the Difference Between Unique Index vs Unique Constraint.http://www.jlcomp.demon.co.uk/faq/uk_idx_con.html
    and
    Difference Between Unique Index and bitmap index.The documentation is your friend:
    http://download.oracle.com/docs/cd/B28359_01/server.111/b28318/schema.htm#CNCPT1157
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/schema.htm#sthref1008
    Regards,
    Rob.

  • Unique Index vs. Unique Constraint

    Hi All,
    I'm studying for the Oracle SQL Expert Certification. At one point in the book, while talking about indices, the author says that a unique index is not the same a unique constraint. However, he doesn't explain why they're two different things.
    Could anyone clarify the difference between the two, please?
    Thanks a lot,
    Valerio

    A constraint has different meaning to an index. It gives the optimiser more information and allows you to have foreign keys on the column, whereas a unique index doesn't.
    eg:
    SQL> create table t1 (col1 number, col2 varchar2(20), constraint t1_uq unique (col1));
    Table created.
    SQL> create table t2 (col1 number, col2 varchar2(20));
    Table created.
    SQL> create unique index t2_idx on t2 (col1);
    Index created.
    SQL> create table t3 (col1 number, col2 number, col3 varchar2(20), constraint t3_fk
      2                   foreign key (col2) references t1 (col1));
    Table created.
    SQL> create table t4 (col1 number, col2 number, col3 varchar2(20), constraint t4_fk
      2                   foreign key (col2) references t2 (col1));
                     foreign key (col2) references t2 (col1))
    ERROR at line 2:
    ORA-02270: no matching unique or primary key for this column-listIt's like saying "What's the difference between a car seat and an armchair? They both allow you to sit down!"

  • Constraint table in sql server7

    i have a database in sql server7 and i want to see all the constraints that are applied on that table manually i.e. through sql query.please tell me what is the sql query that i can use to see all the constraints applied on the table.
    same thing i want to do with ms-access ,tell me if i can use any query to see the constraints on ms-access table.

    Hi, this is Oracle Forum, you must go to Microsoft Forum for add this Post, please take the next reference.
    http://forums.microsoft.com/
    Regards.

  • How to apply the constraint ONLY to new rows

    Hi, Gurus:
       I have one question as follows:
       We need to migrate a legacy system to a new production server. I am required to add two columns to every table in order to record who updates the row most recently through triggers, and  I should apply not null constraint to the columns . However, since legacy system already has data for every table, and old data does not have value for the 2 new columns. If we apply the constraint, all of existing rows will raise exception. I wonder if there is possibility to apply the constraint ONLY to new rows to come in future.
    Thanks.
    Sam

       We need to migrate a legacy system to a new production server. I am required to add two columns to every table in order to record who updates the row most recently through triggers, and  I should apply not null constraint to the columns .
    The best suggestion I can give you is that you make sure management documents the name of the person that came up with that hair-brained requirement so they can be sufficiently punished in the future for the tremendous waste of human and database resources they caused for which they got virtually NOTHING in return.
    I have seen many systems over the past 25+years that have added columns such as those: CREATED_DATE, CREATED_BY, MODIFIED_DATE, MODIFIED_BY.
    I have yet to see even ONE system where that information is actually useful for any real purpose. Many systems have application/schema users and those users can modify the data. Also, any DBA can modify the data and many of them can connect as the schema owner to do that.
    Many tables also get updated by other applications or bulk load processes and those processes use generic connections that can NOT be tied back to any particular system.
    The net result is that those columns will be populated by user names that are utterly useless for any auditing purposes.
    If a user is allowed to modify a table they are allowed to modify a table. If you want to track that you should implement a proper security strategy using Oracle's AUDIT functionality.
    Cluttering up ALL, or even many, of your tables with such columns is a TERRIBLE idea. Worse is adding triggers that server no other purpose but capture useless infomation but, because they are PL/SQL cause performance impacts just aggravates the total impact.
    It is certainly appropriate to be concerned about the security and auditability of your important data. But adding columns and triggers such as those proposed is NOT the proper solution to achieve that security.
    Before your organization makes such an idiotic decision you should propose that the same steps be taken before adding that functionality that you should take before the addition of ANY MAJOR structural or application changes:
    1. document the actual requirement
    2. document and justify the business reasons for that requirement
    3. perform testing that shows the impact of that requirement on the production system
    4. determine the resource cost (people, storage, etc) of implementing that requirement
    5. demonstrate how that information will actually be used EFFECTIVELY for some business purpose
    As regards items #1 and #2 above the requirement should be stated in terms of the PROBLEM to be solved, not some preconceived notion of the solution that should be used.
    Your org should also talk to other orgs or other depts in your same org that have used your proposed solution and find out how useful it has been for them. If you do this research you will likely find that it hasn't met their needs at all.
    And in your own org there are likely some applications with tables that already have such columns. Has anyone there EVER used those columns and found them invaluable for identifying and resolving any actual problem?
    If you can't use them and their data for some important process why add them to begin with?
    IMHO it is a total waste of time and resources to add such columns to ALL of your tables. Any such approach to auditing or security should, at most, be limited to those tables with key data that needs to be protected and only then when you cannot implement the proper 'best practices' auditing.
    A migration is difficult enough without adding useless additional requirements like those. You have FAR more important things you can do with the resources you have available:
    1. Capture ALL DDL for the existing system into a version control system
    2. Train your developers on using the version control system
    3. Determining the proper configuration of the new server and system. It is almost a CERTAINTY that settings will get changed and performance will suffer even though you don't think you have changed anything at all.
    4. Validating that the data has been migrated successfully. That can involve extensive querying and comparison to make sure data has not been altered during the migration. The process of validating a SINGLE TABLE is more difficult if the table structures are not the same. And they won't be if you add two columns to every table; every single query you do will have to specify the columns by name in order to EXCLUDE your two new columns.
    5. Validating the performance of the app on the new system. There WILL BE problems where things don't work like they used to. You need to find those problems and fix them
    6. Capturing the proper statistics after the data has been migrated and all of the indexes have been rebuilt.
    7. Capturing the new execution plans to use a a baseline for when things go wrong in the future.
    If it is worth doing it is worth doing right.

  • Null values v IOT with primary constraint

    Hi gurus.
    I've overheard boss' conversation with client, who complaints that one of the columns in a system IOT table with NOT NULL and PRIMARY KEY returns nulls.
    Do you have any ideas? I do not have access to this DB, I just wonder, how it could be and what are these points, that we should start with.
    Thank you in advance,
    Maria.

    ou, sorry if I was not so clear, but I'm absolutely calm and even more: it's not my responsibility at all to fix that problem :-))
    all that I wanted is just to find some weak places where the reason of the problem could exists and give it my boss while he is busy with his time consuming project (in short, i just wanted to help him to resolve it, not waiting while he will ask me to do that). nobody is in panic, everything is ok in a world.
    clear description:
    client has a system table (IOT) that sometimes returns null values from column with NOT NULL and PRIMARY KEY constraint. as I remember from school, it's impossible. client wonders if it's an Oracle 9i bug and upgrade to 10g will fix it, or it's a block corruption. I do't know the answer, that's why I'm asking you, Oracle's gurus.
    Thank you all,
    M.

  • 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

  • NOT and NOT NULL constraints

    I saw this posted on Metalinks and the answer was to be found here. I can't seem to find it..... has there been a resolution to this? Unfortunately, I am running into the same problem.
    You help is appreciated.
    I am trying to create Oracle8i schema from MS SQL Sercer 7.0 using Oracle Migration Workbench and it is not functioning as expected.
    Problems are:
    =============
    1. If the column type is CHAR OR VARCHAR in MS SQL Server and the integrity contraints is NOT NULL or NULL, in Oracle8i it create as NULL only and it not taking the NOT NULL in MS SQL Server to Oracle8i NOT NULL. I can say that it is ignoring the integrity constraint for CHAR OR VARCHAR type while converting to Oracle8i.
    Example in MS SQL Server
    ========================
    CREATE TABLE emp (
    emp_name CHAR(10) NOT NULL
    the tool converts to Oracle8i as
    CREATE TABLE emp (
    emp_name CHAR(10)
    It is ignoring the NOT NULL constraints in Oracle8i and it is happening only for CHAR and VARCHAR data type. Can anyone help me on this how to rectify the problem in Migration Workbench. ....... "

    We reported this for the EA's, but got little response and obviously no resolution.
    K.

  • 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

  • Difference between Primary Key and Unique Key with NOT NULL constraint

    As both can be referred to another table.
    Apart from the difference that Primary Key can be only 1 and Unique keys can be multiple,
    is there any difference?
    Like in terms of type of Index?

    PARAG_C wrote:
    As both can be referred to another table.
    Apart from the difference that Primary Key can be only 1 and Unique keys can be multiple,
    is there any difference?
    Like in terms of type of Index?Technically there is almost no difference. Logically the two are often used for slightly different concepts.
    The PK (and with it the index) is often an ID column filled by a seqeunce. This key can then be refenced by foreign key constraints on other tables. it is very useful to have this as a meaningless technical construct. Because then the chance that such a ID needs to be changed is extremly slim.
    The UK (and with it the index) is often one or several columns that represent the logical key for the entity. Foreign key constriants should not point to this. THe chance that this attribute will be changed at some point in time is way higher then for a meaningless number (ID).

  • Problem with constraint in a table..help required..

    Hi ,
    i need to create a table which has an attribute year_joined and need to set a constraint that the year_joined should be less than or equal to the current year (year obtained from sysdate (YYYY)) ..
    can any one help me with the create statement required...
    eg: create table test(year_joined number, constraint c_year check(year_joined< = ?));
    i could not use a sub query in the create statement.
    help req..
    thanks,
    sri

    Satyaki,
    I tried but fail. Could you please tell the way how it can be implementaed in CHECK constraint.
    SQL> CREATE TABLE T ( YERR_JOINED NUMBER(4) , CHECK (YERR_JOINED <='2007'));
    Table created.
    SQL> drop table t;
    Table dropped.
    SQL> CREATE TABLE T ( YERR_JOINED NUMBER(4) , CHECK (YERR_JOINED <= TO_CHAR(SYSDATE,'YYYY')));
    CREATE TABLE T ( YERR_JOINED NUMBER(4) , CHECK (YERR_JOINED <= TO_CHAR(SYSDATE,'YYYY')))
    ERROR at line 1:
    ORA-02436: date or system variable wrongly specified in CHECK constraint
    SQL>

Maybe you are looking for