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 4347482
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:18:44+00:00 2026-05-21T12:18:44+00:00

I have 2 tables one named Students and one named Grades and I’m trying

  • 0

I have 2 tables one named Students and one named Grades and I’m trying to add a foreign key constraint to the Grades table so that if someone is deleted from the Students table all of their grades will be deleted as well. I have a column named TNumber to match the 2. Here’s my code so far.

    ALTER TABLE Grades
    ADD CONSTRAINT fk_Grades
    FOREIGN KEY (TNumber)
    REFERENCES Students(TNumber) ON DELETE CASCADE;

The problem is that the code runs but it doesn’t create the foreign key.
Could someone just look at it and see if I’m doing something wrong in my syntax because the code runs and doesn’t throw any errors.

  • 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-05-21T12:18:45+00:00Added an answer on May 21, 2026 at 12:18 pm

    The most likely reason (and the one hinted at in the comments) given that the statement completes without error but seems to have no effect is that one or both of the tables use the MyISAM engine, which is usually the default. Both tables need to use an engine that supports foreign keys, such as InnoDB.

    If your tables are MyISAM tables, you can convert them to InnoDB tables with the following:

    ALTER TABLE Students Engine=InnoDB;
    ALTER TABLE Grades Engine=InnoDB;
    

    After that, try adding the foreign key again. A heads up: the columns in the foreign key constraint need to have the same type. If there are differences, you’ll get the extremely unhelpful “ERROR 1005 (HY000): Can’t create table filename (errno: 150)” error message.

    Note that using the InnoDB engine has consequences (see also “Storage Engine Performance Benchmark for MyISAM and InnoDB” and whatever a web search may turn up) beyond allowing foreign key restraints, but most of them are beneficial.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I Have a table in my databse that one of the columns named NumOfView
There is one table that have fields included the add row button. I am
I have a database table named 'student' in which there is one column named
I have two tables one with ID and NAME table 1 ID | NAME
I have a calendar table in my MYSQL database with one field named datefield
I have a database with many tables and one particular table has columns: name
I have multiple tables that need to be merged into one. SELECT name, SUM(money)
Quick method description: I have two tables, lets name them table ONE and table
I have two tables. In the one table I have a list of dorm
Let's say I have a Student and a School table. One operation that I

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.