Foreign keys without ON DELETE CASCADE; Database design question

It's the 3rd company, while I work, where I see that created foreign keys
ON DELETE CASCADE
clause.
My colleague said that it is created without the ON DELETE CASCADE clause in order to complicate the deletion of data (records of children). Thus, for codes of the Purge and archive, before we delete the parent table we must remove from the child table first.

Occasinaly, something is wrong and we will end up disabling FKs make them all and then purging, archiving, etc...

So, is it not better to create foreign keys with the clause ON DELETE CASCADE, rather than having all these hassles?

Experience, no matter what you think?

Personally, I am firmly in the removal of the brand of hard data camp. In the vast majority of cases, trying to remove an active parent is an error if the user must be informed of what they are trying to do and must make a conscious effort to do so (in other words, remove first the children).

John

Tags: Database

Similar Questions

  • Database design question

    Hello, I have a one-to-many relationship problem when designing a store management system. Each store can have several names, but there at least a name. Any suggestion? Thank you

    Try this:

    CREATE TABLE MyStores

    (

    --E t c...

    , Store_Name_Id VARCHAR2 (7) NOT NULL

    CONSTRAINT Fk_Store_name

    REFERENCES Store_Names_Tab (Name_Id)

    -- ...

    )

  • ON DELETE CASCADE and the CASCADE CONSTRAINTS - what are the difference?

    I know that CASCADE CONSTRAINTS would allow me to remove the parent key and the reference of the following children will be freed from the constraints. However, the child columns will remain and will be set to NULL.

    SO:

    If the CASCADE CONSTRAINTS could do the job, why do we need on REMOVE CONSTRAINTS?

    Unnecessary extra Note:

    I know that YOU DELETE CONSTRAINT is defined with the child. When I tried to delete the parent key without having the CONSTRAINTS of the WATERFALL, I got an error message indicates that the parent key has childs! So ON DELETE CASCADE was not up to what I had to mention the CASCADE CONSTRAINTS when deleting the parent key while the CASCADE CONSTRAINTS worked fine without ON DELETE CASCADE on the side of the child.

    I hope that my question is simple...

    A foreign key with a delete cascade means that if a record in the parent table is deleted, then the corresponding records in the child table with automatically deleted. This is a deletion of the waterfall.

    Forced to cascade deletes all foreign keys that reference the table to remove, and then deletes the table.

  • How do I change or add constr. foreign key to the table whose children or data lines

    Hello

    I have a table with the name of Department in which the DEPTNO column is a column of data and primary key in it for all columns. Now, I have a table EMP where DEPTNO column is not having any constraints, including constraint foreign key also. I now have data in the EMP table for all columns. I would now add the DEPTNO column foreign key constraint in the EMP table that references the column DEPTNO in DEPT table. Both the table have not all null values.

    I need to add the foreign key without removing the data in the EMP table.


    Please advice.

    Kind regards
    Alriq

    In addition, if you have pre-existing data that will never have a parent record but you want to ensure that any NEW data is consistent with the FK constraint you can always create it with the NOVALIDATE option:

    SQL> CREATE TABLE EMP_BKP AS SELECT * FROM SCOTT.EMP;
    
    Table created.
    
    SQL> CREATE TABLE DEPT_BKP AS SELECT * FROM SCOTT.DEPT;
    
    Table created.
    
    SQL> DELETE FROM DEPT_BKP WHERE DEPTNO=10;
    
    1 row deleted.
    
    SQL> ALTER TABLE DEPT_BKP ADD CONSTRAINT DEPT_BKP_PK PRIMARY KEY(DEPTNO);
    
    Table altered.
    
    SQL> ALTER TABLE EMP_BKP ADD CONSTRAINT DEPT_FK FOREIGN KEY(DEPTNO) REFERENCES DEPT_BKP(DEPTNO);
    ALTER TABLE EMP_BKP ADD CONSTRAINT DEPT_FK FOREIGN KEY(DEPTNO) REFERENCES DEPT_BKP(DEPTNO)
                                       *
    ERROR at line 1:
    ORA-02298: cannot validate (TEST_USER.DEPT_FK) - parent keys not found
    
    SQL> ALTER TABLE EMP_BKP ADD CONSTRAINT DEPT_FK FOREIGN KEY(DEPTNO) REFERENCES DEPT_BKP(DEPTNO) NOVALIDATE;
    
    Table altered.
    
    SQL> INSERT INTO EMP_BKP(EMPNO,ENAME,DEPTNO) VALUES(9999,'Test Emp',10);
    INSERT INTO EMP_BKP(EMPNO,ENAME,DEPTNO) VALUES(9999,'Test Emp',10)
    *
    ERROR at line 1:
    ORA-02291: integrity constraint (TEST_USER.DEPT_FK) violated - parent key not found
    
    SQL> SELECT * FROM EMP_BKP WHERE DEPTNO = 10 ORDER BY EMPNO;
    
         EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
    ---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
          7782 CLARK      MANAGER         7839 06/09/1981 00:00:00       2450                    10
          7839 KING       PRESIDENT            11/17/1981 00:00:00       5000                    10
          7934 MILLER     CLERK           7782 01/23/1982 00:00:00       1300                    10
    
  • Foreign key constraint, not recognized during the synchronization of data with the model dictionary

    Hello

    Data Modeler is a foreign key constraints do not recognize when synchronizing data with the model dictionary, although the foreign key is there (in the database that a data dictionary is read). I can't find any criterion when a foreign key is not recognized by the Data Modeler. Are there limits to the length of the attribute, or the number of columns in a foreign key, or other limitations which may lead to this behavior not to recognize a fk by Data Modeler? I have columns more than 32 characters. I compared with the fk is recognized by DM, but I can't find anything that indicates why it is not recognized.

    I wonder if someone also has constraints of foreign keys that are not recognized in the comparison of data bases and model?

    Thank you

    Robert

    Hi Robert,.

    Thanks for the comments, I logged a bug.

    Philippe

  • foreign key 'generate' strange behavior check box, any idea?

    Summary: in the properties of the table, the foreign keys, the box generate behaves badly, and I don't understand why or how I got there.

    Oracle Data Modeler 4.0.2.840 8.1 X 64 Windows, jdk1.7.0_55

    the behavior is:

    (1) add the foreign key (two different more to see strange behavior)

    (2) uncheck 'generate' on a foreign key

    (3) apply, Ok

    (4) ask 'Preview DDL', a foreign key constraint is generated, SO FAR SO GOOD, I'm happy

    5-now click on the button 'generate the DDL' for any design = > * * TWO foreign keys are generated?

    (6) even more strange: sometimes the 'generate' check itself after step 5, most of the time is not

    (7) at the beginning this has occurred for a couple of foreign key 'uncheckees', now it almost always happens.

    The relational model was built by importing the SQL scripts already exist (try to migrate the Data Modeler). No too complex ~ 115 tables, 12 times.

    I think it's a bug, but I can't find any reference on the web, maybe I do something wrong?

    Hi Michel,.

    The generation is different depending on whether or not the relevant storage design is open.

    If the design of the storage is not open, the option "Generate DDL" on the foreign key is taken into account (for an overview of the DDL or full generation of DDL).  For an entire generation of DDL, the foreign key will initially not selected phase in the generation of the DDL if Options the option "Generate DDL" on the foreign key has been disabled.  (This change in the phase of the generation of DDL Options will also cause the option "Generate DDL" on the foreign key update.)

    If the design of the storage is open, the option 'generate DDL"on the foreign key has no effect (in a Preview of DDL or full DDL generation).

    Also in a generation full of DDL, an object will be initially marked as not selected if it has been disabled in the previous generation of DDL.

    I hope that this helps to explain the behavior that you find.

    David

  • ORA-02266: permit to unique/primary keys in table referenced by foreign keys

    Hello
    I'm trying to delete data from a table by dropping a partition. I've identified all the child tables by running the following command.

    Select "select count (*) from ' |" table_name |' where employee_id = 100; »
    of dba_constraints
    where constraint_type = 'R '.
    and r_constraint_name in
    (select constraint_name from dba_constraints
    where constraint_type in ('P', 'U') and table_name =' EMPLOYEE);


    "SELECTCOUNT (*) OF | TABLE_NAME | "WHEREEMPLOYEE_ID_ID = 100; »
    -----------------------------------------------------------------------------------------------
    Select count (*) in the PT_ORDERS where employee_id = 100;
    Select count (*) in the PT_DEP where employee_id = 100;
    Select count (*) in the PT_SKILLSET where employee_id = 100;

    I dropped the score for number 100 in all child tables. The count (*) select returns 0 rows for each of the foregoing.

    When I try to run the command on the EMPLOYEE table, below I get ' ORA-02266: unique/primary keys in table referenced by foreign keys enabled.

    Drop partition ALTER table EMPLOYEE EMP_ID_100;

    I don't see why I am unable to give up this partition now because it is data child present in any of the referenced tables. Any suggestions or help on this would be greatly appreciated.

    Thank you.

    RGS,
    Rob

    You must first disable foreign key constraints and delete the partition. Deletion of lines or a fall in childs partitions do not work in this case
    as you have the overall dependence:


    SQL > create table scott.t (x int primary key, int y)
    2 partition by (list (y)
    3 values p_1 (1) partition, partition values p_2 (2))
    4.

    Table created.

    SQL > create table scott.t_c (x int references scott.t (x), int y)
    2 partition by (list (y)
    3 values p_1 (1) partition, partition values p_2 (2))
    4.

    Table created.

    SQL > insert into scott.t values (1,1)
    3 N

    1 line of creation.

    SQL > insert into scott.t values (2,2)
    3 N

    1 line of creation.

    SQL > insert into scott.t_c values (1,1)
    3 N

    1 line of creation.

    SQL > insert into scott.t_c values (2,2)
    3 N

    1 line of creation.

    SQL > commit;

    Validation complete.

    SQL > alter table scott.t_c drop partition p_2.

    Modified table.

    SQL > alter table scott.t drop partition p_2.
    ALTER table drop partition p_2 scott.t
    *
    ERROR on line 1:
    ORA-02266: permit to unique/primary keys in table referenced by foreign keys

    SQL > select constraint_name from dba_constraints
    2 where owner = 'SCOTT' and constraint_type = 'P '.
    3 and table_name = 't';

    CONSTRAINT_NAME
    ------------------------------
    SYS_C0011058

    SQL > select constraint_name from dba_constraints
    2 where owner = 'SCOTT' and constraint_type = 'R '.
    3 and r_constraint_name = "SYS_C0011058";

    CONSTRAINT_NAME
    ------------------------------
    SYS_C0011059

    SQL > alter the constraint to disable scott.t_c table SYS_C0011059;

    Modified table.

    SQL > alter table scott.t drop partition p_2.

    Modified table.

    SQL > alter table scott.t_c enable novalidate constraint SYS_C0011059;

    Modified table.

    I guess you should consider options such as partitioning Referencial (with some restrictions).

    Best wishes
    Dmitry.

  • Rename the Parent - foreign key columns

    I need to rename a bunch of parent columns that are referenced in the foreign key constraints. Is it possible to get the child column get automatically updated with the new name of the parent column?

    IE, I have a table named 'subject' with a PK named subjectID. I have a child table addresses that child has a FK to subject.subjectID and the column is automatically named subject_subjectID.

    Now, I want to rename just subject.subjectID "ID". I want this rename also take place in the referencing table "address" so the name change should be translated as subject_ID.


    Thank you!

    You can set {ref column} as for 'Foreign key column' "tools > preferences > Data Modeler > designation standard > Templates.
    And to request that it uses "Apply to keys and constraints naming standards" in the context menu for relational model in the browser tree. Select only "foreign key column" it.

    Philippe

  • Renaming of the foreign keys in the relational model

    Hello


    I'm new to the Data Modeler, we use v 3.0.0.66.5 and Oracle 11 g, and I am trying to build a logic and a relational model for a new application.

    We always call our primary keys as the ID, this causes me a problem with my names of foreign keys in the relational model, as they show as ID #. Is it possible to add the abbreviated of the table of the foreign key?

    Thanks in advance

    Sue

    Yes it is.

    Take a look at the tools > preferences, select Data Modeler > naming Standard > model, you can specify the standard you want to use for your foreign key. You can apply this designation to existing models and all new created FK uses the same model. To apply the standard to existing templates, select the relational model in the browser, right-click to display the context menu and select the menu "apply Naming standards... ».

    Sue

  • Optimize the foreign key for the removal of the cascade constraint.

    Hello

    JDeveloper version: 11.1.2.3.0

    I saw this blog and found something new to me: http://snag.gy/qI6dY.jpg

    Jdeveloper user interface, there is an option to select all tables to select the foreign key and set it for the removal of the waterfall.

    My project is deployed on multiple databases. I wonder where this change is registered. None of the project files is modified.

    Can I make this change (from limitations to the waterfall) for each database that I use?

    Here is the blog where I saw that: http://tompeez.wordpress.com/2013/04/22/master-detail-insertdelete-sample/

    I have my object associations optimized for the removal of the waterfall, but without the option above together, I always get constraint violations...

    Concerning

    Not sure however if you set the option the DOF looks like

    "EMP_JOB_FK' FOREIGN KEY ('JOB_ID') CONSTRAINT
    REFERENCES 'HR '. "" SELECT JOBS "("JOB_ID') WE DELETE CASCADE

    If you set the option to cascade for fk Job_id from the employees table.

    Timo

  • Problems with the database, on delete cascade

    Hello

    I am in a project with the Flahs CS4 with air and as3. I create a database by code, everything is ok. I have 2 tables,
    a main table with a code field as primary key and other details of the table, named e.g. DetailTable, with 3 fields as the primary key. What I want to do, this is a deletion of a row in MainTable, all lines of DetailTable, where the field code is the same as the field in MainTable code should be deleted also.

    Here's the SQL code to create the tables.

    var sql2:String = "CREATE TABLE If NOT EXISTS MainTable ('+ '.
    "code INTEGER PRIMARY KEY AUTOINCREMENT, ' +.
    "quote," +
    'date ' +.
    "  " +
    ")";

    var sql3:String = "CREATE TABLE If NOT EXISTS DetailTable ('+ '.
    "code INTEGER, INTEGER position, type INTEGER, ' +.
    "path of TEXT, TEXT document, ' +.
    'PRIMARY KEY (code, position, type) +.
    'FOREIGN KEY (code) REFERENCES Detallesecuencia (code) ON DELETE CASCADE ' +.
    ")";


    Thus, when the tables are created, insert data. I connect without a problem, remove a line in MainTable (see code), to remove the line with the example code = 4, but in the DetailTable, all with code = 4 lines are NOT deleted, why?

    [CODE]
    Inside of a class

    private var conn: SQLConnection;

    public void constructorClass() {}
    Conn = new SqlConnection ();
    ConexionBD();
    }

    function ConexionBD() {}

    conn.addEventListener (SQLEvent.OPEN, openHandler);
    conn.addEventListener (SQLErrorEvent.ERROR, errorHandler);
    var dbFile:File = File.applicationDirectory.resolvePath ("mydatabase.db");
    conn.openAsync (dbFile, SQLMode.UPDATE);
    }

    function deleteRow() {}
    selectData:SQLStatement = new SQLStatement();
    selectData.sqlConnection = conn;
    selectData.text = "" DELETE FROM MainTable WHERE code =: param1 ";"
    selectData.addEventListener (SQLEvent.RESULT, resultHandler);
    selectData.addEventListener (SQLErrorEvent.ERROR, errorHandler);

    Delete line in MainTable code = 4, but not to delete all the rows in DetailTable with code = 4
    selectData.parameters [": param1"] = 4;

    selectData.execute ();
    }
    [/ CODE]

    Thanks in advance

    Hmmm, well then maybe it's you must go down the road of the old school and delete individual tables as needed, rather than rely on the cascade delete.

  • correct handling of foreign keys in unique constraints for operations ON DELETE SET NULL

    During my troubleshooting at a client site, I came across an interesting setup where I would like to ask your opinion.


    Consider two tables ADTB and TBLB.

    ADTB:

    INT COLA1

    COLA2 INT

    TBLB:

    COLB1 INT

    COLA2 is COLB1 as a foreign key ON DELETE SET NULL value.

    COLA1 and COLA2 are combined into a UNIQUE for the BATTERY constraint.

    I have two records of TBLB:

    (1)

    (2)

    and two DRUM recordings:

    (1, 1)

    (2, 2)

    so far, all the constraints are valid.

    During my research, I learned that I can not put COLA2 null in ADTB for two lines at the same time:

    TBLA UPDATE set COLA2 = NULL where COLA1 = 1;

    -> OK

    TBLA UPDATE set COLA2 = NULL where COLA1 = 2;

    -> VIOLATED UNIQUE CONSTRAINT

    Unfortunately, it's something my application needs, anyway. In order to get this resolved, but I try to understand, what would happen if I:

    REMOVE THE TBLB;

    ?

    It should set COLA2 in ADTB "Null" on the two lines, which is not allowed due to the UNIQUE CONSTRAINT.

    Can someone shed light on this issue? Thank you.


    Yours,

    Ronny

    Unfortunately, as you say, you can't not NULL values in such a unique constraint.  It would be the same as if you had a composite primary key and try to allow one of the columns will be null in several rows with the same value in the other column.  NULL is treated as an "unknown" value, it is possible that it could be the same value (it may or may not be, but Oracle does not know), so it must assume that it might be and that's why treat it as if there is the potential for a duplicate... so it's not unique.

    In short, do not allow null values in your unique constraints.

    The default is in the drawing, not in the way that Oracle is the treatment.  Fix the design if you do not have NULL values.

    In terms of relational database design, it seems that you are trying to transform the 1:M relations M:M relations, and which requires an intermediate table if you have M:1 and 1:M between 3 tables instead.

  • Foreign key delete rule: no matching combination does not show a difference to compare models

    Hello

    I've noticed that if there are in the relational model a foreign key with delete rule NO ACTION and in the database (Data Dictionary), the delete rule is RESTRICT, no difference appears in the dialog box to compare. The difference is displayed if the delete rule for example is CASCADE and RESTRICT.

    Kind regards

    Robert

    Hi Robert,.

    Thanks for reporting this problem.  I connected a bug on this subject (21754221).

    This situation does not normally flow when an Oracle database is imported, but may occur when importing other types of database.

    Kind regards

    David

  • Application with no standardized and the stress of missing foreign key in database

    Hi all

    We bought Asset Tracking System of a local company. They developed in Oracle Developer Suite 6i Asset Tracking System and database is Oracle 10g in the Ms Windows environment.

    the database provided by the company had a problem. I send the company as below;

    1. There are issues of standardization in the data base.
    2. Foreign key constraints are missing.

    Please specify.

    the company responded below

    The solution provided is a product and not a custom solution.  We have already stated in our previous meetings that pack that your company is facing problems regarding performance, bugs, then we will bring the necessary technical support, which includes the software update, all bug fixes and access to assistance. your organization must be valid AMC contract with us.

    · We would like to inform you that the Application and the database are designed according to the standards. Customer consent we alter / change/view data or function, the guarantee or AMC spread during modification is cancelled. your organization absolves us of any other maintenance and support of the software.

    I just wonder what that should I replied for them? I convinced my management because they are mislead our management saying that they have their own STANDARDS, while not missing constraint Foreign Key is a MISTAKE.

    Please guide me and tell me your opinion as well. I really need it.

    Thank you.

    Simple.

    Do not. They won't understand. The only thing that they care for is their bonus.  They blame the software, they know the least: the database.

    You manage the database, they will be blaming you (and potentially you fire).

    You can't win this battle.

    I recommend that you start looking for another job.

    I have stayed here several times. All these consuiltancies have a very high rate of recovery of underpaid, junior developers who knows nothing, because they produce all disasters.

    The first thing to teach developers in these companies is of CTA (I don't spelling here, because it will be deleted, but it isn't a polite expression).

    Once they have learned to become Director of the project.

    ------------

    Sybrand Bakker

    Senior Oracle DBA

  • without using foreign key

    use jdev 11.1.1.4.0 using adfbc.

    today I work around with foreign key constrainst are in the db table. between parent-child relationship between two fields in a table.


    without using the dbconstraint.

    How can I use the parent child relationship.

    What mean average.

    without using the foregin db key constraint.

    When the deleted parent field means throw child error exists.

    How I can do without database constrainst.

    I guess that I have already spoken...
    http://download.Oracle.com/docs/CD/E15051_01/Web.1111/b31974/bcentities.htm#BABHFJFJ

Maybe you are looking for

  • Put iTunes on Macbook Pro external drive

    I have a new Macbook Pro running OS X El Capitan. With my older iMac, I wanted to save space so I consolidated my iTunes library and put all my music on my external hard drive and then deleted all my music off my old iMac. I did the same thing with m

  • Can't see the Menu bar.

    Somehow, I lost the menu bar. I chose to show using the customization but screen when turned on/off the screen jumps only once again does not show me the menu bar. I do not use the mode full-screen. Version of FF (do not know how to find it)Windows 7

  • Have you lost the combined stop/reload button?

    In Firefox4, I started with a combined stop/reload button, but since I use the toolbars, I only reload separate and buttons available stop?

  • When you visit some Web sites, Firefox does not display the topic sites and sometimes the text correctly. It seems broken and unreadable.

    I reinstalled a new version of Firefox and set all of the default settings, but the problem still persists. Running Windows 7 and I have tried several different browsers (IE, Safari, Chrome and Opera) and all seem to work well. Only problem is with F

  • IS NO LONGER UPDATED

    I could not update via the App Store since 18/11/2015 despite the system tells me there's an update that is available for all users of Capitan.Any El of suggestions as to what is wrong and what I need to do to get back to normality.