Download as pdf or txt
Download as pdf or txt
You are on page 1of 33

DATABASE SYSTEMS

Course Code CSC 352

Laboratory Manual

Department of Computer Science


Lahore Garrison University
Main Campus, Sector-C Phase-VI, DHA Lahore
Guidelines for Laboratory Procedure

The laboratory manual is the record of all work on your experiments. A complete, neat, and organized data

record is as important as the experiment itself. Please follow these guidelines for efficient performance in the

laboratory:

1. Attend the lab orientation to familiarize yourself with the lab setup.

2. Follow the designated lab schedule and complete assignments on time.

3. Write clear and well-documented code, avoiding plagiarism and unauthorized collaboration.

4. Seek help from lab instructors or peers if you encounter difficulties with programming concepts.

5. Regularly back up your code and project files to prevent data loss.

6. Use lab resources responsibly, including computers and software licenses.

7. If collaboration is allowed, work effectively with peers, ensuring each member contributes meaningfully.

8. Maintain a clean and organized workspace for better focus and efficiency.

9. Thoroughly test your code to identify and fix errors before submission.

10. Engage in lab discussions, share insights, and actively participate to enhance the learning experience.
Safety Precautions

1. Handle equipment carefully to prevent damage and avoid placing liquids near electronic devices.

2. Maintain an ergonomic workspace for comfortable and strain-free programming.

3. Save work frequently and use surge protectors to prevent data loss due to power issues.

4. Keep software and antivirus programs up to date and avoid downloading from untrusted sources.

5. Regularly back up code and important files to prevent data loss.

6. Establish clear communication and collaboration guidelines when working with others.

7. Be aware of emergency exits, fire extinguisher locations, and evacuation procedures.


Safety Undertaking

I have read all of the above, and I agree to conform to its contents.

Name: ______________________________________

Registration No.: _____________________________

Student Signature: ____________________________

Date: _______________________________________

Lab Instructor:
Grading Policy
Lab Performance 15%
Lab Report 15%
Lab Project +Viva 20%+10%
Final Lab Exam 40%

Rubrics
Lab Performance (Continuous Assessment) / Performance Test

Sr.No. Performance Exemplary Satisfactory Unsatisfactory


Indicator (4-5) (2-3) (0-1)

1 Fully understand the Has very good Has poor


software including its understanding of understanding of
Ability to Conduct features, working and the software the software
Practical quite able to conduct including its including its
the entire practical features, working features, working
with negligible help and able to and unable to
from lab instructor conduct practical conduct practical
with some help on his own;
from lab
instructor
2 Always analyzes and Analyzes and Analyzes and
Data Analysis & interprets data interprets data interprets data
Interpretation correctly and always correctly most of incorrectly
display correct output; the time; most of most of the
always compares the output are time; many
theory against correct; output are
practical results and compares theory incorrect;
resolve related error. against practical most of the
results and time never
resolve related attempts to
error most of the compare
time. theory against
practical
results.
Lab Reports

Sr. Performance Exemplary (4-5) Satisfactory (2-3) Unsatisfactory


Indicator (0-1)
1 All the code is Most of the Some of or complete
Structure very accurate and code is very code is inaccurate.
precise. accurate and Somewhat or no logical
Completely precise. Quite and systematic
logical and logical and compilation.
systematic systematic
compilation. compilation.

2 Efficiency The code is fairly The code The code is huge and
efficient without is brute appears to be patched
force and
sacrificing unnecess together.
readability and arily long.
understanding.

Viva Voce

Sr Performance Exemplary Satisfactory (2- Unsatisfactory


Indicator (4-5) 3) (0-1)

1 Responds well, Generally Non-responsive.


Responsiveness quick and very Responsive and
to Questions/ accurate all the accurate most of
Accuracy time. the times.

2 Level of Demonstration of At ease with No grasp of information.


understanding of full knowledge of content and able Clearly no knowledge of
the learned skill the subject with to elaborate and subject matter. No
explanations and explain to some questions are answered.
elaboration. degree. No interpretation made.
Lab Project

Sr.No. Performance Exemplary Satisfactory (2-3) Unsatisfactory


