0% found this document useful (0 votes)
8 views3 pages

Lab 9 (Mohamad Muizzuddin Bin Mohd Saat) Database

The document outlines the process of creating a MySQL database named FSTM, including the creation of three tables: SUBJECT, LECTURER, and STUDENT, with appropriate foreign key relationships. It also includes the insertion of sample data into these tables and several SQL queries to retrieve and join data from them. The final queries display relationships between students, subjects, and lecturers.

Uploaded by

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

Lab 9 (Mohamad Muizzuddin Bin Mohd Saat) Database

The document outlines the process of creating a MySQL database named FSTM, including the creation of three tables: SUBJECT, LECTURER, and STUDENT, with appropriate foreign key relationships. It also includes the insertion of sample data into these tables and several SQL queries to retrieve and join data from them. The final queries display relationships between students, subjects, and lecturers.

Uploaded by

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

C:\laragon\www

λ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 23
Server version: 8.0.30 MySQL Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its


affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CREATE DATABASE FSTM;


Query OK, 1 row affected (0.01 sec)

mysql> USE FSTM;


Database changed
mysql> CREATE TABLE SUBJECT (
-> SubjectCode VARCHAR(10) PRIMARY KEY,
-> Name VARCHAR(100),
-> CreditHours INT
-> );
Query OK, 0 rows affected (0.04 sec)

mysql> CREATE TABLE LECTURER (


-> staffID VARCHAR(10) PRIMARY KEY,
-> Name VARCHAR(100),
-> Department VARCHAR(100),
-> SubjectCode VARCHAR(10),
-> FOREIGN KEY (SubjectCode) REFERENCES SUBJECT(SubjectCode)
-> );
Query OK, 0 rows affected (0.11 sec)

mysql> CREATE TABLE STUDENT (


-> matricNo VARCHAR(10) PRIMARY KEY,
-> Name VARCHAR(100),
-> Programme VARCHAR(100),
-> LecturerID VARCHAR(10),
-> SubjectCode VARCHAR(10),
-> FOREIGN KEY (LecturerID) REFERENCES LECTURER(staffID),
-> FOREIGN KEY (SubjectCode) REFERENCES SUBJECT(SubjectCode)
-> );
Query OK, 0 rows affected (0.04 sec)

mysql> INSERT INTO SUBJECT (SubjectCode, Name, CreditHours) VALUES


