0% found this document useful (0 votes)
11 views8 pages

Practical Work 01-Correction

The document outlines practical work for a DB2 module at Ferhat Abbas University, focusing on database creation and management using PHP MyAdmin and SQL commands. It includes instructions for creating databases, tables, establishing relationships, and inserting records into the TRAVELER, FLIGHT, and RESERVATION tables. Additionally, it covers modifying table structures and provides example SQL code for various operations.

Uploaded by

rriiaaddhh123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views8 pages

Practical Work 01-Correction

The document outlines practical work for a DB2 module at Ferhat Abbas University, focusing on database creation and management using PHP MyAdmin and SQL commands. It includes instructions for creating databases, tables, establishing relationships, and inserting records into the TRAVELER, FLIGHT, and RESERVATION tables. Additionally, it covers modifying table structures and provides example SQL code for various operations.

Uploaded by

rriiaaddhh123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Ferhat Abbas University - Setif 1

Computer Science department


Academic Year 2024-2025
Module: Module: DB2 (1st year Big Data)

Database Practical Work 01


A. Using the PHP MyAdim graphical interface:
Right click on The Easy PHP icon in the task bar.
Choose Administration.

A web page opens, click on the “Open” button of the Php MyAdmin module.

Choose the “Database” tab.


Give the database a name and click “create”.

Click on “New Table”..

Fill in the table fields, then click “Save”.


O We can now select the tables, use the INSERT tab to insert the records and the
Display tab to view them….

Create relationships between tables: Foreign keys


1. Choose the database directory "L2".
2. Click on more (1), then on “Designer”. (2)
3. Click on “New Relation” (1)
4. In the “Flight” table, click on the “NoFL” reference field (2), then click on the “NoFl”
field in the “Reservation” table (3).
5. Choose ON DELETE “Cascade” (4) and ON UPDATE “Cascade” (5) in the window
that appears.

6. The relationships will be created as follows:


Delete a relationship:
To delete a relationship, double-click on the relationship link, then click "Delete".

B. Using SQL DDL commands:


To drop database, we can use: DROP DATABASE L2;
We can create the database using SQL code:
CREATE DATABASE IF NOT EXISTS L2;
You must first select the Data Base as follows: In the “Database” tab, Check the box in front
of “L2” then click on L2.

After the selection, we can notice that we are in the “L2” database directory.
Click on the SQL tab, then write the SQL code in the SQL code editor, finally click on the
“Execute” button in the right bottom of the code editor.

SQL code:
Creating Database:
CREATE DATABASE IF NOT EXISTS L2;
---------------------------------------------------------------------
 Create the TRAVELER table:
USE L2;/* To use if the case of DB has not been selected. */
DROP TABLE IF EXISTSTRAVELER;
CREATE TABLE TRAVELER(
NoTR INT PRIMARY KEY,
LastName VARCHAR(20)UNIQUE NOT NULL,
FirstName VARCHAR(20)NOT NULL,
BirthDat DATE,
Gender SET ('M', 'F') DEFAULT 'M'
);
------------------------------------------
 Create the FLIGHT table:
DROP TABLE IF EXISTS FLIGHT;
CREATE TABLE FLIGHT (
NoFL INT PRIMARY KEY,
Destination SET ('Algiers', 'Bejaia', 'Constantine', 'Oran', 'Ouargla', 'Sétif') DEFAULT
'Algiers',
FlightDat DATE,
DepartTime TIME,
NbrPlaces INT DEFAULT 100,
CONSTRAINT Limit_Nbr_Pl CHECK (NbrPlaces>=100)
);
Note: If we use MySQL 8.0.15 or earlier, The CHECK clause is parsed but ignored by all
storage engines (In other word it doesn’t work).
------------------------------------------------
 Create the RESERVATION table:
DROP TABLE IF EXISTS RESERVATION;
CREATE TABLERESERVATION (
NoTRINT,
NoFLINT,
PRIMARY KEY(NoTR,NoFL),
CONSTRAINT FK_1 FOREIGN KEY (NoTR) REFERENCES TRAVELER (NoTR) ON UPDATE
CASCADEON DELETE RESTRICT,
CONSTRAINT FK_2 FOREIGN KEY (NoFL) REFERENCES FLIGHT(NoFL) ON UPDATE
CASCADE ON DELETE RESTRICT
);
 Deleting Gender column:
ALTER TABLE TRAVELER DROP COLUMN GENDER;
 Adding Gender column:
ALTER TABLE TRAVELER ADDCOLUMN GENDER SET ('M', 'F') DEFAULT 'M';
 Remove the default value from the Number of places:
ALTER TABLE FLIGHT ALTER NbrPlaces DROP DEFAULT;
C. Using SQL DML commands:
 Insert tuples (Records) into each table.
Inserting tuples in the FLIGHT table:
INSERT INTO FLIGHT VALUES (1000,'Algiers','2024-03-01','80:00',200);
INSERT INTO FLIGHT VALUES (1001,'Oran','2024-03-01','13:00',150);
INSERT INTO FLIGHT VALUES (1002, Default,'2024-03-02','12:00',120);
INSERT INTO FLIGHT VALUES (1003,'Ouargla','2024-03-03','80:00',100);
INSERT INTO FLIGHT VALUES (1004,'Bejaia','2024-03-05','20:00',180);
INSERT INTO FLIGHT VALUES (1005,'Sétif','2024-03-06','06:00',200);

Inserting tuples in the TRAVELER table:


We will use different syntaxes to insert travelers.All of these syntaxes are correct.
INSERT INTO TRAVELER (NoTR, LastName, FirstName, BirthDat, Gender) VALUES (1, 'Aissani',
'Mohamed', '1970-01-01', 'M');
INSERT INTO TRAVELER (NOTR, LastName, FirstName, BirthDat, Gender) VALUES (2, 'Mohamedi',
'Mustafa', '1980-07-05', default);
INSERT INTO TRAVELER (NoTR, LastName, FirstName, BirthDat, Gender) VALUES (3, 'Yahiaoui',
'Djamila', '1987-04-02', 'F');
INSERT INTO TRAVELER VALUES (4, 'Smaili', 'Faiza', '1990-09-18', 'F');
INSERT INTO TRAVELER VALUES (5,'Brahimi', 'Mohamed', '1976-12-23', Default);
INSERT INTO TRAVELER VALUES (6,'Mostefaoui', 'Kamel', '1990-12-12', Default);

Inserting records into RESERVATION table:


INSERT INTO RESERVATION VALUES (1,1000);
INSERT INTO RESERVATION VALUES (2,1000);
INSERT INTO RESERVATION VALUES (3,1001);
INSERT INTO RESERVATION VALUES (4,1002);
INSERT INTO RESERVATION VALUES (1,1002);
INSERT INTO RESERVATION VALUES (5,1002);
INSERT INTO RESERVATION VALUES (3,1003);

You might also like