(4-5) (0-1)
Project Design
1 Implementation Project is Project is Project is completed but
and Completion completed without completed with not working properly. Or
any external quite less technical Project is not
assistance and is assistance from completed.
working properly. the instructor or
others in order to
complete the
project and is
working properly.
2 Appearance and Circuit wiring and Circuit wiring and Circuit wiring and
Problem components are components are components are
Analysis perfectly organized organized and disorganized but some
and proper some prototyping prototyping is done.
prototyping is is done.
done.
Project Report
1 Structure and Information is
Information is
Literature Review presented in a
presented in a
less logical way, Information is not
logical,
which is little presented in a logical,
interesting way,
difficult to interesting way, which
which is easy to
follow. All is so difficult to follow.
follow. All
sections are in a All sections are
sections are in a
little incorrect incorrect order or not
correct order and
order or submitted on a time.
submitted on a
submitted little Collected a poor
time. Collected a
late time. information--all
great deal of
Collected a fine doesn’t relates to the
information--all
information—all topic.
relates to the
may relates to
topic.
the topic.
2 Result and Clearly discusses Generally clear
Presentation what results discussion of
Limited discussion
mean results and
of results and
and what conclusions, but
conclusions. Little
conclusions may may miss some
or no reference to
be points. Some use
published standards
drawn from them. of references and
or other reports.
Cites published published
standards or standards.
other
related reports.

Project Viva
Responds well, Generally Non-responsive.
Responsiveness to quick and very Responsive and
1
Questions/ accurate all the accurate most of
Accuracy time. the times.
Demonstration of At ease with No grasp of
full knowledge of content and able information. Clearly no
Level of
the subject with to elaborate and knowledge of subject
2 understanding of
explanations and explain to some matter. No questions
the learned skill
elaboration. degree. are answered. No
interpretation made.
Project Presentation
Presentation is
Presentation is
clear Listener can follow
generally clear.
and logical. presentation with
A
1 Organization Listener can effort.
few minor points
easily Organization not
may be
follow line of well thought out.
confusing
reasoning
Is very confident
and explains the
details properly. Is confident to Has low confidence to
Proper eye some extent explain and deliver
contact is with quite less topic properly. Less
2 Confident
maintained all eye contact and eye contact and
the time with presentational presentational
proper gestures. gestures used.
presentational
gestures.
Responds well to
Reluctantly interacts
questions. Generally
Responsiveness to with audience.
3 Restates responsive to
Audience Responds poorly to
and summarizes questions.
questions.
when needed.
Team Work
Relays very little
Share Relays some basic
1 Relays a great deal information--some
Information information--most
of relates to the topic
information--all relates
relates to to the topic.
the topic.
Performs all duties
Performs nearly
Fulfill Team of Performs very little
2 all
duties assigned team duties.
duties
role
Lab’s Course Learning Outcomes
Course Title: Database Systems
Course Code: CSC-352
Instructor: Ms. Batool Abbas
Designation: Lecturer
E-mail: batoolabbas@lgu.edu.pk
Students will be able to:
To provide a classroom and laboratory environment that enables students to become proficient C++
programmers.
• Students are not assumed to have a background in computer programming and therefore
introductory material on software engineering and program development will be presented.
• However, most of the course will be on the specifics of the C++ language. Students completing this
course will be able to compile various programs in text-user-interface computer language.
• Students can write the basic structure of C++ programs, perform programming experiments in C++
language, and develop techniques to solve problems.

CLO1: Formulate SQL query to access data within the relational databases.
CLO2: Use structured query language (SQL) to manage database systems and extract data efficiently.
Mapping of Course Learning Outcomes (CLO) to Program Learning Outcomes (PLO) / Graduate
Attributes
Course Code
CLOs/ PLOs PLO 1 PLO 10
PLO2 PLO3 PLO4 PLO5 PLO6 PLO7 PLO8 PLO9
CLO 1
X
CSC-351
CLO2
X

PLO1: Academic Education


PLO2: Knowledge for Solving Computing Problems
PLO3: Problem Analysis
PLO4: Design/ Development of Solution
PLO5: Modern Tool Usage
PLO6: Individual and Teamwork
PLO7: Communication
PLO8: Computing Professionalism and Society
PLO9: Ethics
PLO10: Lifelong Learning
Sr.No List of practical CLO’s

1 Introduction of Database Systems and its Practical Use Installation of SQL 1


Server and SSMS.
2 Create Database and table in SQL, DDL, DML, and DCL commands 1

3 Select, From, Where all related Queries in SQL, Distinct, and Order by clause 1

4 Arithmetic Operators in SQL., Logical and Relational Operators In SQL. 1

5 Group functions, Having clause, Column, and Table Alias. 1

6 Commands to Alter Table, Add or Drop a Column, update data 1

7 Use queries Delete Table and a Row, Truncate a Table in SQL. 1

8 JOINS in SQL Server 1

9 Subqueries 2

10 Single Row functions in SQL 2

11 Stored Procedure and Views 2

12 Introduction to Triggers and its type 2

13 Views and its types 2

14 CRUD operations using C# language with SQL server 2


PRACTICAL NO.01
Introduction of Database Systems and its Practical Use & Installation of
SQL Server and SSMS.

PLO CLO LL
Objectives:
5 1 P2
The objectives of this first experiment are:

• Installation of SQL server and SSMS.


• Create a new database named Northwind.
• Restore Schema using scripts Northwind. SQL.
• Restore schema data using northwind_data.sql.

Activity:

1. System Requirements for SQL Server 2019

1.1. Operating system

Windows 10 TH1 1507 or greater and Windows Server 2016 or greater


1.2. .NET Framework

SQL Server 2016 (13. x) RC1 and later require .NET Framework 4.6 for the Database Engine, Master Data
Services, or Replication. SQL Server setup automatically installs .NET Framework. You can also manually
install .NET Framework from Microsoft .NET Framework 4.6 (Web Installer) for Windows.

1.3. Disc Space

SQL Server requires a minimum of 6 GB of available hard disk space.


1.4. Memory

At least 4 GB should be increased as database size increases to ensure optimal performance.


1.5. Processor

• Minimum: x64 Processor: 1.4 GHz, Recommended: 2.0 GHz or faster

• x64 Processor: AMD Opteron, AMD Athlon 64, Intel Xeon with Intel EM64T support,
Intel Pentium IV with EM64T support

1.6. Monitor

SQL Server requires Super-VGA (800x600) or higher resolution monitor.


2. Installation guide

Important Note:

2.1. connect your system with the internet and download the developer
edition using this given link: https://www.microsoft.com/en-us/sql-
server/sql-server-downloads
2.2. Login on window as Administrator

1:
2.3. Once downloaded then click on the .exe file and run.
2.4. Then click on Basic version to install.

Figure2: Selection of basic version


2.5. Scroll down and then click on accept.

Figure: Terms and conditions for installing SQL Server

2.6. Click on Install and eat popcorn until installation is done.


2.7.After installation is done click on install SSMS

Figure5:

2.8.Click on the highlighted link. It will download the. file of SSMS. After downloading run the .exe file.
Figure6: Version of SSMS for installation
2.9. Click on Install and wait until installation is done successfully.

Figure 7: Installation of SS
3. Generate Scripts of a schema

• Step 1

Right click on your database and select Task -> generate script.

Figure 8: Database_Scripts_With_Data_Select_Option
Database system Lab
Department of Computer Science

• Step 2

Click next in the introduction screen

Figure 9: Database_Scripts_With_Data_Introduction

DATABASE MANAGEMENT SYSTEMS LAB 20


Database system Lab
Department of Computer Science

• Step 3

Select the database object which you are all you need and then click next.

Figure 10: Selecting database objects

DATABASE MANAGEMENT SYSTEMS LAB 21


Database system Lab
Department of Computer Science

• Step 4

Now you will be shown a window which asks you about how your script should be published.

Figure 11: Database_Scripts_With_Data_Publish_Options

Click on advanced in that window.

DATABASE MANAGEMENT SYSTEMS LAB 22


Database system Lab
Department of Computer Science

• Step 5

Select ‘Schema and data’ from the type of data to the script option and then click OK.

Figure 12: Database_Scripts_With_Data_Advanced Click on Next.

P a g e 23 | 33
Database system Lab
Department of Computer Science

• Step 6

Click finish, now check the script file, it must have the insert queries too.

Figure 13: Database_Scripts_With_Data_Finish

Now what else is pending, go ahead and run your script.

Lab Tasks
1. Create a new database named TestDB_2022_CS

2. Create a new table named student using some attributes

P a g e 24 | 33
Database system Lab
Department of Computer Science

