I'm new to Oracle SQL and I am having a hard time adding a constraint. I am trying to add constraints on my table to enforce specific business rules that only allows students only to take 4 courses and a max of 25 students per class.
Please let me know what additional information you need from me to help answer this question. I am at a loss...
CREATE TABLE GRADES
(STU_ID int NOT NULL ENABLE,
CRSE_ID CHAR(9) NOT NULL ENABLE,
STU_CRSE_GRADE VARCHAR2(20)
check(STU_CRSE_GRADE='A' or
STU_CRSE_GRADE='B' or
STU_CRSE_GRADE='C' or
STU_CRSE_GRADE ='D' or
STU_CRSE_GRADE= 'F'),
CONSTRAINT GRADES_PK PRIMARY KEY (STU_ID, CRSE_ID),
constraint fk_Grades Foreign key(Stu_ID)
REFERENCES Students,
constraint fk_Grades_Crse_ID foreign key(Crse_ID)
REFERENCES Courses
);
No problem! See tables below:
CREATE TABLE Students
(Stu_ID int Constraint pk_Stu_ID Primary Key,
Stu_name VARCHAR(255) NOT NULL, Stu_Add varchar(255),
Stu_Maj CHAR(6)
);
CREATE TABLE Instructors
(Instr_ID char(3) Constraint pk_Instr_ID Primary Key,
Instr_Name VARCHAR(255) NOT NULL, Instr_Office varchar(8)
);
CREATE TABLE Courses
(Crse_ID char(9) Constraint pk_Crse_ID Primary Key,
Crse_Title VARCHAR(255) NOT NULL,
Student’s name: Lai Xia
Instr_ID CHAR(3) not null,
constraint fk_Courses_Instr_ID Foreign key(Instr_ID) REFERENCES Instructors
);
gradestable doesn't appear to be relevant to your question-- you'd need to post the tables that are. The rules you listed here do not appear to be the sort of thing that you can enforce with constraints, they are probably the sort of thing that you'd enforce with triggers if this is a homework assignment. Triggers would create other issues in the real world.