Midterm Copy1
Midterm Copy1
Haya
Systems Lab Abu-Raed
Question 1: using the following tables, answer the following sections with the
suitable SQL statements:
Section A:
1- Create a user named as student_ [your name] (1 mark)
2- Give your user all the privileges you might need. (1 mark)
Page 1 of 3
Section B:
1- Create the previous three tables (STUDENT, COURSES, and ENROLLMENTS) with appropriate
data types, constraints, and relationships between them, ensuring the following: (10 marks)
o The student’s ID does not exceed 9 digits as shown in the sample data.
o The student’s first name and course’s name cannot be empty.
o The student’s last name must allow a maximum of 100 characters.
o There must be no duplicates in the courses’ names.
o The student’s GPA consists of two digits as shown in the sample date.
2- Add a new column Email (max 100 characters) to the STUDENTS table. (1 mark)
5- Change the LastName column to allow a maximum of 50 characters instead of 100. (2 marks)
6- Add a default value of 3 to the Credits column in the Courses table. (1 mark)
7- Add a CHECK constraint named CHK_GPA that ensures GPA is between 0.0 and 4.0 (2 marks)
Page 2 of 3
10- Require the JoinDate column (originally EnrollmentDate) to automatically store the
current date if no value is provided. (1 mark)
11- Create a new user from your account named registerer and give him the suitable privileges
to retrieve, modify and add new students. (2 marks)
12- Remove the privilege to modify existing students from registerer. (1 mark)
Section C:
2- Change the password to password456 of your student_user account then lock it. (2 marks)
1- In your own words, explain the difference between the DROP and TRUNCATE commands
and their impact on database. (2 marks)
3- What SQL statement would you advise Omar to use if he is sure that he created a table called
Authors, but he still gets the error: table or view does not exist? (1 mark)
Page 3 of 3