0% found this document useful (0 votes)
4 views

Midterm Copy2

Uploaded by

hayamousa78
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Midterm Copy2

Uploaded by

hayamousa78
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Course's Name: Database Palestine Technical University-Kadoorie Instructor’s Name: Eng.

Haya
Systems Lab Abu-Raed

Course's Number: 12140314 Student’s Name: ______________

Exam’s Period: 2 hours Student’s Number: ____________

Number of Pages: 3 Section’s Number: 2


Midterm Exam
Total Mark: 35 First Semester 2024-2025 Exam’s Date: 18/11/2024

Question 1: using the following tables, answer the following sections with the
suitable SQL statements:

Table 1 Sample Data - Employees Table


ID FirstName LastName HireDate Salary
1001 Lina Ahmad 2021-03-01 1200.50
1002 Omar Khalid 2022-05-12 1350.00
1003 Rania Hasan 2023-08-20 1500.75
1004 Nabil Saleh 2023-09-01 1600.00

Table 2 Sample Data - Departments Table


ID Name Budget
1 IT 5000.00

2 HR 3000.00

3 Marketing 4000.00

Table 3 Sample Data - Assignments Table


ID EmployeeID DepartmentID AssignedDate Description
Lorem ipsum
1 1001 1 2024-09-15
dolor sit amet,
2 1003 3 2024-09-10 Lorem ipsum
3 1004 1 2024-09-20 Lorem ipsum

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 EMPLOYEES, DEPARTMENTS, and ASSIGNMENT tables with appropriate data
types, constraints, and relationships between them, ensuring the following: (10 marks)

o The employee’s ID does not exceed 4 digits as shown in the sample data.
o The employee’s first name and department’s name cannot be empty.
o The employee’s last name must allow a maximum of 50 characters.
o The employee’s salary consists of two digits as shown in the sample date.
o There must be no duplicates in the departments’ names.

2- Add a new column PhoneNumber (max 15 characters) to the EMPLOYEES table. (1 mark)

3- Rename the HireDate column to StartDate in the EMPLOYEES table. (1 mark)

4- Remove the Budget column from the DEPARTMENTS table. (1 mark)

5- Change the LastName column to allow a maximum of 30 characters instead of 50. (2 marks)

6- Set a default value of 1000.00 for the Budget column in the DEPARTMENTS table. (1 mark)

7- Ensure that Salary is between 1000.00 and 5000.00 with constraint named CHK_SALARY
(2 marks)

8- Rename the ASSIGNMENTS table to EMPLOYEE_DEPARTMENT. (1 mark)

9- Remove the constraint CHK_SALARY from the EMPLOYEES table. (1 mark)

Page 2 of 3
10- Require the StartDate column (originally HireDate) to automatically store the current
date if no value is provided. (1 mark)

11- Create a new user from your account named hr and give him the suitable privileges to
retrieve, modify and add new employees. (2 marks)

12- Remove the privilege to modify existing employees from hr. (1


mark)

Section C:

1- Remove the hr user. (1 mark)

2- Change the password to password456 of your student_user account then lock it. (2 marks)

Question 2: answer the following questions

1- In your own words, explain the difference between the DROP and TRUNCATE commands
and their impact on database. (2 marks)

2- There is a DML command that can be used to achieve a similar effect as


the TRUNCATE command. Identify this command and explain the difference between them?
(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

You might also like