Docsity

MySQL & DBMS Practical Notes — Complete Study Guide, Exercises of Database Management Systems (DBMS)

Toggle sidebar
bg1
DATABASE SYSTEMS LAB MANUAL
1 | P a g e
Introduction to the Relational Model
Topic: Tables, Rows, Columns, Domains, and Schemas
1. Objective:
By the end of this lab, students will be able to:
Explain the basic concept of the relational model.
Understand a relation/table.
Identify rows and columns in a relation.
Understand the concept of a domain.
Understand the meaning of a schema.
Differentiate between a table, row, column, and domain.
Create a simple relational table using MySQL Workbench.
Inspect a table structure using MySQL.
Relate theoretical concepts of the relational model to an actual database table.
2. HARDWARE AND SOFTWARE REQUIRED :
Hardware
PC/Laptop
Keyboard and Mouse
Internet connection
Software
MySQL Server
MySQL Workbench
Windows/Linux/macOS
Other Requirements
LMS access
Lab 01 database environment
Folder for screenshots and SQL files
3. INTRODUCTION TO RELATIONAL MODEL
The relational model is a database model in which data is organized into relations.
In practical database systems, a relation is commonly represented as a table.
For example:
STUDENT:
Student_ID Name Program Semester
101 Ali BSCS 3
102 Sara BSAI 2
103 Ahmed BECSE 4
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download MySQL & DBMS Practical Notes — Complete Study Guide and more Exercises Database Management Systems (DBMS) in PDF only on Docsity!

1 | P a g e

Introduction to the Relational Model

Topic: Tables, Rows, Columns, Domains, and Schemas

1. Objective:

By the end of this lab, students will be able to:  Explain the basic concept of the relational model.  Understand a relation/table.  Identify rows and columns in a relation.  Understand the concept of a domain.  Understand the meaning of a schema.  Differentiate between a table, row, column, and domain.  Create a simple relational table using MySQL Workbench.  Inspect a table structure using MySQL.  Relate theoretical concepts of the relational model to an actual database table.

2. HARDWARE AND SOFTWARE REQUIRED:

Hardware  PC/Laptop  Keyboard and Mouse  Internet connection Software  MySQL Server  MySQL Workbench  Windows/Linux/macOS Other Requirements  LMS access  Lab 01 database environment  Folder for screenshots and SQL files

3. INTRODUCTION TO RELATIONAL MODEL

 The relational model is a database model in which data is organized into relations.  In practical database systems, a relation is commonly represented as a table.  For example: STUDENT: Student_ID Name Program Semester 101 Ali BSCS 3 102 Sara BSAI 2 103 Ahmed BECSE 4

2 | P a g e This table represents student-related data.

4. WHAT IS A RELATION?

In the relational model, a relation represents a collection of related data. In a practical database, we usually see a relation as a table. For example: Student can be represented as: Student_ID Name Program 101 Ali BSCS 102 Sara BSAI Here, Student is the relation/table.

5. WHAT IS A ROW?

A row represents one record in a table. Example: Student_ID Name Program 101 Ali BSCS The complete record:is one row.

6. WHAT IS A COLUMN?

A column represents a particular attribute or type of information. In the following table: Student_ID Name Program 101 Ali BSCS 102 Sara BSAI

7. WHAT IS A DOMAIN?

A domain defines the set of valid values that can be stored in a particular attribute/column. For example: Age : A domain might contain: 18, 19, 20, 21, 22... Semester: A suitable domain might contain: 1, 2, 3, 4, 5, 6, 7, 8 Student_Name The domain consists of valid text values representing student names. In MySQL, data types help define what kind of values a column can store. For example: Student_ID INT and: Student_Name VARCHAR(50)

8. WHAT IS A SCHEMA?

4 | P a g e

Identify Relational Components

Consider this table: STUDENT Student_ID Name Program Semester 101 Ali BSCS 3 102 Sara BSAI 2 103 Ahmed BECSE 4 You must identify:

  1. What is the relation/table? Ans: Where rows and columns are in a relation. OR Relationship b/w Rows and Columns.
  2. How many rows are present? Ans: There are 3 rows present in it.
  3. How many columns are present? Ans: There are 4 Columns present in it.
  4. What are the column names? Ans: Columns are named as : Student_ID , Name , Program , and Semester.
  5. Give one example of a row. Ans: 102SaraBSAI2
  6. What could be the domain of Semester? Ans: As we know, there are 8 Semesters for any BS Field. So, domain of the Semester can be 8.
  7. What could be the domain of Program? Ans: All the programs that the respective University offers. It varies upon different universities. Like our uni SMIU offered BSAI for previous batches but now it’s not offering. So, this year BSAI is not included in the domain of Program. Deliverable Complete the identification in the lab manual.

