Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help where it says Constraint. I don\'t know how to name them or make the

ID: 3581885 • Letter: I

Question

I need help where it says Constraint. I don't know how to name them or make them exactly. Code Below

CREATE TABLE STUDENT

(
Student_Number int Primary Key,
Student_FName char(25),
Student_LName char(25),
Student_Inital char (1),
Student_DOB date ,
Student_Join_Date date,
Student_Address varchar(75)
);


CREATE TABLE INSTRUCTOR
(
Student_Number int Primary Key,
Instrucor_Hire_Date date,
Instructor_Rank char(20),
FOREIGN KEY (Student_Number) REFERENCES STUDENT(Student_Number)
);

CREATE TABLE CLASS
(
Class_ID int Primary Key,
Class_Day char(15),
Class_Time time,
Class_Dojo char(25),
Student_Number int ,
FOREIGN KEY (Student_Number) REFERENCES STUDENT(Student_Number)
);

CREATE TABLE MEETING
(
Meeting_Number int Primary Key,
Meeting_Date date,
Class_ID int Foreign Key,


CREATE TABLE ATTENDANCE
(
Meeting_Numbeer int ,
Studnt_Number int ,
Attend_Role Char(60),
Primary key (Meeting_Number, Student_Number),
FOREIGN KEY (Meeting_Number) REFERENCES MEETING(Meet_Number), -- add name to constraint
FOREIGN KEY (Student_Number) REFERENCES STUDENT(Student_Number),-- add name to constraint
);

CREATE TABLE RANK
(
Rank_Number int Primary Key,
Rank_Name Char(25) ,
Rank_Belt Char(25)
);

CREATE TABLE REQUIREMENT
(
Requirement_Number Int Primary Key,
Requirement_Description varchar(75) ,
Rank_Number int ,
FOREIGN KEY (Rank_Number) REFERENCES RANK(Rank_Number)
);


CREATE TABLE ATTAIN
(
Rank_Number Int,
Student_Number Int ,
Attain_Date date,
primary key (Rank_Number, Student_Number), -- constraint
FOREIGN KEY (Rank_Number) REFERENCES RANK(Rank_Number),
FOREIGN KEY (Student_Number) REFERENCES STUDENT(Student_Number), -- constraint clause
);

Explanation / Answer

The below are the queries which are modified by adding constrain names in the queries. See the explanation below the queries.

==> CREATE TABLE ATTENDANCE(Meeting_Number int ,Student_Number int ,Attend_Role Char(60),Primary key (Meeting_Number, Student_Number),constraint fk_attendance FOREIGN KEY (Meeting_Number) REFERENCES MEETING(Meeting_Number),constraint fk1_attendance FOREIGN KEY (Student_Number) REFERENCES STUDENT(Student_Number));

==> CREATE TABLE ATTAIN(Rank_Number Int,Student_Number Int,Attain_Datedate, constraint pk_attain primary key (Rank_Number,Student_Number),FOREIGN KEY (Rank_Number) REFERENCES RANK(Rank_Number),constraint fk_attain FOREIGN KEY (Student_Number) REFERENCES STUDENT(Student_Number));

We can define the names which we want for the constrains in the table definition itself i.e. while writing queries for table creation or even we can alter the created tables also. We can give the names for the constrains inorder to use the constraint on multiple columns.See the Syntax below

CONSTRAINT <Constraint_name> <constraints which we want>

ex:- CONSTRAINT pk_demo PRIMARY KEY

Just before the constraint which we want to give name put a keyword CONSTRAINT and then followed by user defined constrain name followed by actual constraint.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote