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

lab2

lab 2 databases ensia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

lab2

lab 2 databases ensia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

2nd Year /Semester3 (2024-2025)

DataBases

Lab sheet 2: DBMS administration

OBJECTIVES:

• Database Creation and Manipulation: This lab emphasizes the process of creating, managing, and querying a database.
• Static Integrity Constraints: Understanding and applying static integrity constraints to ensure data consistency.
• Schema Evolution: Exploring schema modifications and adaptations over time to meet evolving data requirements.

The following DB will be used throughout the labs during this semester.

Consider the " School Management System" database, the relational schema of which is given below:

STUDENT (StudentID, FirstName, LastName, BirthDate, Address, Email, Year)


COURSE (CourseID, CourseName, CourseCoef, CourseCredits)
ENROLLMENT (StudentID*, CourseID*, EnrollmentDate, FinalMark)
TEACHER (TeacherID, CIV, FirstName, LastName, Salary, Email, Grade)
COURSE_ASSIGNMENT (CourseID*, TeacherID*, StartDate, EndDate)
EXAM (ExamID, CourseID*, ExamDate, ExamType)
EXAM_RESULT (ResultID, StudentID*, ExamID*, Score)

In this schema:

- Attributes ending with Date are of type Date; CourseCredits and those ending with ID are
integers, and all others are strings, except for Salary, FinalMark and Score which are reals
- The Grade of a teacher is a string taken from the domain {'Assistant', 'Associate', 'Full Professor'}.
- The CIV attribute is a character string taken from the domain {'Mr', 'Miss', 'Mrs'}.
- ExamType could be Midterm, Final, or Quiz.
Student table:
StudentID FirstName LastName BirthDate Address Email Year
1 Cherifa Haddad 22/10/2005 city 1024 Logts, Djenane Sfari, Alger [email protected] 1
2 Amina Larbi 13/12/2006 city 2000 Logts, Ain Naadja, Alger [email protected] 1
3 Hayat Ouali 04/11/2005 city 3000 Logts, Bach Djerrah, Alger [email protected] 1
4 Leila Ait Aoudia 11/04/2004 city 1000 Logts, Belle Vue, Alger [email protected] 2
5 Farah Zidani 12/06/2004 city 100 Logts, Jolie Vue, Alger [email protected] 2
6 Nesrine Oukali 28/07/2004 city 200 Logts, Rue Hassiba, Alger [email protected] 2
7 Lamisse Chaabane 15/03/2003 city 301 Logts, Belle Court, Alger [email protected] 3
8 Sabrina Ben Aissi 23/03/2004 city 2030 Logts, Ben Aknoun, Alger [email protected] 2
9 Zahra Saoudi 17/02/2006 city 190 Logts, Bir Khadem, Alger [email protected] 1
10 Wardia Khaldi 06/05/2003 city 1024 Logts, Sidi Abdellah, Alger [email protected] 3
11 Narjis Merabet 05/11/2003 city 2000 Logts, El Harrache, Alger [email protected] 3
12 Douaa Jdid 11/09/2004 city 3000 Logts, Hay El Badr, Alger [email protected] 2
13 Dina Mendes 09/08/2004 city 1000 Logts, Mer et Soleil, Alger [email protected] 2
14 Khawla Ben Ali 14/06/2006 city 100 Logts, Les Fusiliers, Alger [email protected] 1
15 Ibtissam Bouklioua 17/05/2004 city 200 Logts, Aisset Idir, Alger [email protected] 2
16 Sajida Derbane 26/12/2003 city 1024 Logts, Djenane Sfari, Alger [email protected] 3
17 Abdelfattah Ait Mokhtar 29/01/2005 city 2000 Logts, Ain Naadja, Alger [email protected] 1
18 Tahar Amrane 19/04/2004 city 3000 Logts, Bach Djerrah, Alger [email protected] 2
19 Ali Ben Chikh 01/01/2004 city 1000 Logts, Belle Vue, Alger [email protected] 2
20 Hicham Bennour 08/10/2006 city 100 Logts, Jolie Vue, Alger [email protected] 1
21 Mustafa Ben Yattou 04/01/2003 city 190 Logts, Bir Khadem, Alger [email protected] 3
22 Adem Laichi 29/12/2004 city 1024 Logts, Sidi Abdellah, Alger [email protected] 2
23 Mohamed Kadourri 01/01/2005 city 2000 Logts, El Harrache, Alger [email protected] 1
24 Aymen Kadri 12/13/2022 city 190 Logts, Bir Khadem, Alger [email protected] 2

Course Table:
CourseID CourseName CourseCoef CourseCredits
1 Introduction to AI 4 6
2 Data Structures and Algorithms 1 3 6
3 Data Structures and Algorithms 2 4 5
4 Databases 3 5
5 Digital systems 3 4
6 ITE 2 4
7 Computer and network security 3 5
8 Probability 2 4
9 Web Development 2 6
10 Machine learning 4 6
11 Maths 1 3 6
12 Operating Systems 3 5
13 Data mining 4 5
14 Electronic Circuits 1 2
15 Object oriented programming 4 6

TEACHER Table:
TeacherID CIV FirstName LastName Salary Email Grade
1 Mrs Sajida Laichi 256000 [email protected] Full Professor
2 Miss Nesrine Kadouri 140000 [email protected] Associate
3 Mr Adem Ghezlane 84000 [email protected] Assistant
4 Mrs Douaa Bennour 149000 [email protected] Associate
5 Mr Mohamed Ben Ali 250000 [email protected] Full Professor
6 Mr Hakim Boutaleb 157000 [email protected] Associate
7 Miss Anfal Amrane 131000 [email protected] Associate
8 Mr Hicham Barkat [email protected] Associate
ENROLLMENT Table: EXAM Table:
StudentID CourseID EnrollmentDate FinalMark ExamID CourseID ExamDate ExamType
1 2 25/09/2023 1 1 25/03/2024 Quiz
2 2 26/09/2023 2 1 27/03/2024 Midterm
3 11 25/09/2023 3 1 26/04/2024 Final
9 5 28/09/2023 4 2 14/10/2023 Quiz
14 11 29/09/2023 5 2 15/11/2023 Midterm
17 6 25/09/2023 6 2 16/01/2024 Final
20 15 29/01/2024 7 3 14/10/2023 Quiz
23 2 24/09/2023 8 3 13/11/2023 Midterm
1 11 27/09/2023 9 3 16/01/2024 Final
2 11 26/09/2023 10 4 14/11/2023 Midterm
3 5 26/09/2023 11 4 15/01/2024 Final
9 11 25/09/2023 12 5 14/12/2023 Quiz
14 6 26/09/2023 13 5 17/11/2023 Midterm
17 15 28/01/2024 14 5 17/01/2024 Final
20 2 24/09/2023 15 6 12/10/2023 Midterm
23 11 24/09/2023 16 6 12/01/2024 Final
1 15 28/01/2024 17 7 22/03/2024 Midterm
2 15 25/09/2023 18 7 27/04/2024 Final
3 6 24/09/2023 19 8 22/11/2023 Midterm
5 12 29/01/2024 20 8 17/01/2024 Final
4 1 30/01/2024 21 9 19/11/2023 Midterm
6 3 27/09/2023 22 9 18/01/2024 Final
12 14 29/01/2024 23 10 25/02/2024 Quiz
8 4 28/09/2023 24 10 28/03/2024 Midterm
13 8 26/09/2023 25 10 29/04/2024 Final
15 9 24/09/2023 26 11 13/11/2023 Midterm
19 12 29/01/2024 27 11 18/01/2024 Final
5 1 04/02/2024 28 12 26/02/2024 Quiz
4 3 27/09/2023 29 12 23/03/2024 Midterm
6 14 28/01/2024 30 12 22/04/2024 Final
12 4 27/09/2023 31 13 10/10/2023 Midterm
13 12 29/01/2024 32 13 12/11/2023 Final
15 8 29/09/2023 33 14 01/05/2024 Final
19 1 30/01/2024 34 15 21/03/2024 Midterm
7 7 29/01/2024 35 15 01/05/2024 Final
11 13 26/09/2023
10 10 29/01/2024
16 7 02/02/2024 COURSE_ASSIGNMENT Table:
21 13 28/09/2023 CourseID TeacherID StartDate EndDate
7 10 29/01/2024 1 1 30/01/2024 02/02/2024
21 7 29/01/2024 2 3 24/09/2023 14/01/2024
7 13 26/09/2023 3 4 25/09/2023 14/01/2024
11 10 29/01/2024 4 2 25/09/2023 14/01/2024
10 7 29/01/2024 5 4 26/09/2023 14/01/2024
16 13 28/09/2023 6 7 24/09/2023 14/01/2024
2 16 28/09/2023 7 7 29/01/2024 23/05/2024
35 13 29/01/2024 8 5 26/09/2023 14/01/2024
9 3 24/09/2023 14/01/2024
10 4 29/01/2024 23/05/2024
11 2 25/09/2023 14/01/2024
12 6 29/01/2024 23/05/2024
13 1 25/09/2023 14/01/2024
14 6 28/01/2024 01/02/2024
15 2 28/01/2024 23/05/2024
1 23 28/01/2024 24/06/2024
19 2 24/09/2023 14/01/2024
EXAM_RESULT Table:
ResultID StudentID ExamID Score
1 1 1 14 60 11 25 10
2 1 2 13.5 61 12 33 14
3 1 3 15 62 12 10 15
4 1 26 18 63 12 11 13.5
5 1 27 14 64 13 19 15
6 1 34 16 65 13 20 9
7 1 35 14 66 13 28 12.5
8 2 1 13.5 67 13 29 10.25
9 2 2 15 68 13 30 0
10 2 3 15 69 14 26 13
11 2 26 18 70 14 27 10
12 2 27 10 71 14 15 14
13 2 34 15 72 14 16 15
14 2 35 18 73 15 19 13.5
15 3 26 14 74 15 20 15
16 3 27 14 75 15 21 9
17 3 12 13.5 76 15 22 12.5
18 3 13 15 77 16 17 10.25
19 3 14 9 78 16 18 14
20 3 15 12.5 79 17 15 15
21 3 16 10.25 80 17 16 13.5
22 4 1 11 81 17 34 15
23 4 2 8 82 17 35 9
24 4 3 12.5 83 19 28 12.5
25 4 7 13 84 19 29 10.25
26 4 8 10 85 19 1 14
27 4 9 14 86 19 2 15
28 5 1 15 87 19 3 13.5
29 5 2 18 88 20 34 15
30 5 3 14 89 20 35 9
31 5 28 12 90 20 4 12.5
32 5 29 13 91 20 5 10.25
33 5 30 15 92 20 6 14
34 6 7 13.5 93 21 31 15
35 6 8 15 94 21 32 10
36 6 33 9 95 21 17 14
37 7 17 12.5 96 21 18 15
38 7 18 10.25 97 23 4 13.5
39 7 23 13 98 23 5 15
40 7 24 10 99 23 6 9
41 7 25 14 100 23 26 12.5
42 7 31 13.5 101 23 27 10.25
43 7 32 15 102 2 40 12
44 8 10 9 103 34 26 11
45 8 11 12.5
46 9 12 10.25
47 9 13 13.5
48 9 14 15
49 9 26 9
50 9 27 12.5
51 10 23 10.25
52 10 24 14
53 10 25 15
54 10 17 13.5
55 10 18 15
56 11 31 9
57 11 32 12.5
58 11 23 10.25
59 11 24 13
It is advisable to create a user as well as the necessary objects to obtain more flexibility in the administration.

Creating a user requires at least two tablespaces, one default and one temporary. These operations must be performed as a
DBA (Data Base Administrator).

Some Syntaxes:

• Tablespace creation

CREATE TABLESPACE xxx_tbs DATAFILE 'C:\tbs_xxx.dat' SIZE 100M AUTOEXTEND ON ONLINE;

Description :

CREATE TABLESPACE xxx_tbs Specifies the name of the database tablespace.

DATAFILE 'C:\tbs_xxx.dat' SIZE 100M Specifies the full name of the system file and its size in megabytes.

AUTOEXTEND ON The size is increased automatically in case of saturation

ONLINE Available immediately upon creation

• Temporary Tablespace creation

CREATE TEMPORARY TABLESPACE xxx_TempTBS TEMPFILE 'C:\temp_xxx.dat' SIZE 100M AUTOEXTEND ON;

• User creation

Create User User_Name Identified by Password Default Tablespace Tablespace_Name Temporary Tablespace
Temp_Tablespace_Name;

• Grant all rights to the user:

GRANT ALL privileges to User_Name

• Table creation

CREATE TABLE [schema.] Table_name (column1 type1 [DEFAULT value1] [NOT NULL] [, column2 type2 [DEFAULT value2] [NOT
NULL] ] [CONSTRAINT constraintName1 constraintType1]);

Four types of constraints

➢ UNIQUE (column1[,column2])
➢ PRIMARY KEY (column1[,column2])
➢ FOREIGN KEY (column1 [,column2]) REFERENCES [schma.]parentTableName (column1 [,column2]) [ON DELETE {
CASCADE | SET NULL }]
➢ CHECK (condition)

To modify data without taking into account a constraint, this constraint must be deactivated:

ALTER TABLE tableName DISABLE CONSTRAINT constraintName;

To Activate a Constraint

ALTER TABLE tableName ENABLE CONSTRAINT constraintName [EXCEPTIONS INTO tableErrors];

Create the "tableErrors" table to identify the tuples that do not satisfy the constraint.

CREATE TABLE TableErrors (address ROWID, user VARCHAR2(30), tableName VARCHAR2(30), constraintName
VARCHAR2(30));
Required work
Week 1-LAB 2: Tables and Constraints Creation

Part I: Creating TableSpaces and Users


1. Create two TableSpaces School_TBS and School_TempTBS
2. Create a DBASchool user by assigning him the two tablespaces created previously
3. Grant all privileges to this user.
Part II: Data Definition Language
4. Create the basic relationships.
5. Add all constraints
6. List the problems you encountered
7. How did you correct them

Week 2-LAB 2: Updating the Structure

8. Add the HireDate attribute of Date type to the Teacher relationship.


9. Add the not null constraint for the Grade, Salary attributes of the Teacher relationship.
10. Modify the length of the FirstName attribute of the Teacher relationship (enlarge, reduce).
11. Delete the HireDate column in the Teacher table. Verify deletion.
12. Rename the Address column in the Student table to StudentAddress. Check.
13. Add the following constraint: The course start date must be less than its end date.

Week 2-LAB 2: Data manipulation language

14. Fill all the tables by the instances represented above


15. List the problems you encountered
16. How did you correct them
17. Suppose the salary of Pr.Sajida Laichi increased by 5000DA. What should be done?
18. For Courses in the month of January, add 5 five days to the start date. Disable constraint to allow editing.
Reactivate the constraint.
19. Delete all ‘Object oriented programming’ course. What are the problems encountered?
20. How did you correct them

You might also like