PRACTICAL ACTIVITY 2

Create a Relational Table in MySQL Workbench

Open the database created in Lab 01. For example: USE UniversityDB; Create a table: CREATE TABLE Students ( Student_ID INT, Student_Name VARCHAR(50),

5 | P a g e Program VARCHAR(50), Semester INT ); Execute the command.

PRACTICAL ACTIVITY 3

View the Table Structure

Objective To identify the columns and their data types in a relational table. Execute: DESCRIBE Students; Observe the output.

7 | P a g e Ans: I used VARCHAR as a Data-type for Student_Name.

  1. Which column stores semester information? Ans: The Fourth Column naming Semester stores the Semester information.

PRACTICAL ACTIVITY 4

Create a Second Relational Table

Create a table named: Courses with suitable columns such as: CREATE TABLE Courses ( Course_ID INT, Course_Name VARCHAR(50), Credit_Hours INT, Department VARCHAR(50) ); Execute the command. Then execute: SHOW TABLES;

8 | P a g e Observe You should now see the tables inside your selected database. Task Identify:  Database/schema  Tables

10 | P a g e Relational Concept Your Database Example semesters can be added. FOR COURSES: FOR COURSES_NAME: Suggested by University. FOR CREDIT_HOURS: Credit hours can maybe 21, but not more than that for Bachelor’s degree. The max limit is 21 Hours. FOR DEPT: Again, Selected and offered by University Management. Discussion: You should explain how the table created in MySQL represents the relational model. Ans: First of all, I’d a database naming UNIVERSITYDB , it was shown in Schema. Then I created Tables having Columns and Rows. In Columns I specified data I required called as attributes , the table is empty table having no record in rows but, it is a table having row and columns. At the end, We have some limitations for every attribute for the accuracy of data, and that’s its Domain. I worked upon this model: Database ↓ Schema ↓ Table / Relation ↓ Columns ↓ Rows And: Column → Attribute / type of information Row → Record Domain → Valid set/type of values

11 | P a g e

LAB TASK

LAB TASK 1 : Create Table Create a table named: Books The table must contain at least 4 appropriate columns. You must choose suitable:  Column names  Data types LAB TASK 2 : Identify the Components For your Books table, identify: Relation/Table: BOOKS Columns: 4 COLUMNS(BOOK_NAME , BOOK_AUTHOR_NAME , BOOK_PUBLISHING_YEAR , AND BOOK_PRICE) Rows: NULL Domain of each column: 1)- BOOK_NAME  BOOK ONLY WRITTEN BY THE AUTHOR GIVEN. EXAMPLE: “THE POWER OF NOW”. 2)- BOOK_AUTHOR_NAME  ONLY THE AUTHOR OF THE BOOK. EXAMPLE: “ EKHART TOLLE”. 3)- BOOK_PUBLISHING_YEAR  ONLY THE REAL YEARS OF PUBLISHING BOOK. EXAMPLE: THE BOOK “ THE POWER OF NOW ” WAS FIRST PUBLISHED IN “ 1997 ”. 4)- BOOK_PRICE  THE ONLY REAL PRICE. EXAMPLE: RS.250/- TO RS.350/-. Schema/Database: COLLEGEDB

13 | P a g e . LAB TASK 5 : View Table Structures Use: DESCRIBE Books; and: DESCRIBE Authors;

14 | P a g e

Questions:

 Can a table contain only columns and no rows? Ans: Yes , In that case the table is called EMPTY TABLE.  Can a table contain multiple rows? Ans: Obviously , a table can contain multiple rows according to the rcords to put.  Can two columns of a table have different data types? Ans: Yes , two different columns can have two different data-types.  Why should a column have an appropriate domain? Ans: To take/get exact and accurate data , appropriate domain is used.  If a Semester column is defined as INT, should we store "Third Semester" in it? Why? Ans: No , we can’t. Cuz, we defined its data-type as INT , which means numbers/digits only. While, Third Semester requires data-type VARCHAR cuz it contains letters.