Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8847749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:15:55+00:00 2026-06-14T12:15:55+00:00

If I have two relations in a database, like this: CREATE TABLE Courses (

  • 0

If I have two relations in a database, like this:

CREATE TABLE Courses (
  CourseID int NOT NULL PRIMARY KEY,
  Course VARCHAR(63) NOT NULL UNIQUE,
  Code CHAR(4) NOT NULL UNIQUE
);

CREATE TABLE BookCourses (
  EntryID int NOT NULL PRIMARY KEY,
  BookID int NOT NULL,
  Course CHAR(4) NOT NULL,
  CourseNum CHAR(3) NOT NULL,
  CourseSec CHAR(1) NOT NULL
);

and I establish a foreign key relationship between the two, like this:

ALTER TABLE BookCourses
ADD FOREIGN KEY (Course)
REFERENCES Courses(Code)
ON DELETE CASCADE;

Then you can see that the Course attribute in the BookCourses relation references the Code attribute in the Courses relation.

My question is when a deletion occurs in either of the two relations, which way does the deletion cascade? If I delete a tuple in the Courses relation, will it delete all referencing tuples in the BookCourses relation, or is it the other way around?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:15:56+00:00Added an answer on June 14, 2026 at 12:15 pm

    Cascade will work when you delete something on table Courses. Any record on table BookCourses that has reference to table Courses will be deleted automatically.

    But when you try to delete on table BookCourses only the table itself is affected and not on the Courses

    follow-up question: why do you have CourseID on table Category?

    Maybe you should restructure your schema into this,

    CREATE TABLE Categories 
    (
      Code CHAR(4) NOT NULL PRIMARY KEY,
      CategoryName VARCHAR(63) NOT NULL UNIQUE
    );
    
    CREATE TABLE Courses 
    (
      CourseID INT NOT NULL PRIMARY KEY,
      BookID INT NOT NULL,
      CatCode CHAR(4) NOT NULL,
      CourseNum CHAR(3) NOT NULL,
      CourseSec CHAR(1) NOT NULL,
    );
    
    ALTER TABLE Courses
    ADD FOREIGN KEY (CatCode)
    REFERENCES Categories(Code)
    ON DELETE CASCADE;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database with some relations. I have two tables in this example:
I have questions which are represented like this in my SQL database : CREATE
I have query with two MtM relations: $em = $this->getEntityManager(); $qb = $em->createQueryBuilder(); $qb
I have a Profile model and two ActiveRecord::Relations of this model. SQL request of
I have a database schema in Symfony like this: Persona: actAs: { Timestampable: ~
I'm using a MySQL database. I have two tables, Table 1 and Table 2.
I have a question about how to set up the relations between two models
I have two classes with many-to-many relation so I created a join table in-between
I'm setting up a database using phpMyAdmin. I have two tables ( foo and
I would like to have a reference between two entities stored in the RavenDB

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.