CONCLUSION:
________________________________________________________
________________________________________________________
________________________________________________________
________________________________________________________

RUBRICS:

Performance Lab Report

Description Total Marks Description Total Marks


Marks Obtained Marks Obtained
Ability to 5 5
Conduct Structure
practical
5 5
Data Analysis &
Efficiency
Interpretation
Total Marks obtained Total Marks Obtained

Instructor Signature: ________________________

P a g e 25 | 33
Database system Lab
Department of Computer Science

PRACTICAL NO.02
DML, DDL, and DCL commands

PLO CLO LL
5 1 P2

Objectives:
This lab provides an:
1. To create a database and table using SQL, Briefing various commands
and their use.
2. DDL command description and practice.

Structured query language is mainly divided into 5 sub-languages.

DDL (DATA DEFINITION LANGUAGE)


1) CREATE DATABASE
Create a database name; Example:
Create database LGU;
2) DROP DATABASE
Drop database database name; Example:
Drop database LGU;
3) CREATE TABLE
CREATE TABLE table_name ( column1 datatype, column2 datatype,
column3 datatype,
....
);

Example:
CREATE TABLE Persons ( PersonID int, LastName varchar(255),
FirstName varchar(255), Address varchar(255), City varchar(255)
);
4) DROP TABLE:
DROP TABLE table_name; Example:
DROP TABLE Shippers;

5) TRUNCATE TABLE:

P a g e 26 | 33
Database system Lab
Department of Computer Science

The TRUNCATE TABLE statement is used to delete the data inside a table,
but not the table itself.

TRUNCATE TABLE table_name;

6) ALTER TABLE:

The ALTER TABLE statement is used to add, delete, or modify columns in


an existing table.

The ALTER TABLE statement is also used to add and drop various
constraints on an existing table.

7) ALTER TABLE - ADD Column


ALTER TABLE table_name
ADD column_name datatype; Example:
ALTER TABLE Customers ADD Email varchar(255);
//add column
ALTER TABLE Persons ADD DateOfBirth date;
//change data type ALTER TABLE Persons
ALTER COLUMN DateOfBirth year;

8) ALTER TABLE - DROP COLUMN


ALTER TABLE table_name DROP COLUMN column_name; Example:
ALTER TABLE Customers DROP COLUMN Email;

9) ALTER TABLE - RENAME COLUMN


EXEC sp_rename 'table_name.old_name', 'new_name', 'COLUMN';

10) ALTER TABLE - ALTER/MODIFY DATATYPE


ALTER TABLE table_name
ALTER COLUMN column_name datatype;

P a g e 27 | 33
Database system Lab
Department of Computer Science

11) CONSTRAINTS IN SQL


What is Data Integrity?
Data integrity ensures that the data which is going to be entered in the
database is reliable, accurate and consistent. Data integrity maintains the
correctness and completeness of data.

What is Constraints?
To maintain the data integrity, we use the constraints. Constraints are the rules
which we applied on the
table’s column to ensure the data integrity.

We can add constraints on column while creating the table and can also add
after creating the table. Constraints are used to specify rules for data in a table.
The following constraints are commonly used in Sql:

NOT NULL - Ensures that a column cannot have a NULL value

UNIQUE - Ensures that all values in a column are different

PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Uniquely


identifies each row in a table

FOREIGN KEY - Uniquely identifies a row/record in another table CHECK -


Ensures that all values in a column satisfies a specific condition DEFAULT -
Sets a default value for a column when no value is specified INDEX - Used to
create and retrieve data from the database very quickly

12) SQL Create Constraints


Constraints can be specified when the table is created with the CREATE
TABLE statement, or after the table is created with the ALTER TABLE
statement.

CREATE TABLE table name (


column1 datatype constraint,
***column2 datatype constraint, column3 datatype constraint,
....
);
P a g e 28 | 33
Database system Lab
Department of Computer Science

13) SQL NOT NULL on CREATE TABLE

CREATE TABLE Persons ( ID int NOT NULL,


LastName varchar(255) NOT NULL, FirstName varchar(255) NOT NULL,
Age int);

14) SQL NOT NULL on ALTER TABLE


ALTER TABLE Persons
ALTER COLUMN Age int NOT NULL;

15) SQL UNIQUE Constraint on CREATE TABLE


