Question: 2 Supporting Advanced Constraints The requirement analysis also revealed certain behaviors and integrity the database must uphold when deployed. For this, you are required to

2 Supporting Advanced Constraints
The requirement analysis also revealed certain behaviors and integrity the database must uphold when deployed. For this, you are required to create appropriate views, functions and procedures, and triggers that allow the database to behave as expected.
2.1 Modifications to Student Table
When a new student is registered, a unique student_id is assigned to each student. A student_id is a 10-digit unique code, with the first four digits being entry_year, the next three characters are dept_id, and the last three digits are seq_number. When a new student is registered, your schema must validate this entry_number with the below conditions:
The entry_year and dept_id in student_id should be a valid entry in valid_entry table.
The sequence number should start from 001 for each department (maintained in valid_ent ry table). Thus, the current sequence number is assigned when a new student is registered in a department.
Create a trigger with the name of validate_student_id to validate the student_id. If the entry_number assigned to a student is not valid, then raise an "invalid" message; else, successfully insert the tuple in the table.
Example: Below is an instance of the valid_entry and student table.
\table[[dept_id,entry_year,seq_number],[CSZ,2020,1],[CSY,2024,3]]
Table 16: Entry in valid_entry table
\table[[first_name,last_name,student_id,address,contact_number,email_id,tot_credits,dept_id],[,,2024CSY001,,XXXXXXXXXX,"2024CSY001@CSY.iitd.ac.in,"0,CSY],[,,2024CSY002,,,2024CSY002@CSY.iitd.ac.in,10,CSY]]
Table 17: Valid student table
Below are the valid 18 and invalid 19 tuples for the student table. The correct entry should be inserted in the table, while the invalid entry should return the "invalid" message.
5
\table[[first_name,last_name,student_id,address,contact_number,email_id,tot_credits,dept_id],[XXxx,XXxx,2020CSZ001,XXXX,XXXXXXXXX,2020CSZ001@CSZ.iitd.ac.in,0,CSZ]]
Table 18: Valid entry in student table
\table[[first_name,last_name,student_id,address,contact_number,email_id,tot_credits,dept_id],[xxxx,xxxx,2021CSZ001,xxxx,xxxxxxxxxx,2020CSZ001@CSZ.iitd.ac.in,0,CSZ],[xxxx,xxxx,2020CSZ002,xxxx,xxxxxxxxxx,2020CSZ001@CSZ.iitd.ac.in,0,CSZ],[xxxx,xxxx,2020CS001,xxxx,xxxxxxxxxx,2020CSZ001@CSZ.iit.ac.in,0,CSZ],[xxxx,xxxx,2020CSY005,xxxx,xxxxxxxxxx,2020CSZ001@CSZ.iitd.ac.in,0,CSZ]]
Table 19: Invalid entry in student table [incorrect student_id]
2. If the above student_id is a valid id, you add that student detail in the student table. But do not forget to increase the counter, i.e., seq_number in valid_entry table after each insert in the student table. Thus, create a trigger with the name, update_seq_number, which will update the seq_number in valid_entry table.
Example: Once the valid student is inserted in the student table as shown in there should be an update in valid_entry table. The correct update based on the above-given instance for valid_entry table is shown below:
\table[[dept_id,entry_year,seq_number],[CSZ,2020,2],[CSY,2024,3]]
Table 20: Valid update in valid_entry table
 2 Supporting Advanced Constraints The requirement analysis also revealed certain behaviors

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!