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

  • Home
  • SEARCH
  • 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 7838887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:14:57+00:00 2026-06-02T15:14:57+00:00

I am creating an application that will handle and record when a student gets

  • 0

I am creating an application that will handle and record when a student gets advised by a faculty member at a university and I need an effective way to structure the tables. My problem is coming from a lack of referential integrity, caused by the inability to create a foreign key that will reference a STUDENT on only part of a composite key in ADVISE_HIST which is (STUDENT_ID,DATE_ADVISED)

here are some of the tables

create table STUDENT(
  LNAME varchar(50),
  FNAME varchar(50),
  ID char(9) primary key,
  ASSIGNED_ADVISOR_EMAIL varchar(70),
  foreign key (ASSIGNED_ADVISOR_EMAIL) references DEP_FACULTY(EMAIL) ON DELETE SET NULL,
  IS_ADVISED tinyint(1),
);

create table DEP_FACULTY(
  LNAME varchar(50),
  FNAME varchar(50),
  EMAIL varchar(70) primary key
);

create table ADVISE_HIST(
  STUDENT_ID char(9),
  /*foreign key (STUDENT_ID) references STUDENT(ID),*/
  ACTUAL_ADVISOR_EMAIL char(70) NOT NULL,
  foreign key (ACTUAL_ADVISOR_EMAIL) references DEP_FACULTY(EMAIL),
  DATE_ADVISED date,
  primary key REF_ADVISE_HIST (STUDENT_ID, DATE_ADVISED),
);

My question is, is there a way around not being able to create this key or is there a better structure that I’m not thinking of?

  • 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-02T15:15:01+00:00Added an answer on June 2, 2026 at 3:15 pm

    MySQL has a lot of restrictions on foreign keys. Among the ones that might be getting in your way . . .

    • Both tables have to use the INNODB engine.
    • “In the referencing table, there must be an index where the foreign key columns are listed as the first columns in the same order. “

    This code works in my version (5.1.62).

    create table DEP_FACULTY(
      LNAME varchar(50),
      FNAME varchar(50),
      EMAIL varchar(70) primary key
    ) ENGINE = INNODB;
    
    insert into DEP_FACULTY values ('Gregor', 'Brandich', 'gbrandich@thisdomain.com');
    
    create table STUDENT(
      LNAME varchar(50),
      FNAME varchar(50),
      ID char(9) primary key,
      ASSIGNED_ADVISOR_EMAIL varchar(70),
      foreign key (ASSIGNED_ADVISOR_EMAIL) references DEP_FACULTY(EMAIL) ON DELETE SET NULL,
      IS_ADVISED tinyint(1)
    ) ENGINE = INNODB;
    
    insert into STUDENT values ('Charmaine', 'DePeletier', 'cmd', 'gbrandich@thisdomain.com', 1);
    
    create table ADVISE_HIST(
      STUDENT_ID char(9),
      foreign key (STUDENT_ID) references STUDENT(ID),
      ACTUAL_ADVISOR_EMAIL char(70) NOT NULL,
      foreign key (ACTUAL_ADVISOR_EMAIL) references DEP_FACULTY(EMAIL),
      DATE_ADVISED date,
      primary key REF_ADVISE_HIST (STUDENT_ID, DATE_ADVISED)
    ) ENGINE = INNODB;
    
    insert into ADVISE_HIST values ('cmd', 'gbrandich@thisdomain.com', CURRENT_DATE);
    insert into ADVISE_HIST values ('ctd', 'gbrandich@thisdomain.com', CURRENT_DATE);
    

    Of those last two inserts, the first works. The second should throw a foreign key constraint error.

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

Sidebar

Related Questions

I am creating an application that will have a list of items that can
I'm creating an application that will store geolocation data for specific transactions. Should I
I'm currently creating an MVC application that will likely to expand to include a
I am in the process of creating a java application that will be running
I am creating a desktop/client application that will be installed on +/- 5 PCs,
I am interested in creating a simple web application that will take in user
I'm creating a splash screen that will display while my Android application loads. I'd
I am creating a forecasting application that will run simulations for various modes that
We’re creating a web application that will display contour areas as bitmaps in a
I'm creating an application that will use a lot of data which is, for

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.