CREATE TABLE Persons
(ID int NOT NULL UNIQUE,
LastName varchar(255) NOT NULL, FirstName varchar(255),
Age int);

16) SQL UNIQUE Constraint on ALTER TABLE


ALTER TABLE Persons ADD UNIQUE (ID);

17) SQL PRIMARY KEY on CREATE TABLE


CREATE TABLE Persons (
ID int NOT NULL PRIMARY KEY,
LastName varchar(255) NOT NULL, FirstName varchar(255),
Age int);

18) SQL PRIMARY KEY on ALTER TABLE


ALTER TABLE Persons ADD PRIMARY KEY (ID);

P a g e 29 | 33
Database system Lab
Department of Computer Science

CONCLUSION:
______________________________________________________________
______________________________________________________________
______________________________________________________________
______________________________________________________________

RUBRICS:

Performance Lab Report

Description Total Marks Description Total Marks


Marks Obtained Marks Obtained
Ability to 5 5
Conduct Structure
practical
5 5
Data Analysis &
Efficiency
Interpretation
Total Marks obtained Total Marks Obtained

Instructor Signature

P a g e 30 | 33
Database system Lab
Department of Computer Science

PRACTICAL NO.03
Basic queries of SQL (select, where, distinct, order by)

PLO CLO LL
5 1 P2
Objectives:
Understand use of basic queries in SQL Select, From, Where , Distint , Order By all related
Queries in SQL
The SQL SELECT Statement

The SELECT statement is used to select data from a database.

The data returned is stored in a result table, called

the result-set. SELECT Syntax

SELECT column1, column2, ...


FROM table_name;

Here, column1, column2, are the field names of the table you want to select data from. If
you want to select all the fields available in the table, use the following syntax:

SELECT * FROM table_name;

SELECT Column Example

The following SQL statement selects the "CustomerName" and "City" columns from the
"Customers" table:

Example

SELECT CustomerName, City

FROM Customers; SELECT *

Example

The following SQL statement selects all the columns from the "Customers" table:

Example

SELECT * FROM Customers;

The SQL WHERE Clause

The WHERE clause is used to filter records.

P a g e 31 | 33
Database system Lab
Department of Computer Science

The WHERE clause is used to extract only those records that fulfill a specified condition.
SELECT column1, column2, ...
FROM table_name
WHERE condition;

WHERE Clause Example

The following SQL statement selects all the customers from the country "Mexico", in the
"Customers" table:

Example

SELECT * FROM
Customers WHERE
Country='Mexico';

Example
SQL requires single quotes around text values (most database systems will also allow

double quotes). However, numeric fields should not be enclosed in quotes:

Example
SELECT *
FROM Customers
WHERE CustomerID=1;

The SQL SELECT DISTINCT Statement

The SELECT DISTINCT statement is used to return only distinct (different) values.

Inside a table, a column often contains many duplicate values; and sometimes you
only want to list the different (distinct) values.

The SELECT DISTINCT statement is used to return only distinct

(different) values. SELECT DISTINCT Syntax

SELECT DISTINCT column1, column2, ...


FROM table_name;

The SQL ORDER BY Keyword

The ORDER BY keyword is used to sort the result-set in ascending or descending order.

The ORDER BY keyword sorts the records in ascending order by default. To sort the

P a g e 32 | 33
Database system Lab
Department of Computer Science
records in descending order, use the DESC keyword.
ORDER BY Syntax
SELECT column1, column2, ... FROM table_name
ORDER BY column1, column2, ... ASC|DESC;

ORDER BY Example

The following SQL statement selects all customers from the "Customers" table, sorted by
the "Country" column:
Example

SELECT * FROM Customers ORDER BY Country;

Lab Task

Task 01: Perform various queries on the inserted and saved data.
Task 02: Check output and practice by changing data.
Task 03: Perform various queries on the inserted and saved data.

CONCLUSION:
______________________________________________________________
______________________________________________________________
______________________________________________________________
______________________________________________________________

RUBRICS:

Performance Lab Report

Description Total Marks Description Total Marks


Marks Obtained Marks Obtained
Ability to 5 5
Conduct Structure
practical
5 5
Data Analysis &
Efficiency
Interpretation
Total Marks obtained Total Marks Obtained

Instructor Signature

P a g e 33 | 33

You might also like