-> ('DTCP3233', 'Web Development', 4),
-> ('DTCE3103', 'Database System', 3),
-> ('DTCP4564', 'FOP', 3),
-> ('DTCA4547', 'Fundamentals of E-commerce', 3);
Query OK, 4 rows affected (0.33 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> INSERT INTO LECTURER (staffID, Name, Department, SubjectCode) VALUES


-> ('M22', 'Shikin', 'Multimedia', 'DTCP3233'),
-> ('M23', 'Farhana', 'Science Comp', 'DTCE3103'),
-> ('M24', 'Illiana', 'Science Comp', 'DTCP4564'),
-> ('M25', 'Haniza', 'E-Commerce', 'DTCA4547');
Query OK, 4 rows affected (0.06 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> INSERT INTO STUDENT (matricNo, Name, Programme, LecturerID, SubjectCode)


VALUES
-> ('S13', 'Faishal', 'DIT', 'M22', 'DTCP3233'),
-> ('S14', 'Nizam', 'DCS', 'M23', 'DTCE3103'),
-> ('S15', 'Naifah', 'DCS', 'M24', 'DTCP4564'),
-> ('S46', 'Aina', 'DEC', 'M25', 'DTCA4547');
Query OK, 4 rows affected (0.01 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> SELECT * FROM SUBJECT;


+-------------+----------------------------+-------------+
| SubjectCode | Name | CreditHours |
+-------------+----------------------------+-------------+
| DTCA4547 | Fundamentals of E-commerce | 3 |
| DTCE3103 | Database System | 3 |
| DTCP3233 | Web Development | 4 |
| DTCP4564 | FOP | 3 |
+-------------+----------------------------+-------------+
4 rows in set (0.00 sec)

mysql> SELECT * FROM LECTURER;


+---------+---------+--------------+-------------+
| staffID | Name | Department | SubjectCode |
+---------+---------+--------------+-------------+
| M22 | Shikin | Multimedia | DTCP3233 |
| M23 | Farhana | Science Comp | DTCE3103 |
| M24 | Illiana | Science Comp | DTCP4564 |
| M25 | Haniza | E-Commerce | DTCA4547 |
+---------+---------+--------------+-------------+
4 rows in set (0.00 sec)

mysql> SELECT * FROM STUDENT;


+----------+---------+-----------+------------+-------------+
| matricNo | Name | Programme | LecturerID | SubjectCode |
+----------+---------+-----------+------------+-------------+
| S13 | Faishal | DIT | M22 | DTCP3233 |
| S14 | Nizam | DCS | M23 | DTCE3103 |
| S15 | Naifah | DCS | M24 | DTCP4564 |
| S46 | Aina | DEC | M25 | DTCA4547 |
+----------+---------+-----------+------------+-------------+
4 rows in set (0.00 sec)

mysql> SELECT STUDENT.Name AS StudentName, SUBJECT.Name AS SubjectName


-> FROM STUDENT
-> JOIN SUBJECT ON STUDENT.SubjectCode = SUBJECT.SubjectCode;
+-------------+----------------------------+
| StudentName | SubjectName |
+-------------+----------------------------+
| Faishal | Web Development |
| Nizam | Database System |
| Naifah | FOP |
| Aina | Fundamentals of E-commerce |
+-------------+----------------------------+
4 rows in set (0.08 sec)
mysql> SELECT STUDENT.Name AS StudentName, SUBJECT.Name AS SubjectName,
LECTURER.Name AS LecturerName
-> FROM STUDENT
-> JOIN SUBJECT ON STUDENT.SubjectCode = SUBJECT.SubjectCode
-> JOIN LECTURER ON STUDENT.LecturerID = LECTURER.staffID;
+-------------+----------------------------+--------------+
| StudentName | SubjectName | LecturerName |
+-------------+----------------------------+--------------+
| Faishal | Web Development | Shikin |
| Nizam | Database System | Farhana |
| Naifah | FOP | Illiana |
| Aina | Fundamentals of E-commerce | Haniza |
+-------------+----------------------------+--------------+
4 rows in set (0.00 sec)

mysql> SELECT STUDENT.Name AS StudentName, SUBJECT.*


-> FROM STUDENT
-> JOIN SUBJECT ON STUDENT.SubjectCode = SUBJECT.SubjectCode;
+-------------+-------------+----------------------------+-------------+
| StudentName | SubjectCode | Name | CreditHours |
+-------------+-------------+----------------------------+-------------+
| Faishal | DTCP3233 | Web Development | 4 |
| Nizam | DTCE3103 | Database System | 3 |
| Naifah | DTCP4564 | FOP | 3 |
| Aina | DTCA4547 | Fundamentals of E-commerce | 3 |
+-------------+-------------+----------------------------+-------------+
4 rows in set (0.00 sec)

mysql> SELECT LECTURER.Name AS LecturerName, SUBJECT.Name AS SubjectName,


SUBJECT.CreditHours
-> FROM LECTURER
-> JOIN SUBJECT ON LECTURER.SubjectCode = SUBJECT.SubjectCode;
+--------------+----------------------------+-------------+
| LecturerName | SubjectName | CreditHours |
+--------------+----------------------------+-------------+
| Shikin | Web Development | 4 |
| Farhana | Database System | 3 |
| Illiana | FOP | 3 |
| Haniza | Fundamentals of E-commerce | 3 |
+--------------+----------------------------+-------------+
4 rows in set (0.00 sec)

mysql>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy