100% found this document useful (1 vote)
803 views58 pages

Lab Manual Dbms

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 58

LABORATORY MANUAL

Database Management Systems Lab


(KCS-551)

B.TECH
(III YEAR – ODD SEM)
(2022-23)

DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

IMS ENGINEERING COLLEGE


(Affiliated to Dr A P J Abdul Kalam Technical University, Lucknow)
Approved by AICTE - Accredited by NAAC – ‘A’ Grade
NH#24, Adhyatmik Nagar, Ghaziabad, UP, India
www.imsec.ac.in

Page | 1
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
Vision
To provide globally competent professionals in the field of Computer Science & Engineering
embedded with sound technical knowledge, aptitude for research and innovation with ethical
values to cater to the industrial & societal needs.

Mission

M1: To provide quality undergraduate education in both the theoretical & applied
foundations of Computer Science Engineering.

M2: Conduct research to advance the state of the art in Computer Science & Engineering
and integrate the research results as innovations.

M3: To inculcate team building skills and promote life-long learning with a high societal
and ethical values.

Page | 2
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

PROGRAMME EDUCATIONAL OBJECTIVES (PEOs)

PEO1: Possess knowledge to enable continued professional development.

PEO2: Engage in life-long learning to foster personal & organization growth.

PEO3: Work productively as successful professionals in diverse career paths.

PEO4: Effectively communicate ideas to promote collaboration in accordance with societal


standards & ethical practices.

PROGRAMME SPECIFIC OUTCOME (PSOs)

PSO1: To apply standard software engineering practices & strategies in real-time software
project development.

PSO2: To apply latest programming languages in creating innovative career opportunities.

Page | 3
Program Outcomes
Engineering Graduates will be able to:

1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering


fundamentals, and an engineering specialization to the solution of complex engineering
problems.
2. Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
3. Design/development of solutions: Design solutions for complex engineering problems and
design system components or processes that meet the specified needs with appropriate
consideration for the public health and safety, and the cultural, societal, and environmental
considerations.
4. Conduct investigations of complex problems: Use research-based knowledge and research
methods including design of experiments, analysis and interpretation of data, and synthesis of
the information to provide valid conclusions.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modelling to complex engineering activities
with an understanding of the limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant
to the professional engineering practice.
7. Environment and sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and need
for sustainable development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or leader in
diverse teams, and in multidisciplinary settings.
10. Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend and write
effective reports and design documentation, make effective presentations, and give and
receive clear instructions.
11. Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member and
leader in a team, to manage projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.

Page | 4
GENERAL LABORATORY INSTRUCTIONS
1. Students are advised to come to the laboratory at least 5 minutes before (to
the starting time), those who come after 5 minutes will not be allowed into
the lab.
2. Plan your task properly much before to the commencement, come prepared
to the lab with the synopsis / program / experiment details.
3. Student should enter into the laboratory with:
• Laboratory observation notes with all the details (Problem statement,
Aim, Algorithm, Procedure, Program, Expected Output, etc.,) filled in
for the lab session.
• Laboratory Record updated up to the last session experiments and
other utensils (if any) needed in the lab.
• Proper Dress code and Identity card.

4. Sign in the laboratory login register, write the TIME-IN, and occupy the
computer system allotted to you by the faculty.
5. Execute your task in the laboratory, and record the results / output in the lab
observation note book, and get certified by the concerned faculty.
6. All the students should be polite and cooperative with the laboratory staff,
must maintain the discipline and decency in the laboratory.
7. Computer labs are established with sophisticated and high end branded
systems, which should be utilized properly.
8. Students / Faculty must keep their mobile phones in SWITCHED OFF mode
during the lab sessions.Misuse of the equipment, misbehaviors with the staff
and systems etc., will attract severe punishment.
9. Students must take the permission of the faculty in case of any urgency to go
out; if anybody found loitering outside the lab / class without permission
during working hours will be treated seriously and punished appropriately.
10. Students should LOG OFF/ SHUT DOWN the computer system before he/she
leaves the lab after completing the task (experiment) in all aspects. He/she
must ensure the system / seat is kept properly.

Page | 5
Sub Code KCS-551 NBA Code : C308
Sub Name Database Management Systems Lab

Bloom’s
COURSE OUTCOMES
Level
Understand and apply oracle 11 g products for creating tables, views, indexes, K2, K4
C308.1
sequences and other database objects.
Design and implement a database schema for company data base, banking data K3, K5,
C308.2 K6
base, library information system, payroll processing system, student information
system.
Write and execute simple and complex queries using DDL, DML, DCL and TCL. K4, K5
C308.3

Write and execute PL/SQL blocks, procedure functions, packages and triggers, K4, K5
C308.4
cursors.
Enforce entity integrity, referential integrity, key constraints, and domain K3, K4
C308.5
constraints on database.

CO-PO Matrix

Course
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
Outcome

C308.1 3 2 2 3 3 2 3 3 3

C308.2 3 2 3 3 2 3 2 3 3

C308.3 3 2 3 2 3 3 3 3 2

C308.4 3 2 3 2 2 2 2 2 3

C308.5 3 2 3 3 3 2 2 3

Avg 3.00 2.00 2.80 2.50 2.60 2.60 2.40 2.60 2.80

CO-PSO Matrix
COs PSO1 PSO2 PSO3 PSO4

C308.1 2 1 2 1

C308.2 2 1 1 1

C308.3 2 1 1 1
C308.4 2 1 1 1

C308.5 2 1 1 1

Avg 2.00 1.00 1.20 1.00

Page | 6
Study and Evaluation Scheme

Course Course
Teaching Scheme Credits Assigned
Code Name
Database Theory Practical Tutorial Theory Practical Tutorial Total
KCS-551 Management
(P)
-- 02 -- -- 01 -- 01
systems Lab (50
Marks)

Page | 7
LIST OF PROGRAMS

Subject: Database Management System Lab Code: KCS-551

S.NO. NAME OF EXPERIMENT MAPPING


WITH CO
1 Installing oracle/ MYSQL CO1
2 Creating Entity-Relationship Diagram using case tools. CO1
3 Writing SQL statements Using ORACLE /MYSQL: a) Writing basic SQL CO2
SELECT statements. b) Restricting and sorting data. c) Displaying data
from multiple tables. d) Aggregating data using group function.
e)Manipulating data. f) Creating and managing tables.
4 Normalization CO4
5 Creating cursor CO1

6 Creating procedure and functions CO2

7 Creating packages and triggers CO1


8 Design and implementation of payroll processing system CO3
9 Design and implementation of Library Information System CO3
10 Design and implementation of Student Information System CO3
11 Automatic Backup of Files and Recovery of Files CO3
12 Mini project (Design & Development of Data and Application ) for CO3
following :
a) Inventory Control System. b) Material Requirement Processing. c)
Hospital Management System. d) Railway Reservation System. e) Personal
Information System. f) Web Based User Identification System. g) Timetable
Management System. h) Hotel Management System

Page | 8
PRACTICAL -1

TITLE: ORACLE Installation

1.1 Objective 1.2 Installation

1.1 OBJECTIVE: learn the procedure of ORACLE installation

1.2 ORACLE INSTALLATION:

Installing Oracle Database 11g on Windows

To install the Oracle software, you must use the Oracle Universal installer.

1. For this installation, you need either the DVDs or a downloaded version of the DVDs. In this tutorial, you
install from the downloaded version. From the directory where the DVD files were unzipped, open
Windows Explorer and double-click on setup.exe from the \db\Disk1 directory.
2. The product you want to install is Oracle Database 11g. Make sure the product is selected and
click Next.

3. You will perform a basic installation with a starter database. Enter orcl for the Global Database Name
and oracle for Database Password and Confirm Password. Then, click Next

4. Oracle Configuration Manager allows you to associate your configuration information with your Metalink
account. You can choose to enable it on this window. Then, click Next.

Page | 9
5. Review the Summary window to verify what is to be installed. Then, click Install.

6. The progress window appears.

7. The Configuration Assistants window appears.

8. Your database is now being created.

Page | 10
9. When the database has been created, you can unlock the users you want to use. Click OK.

10. Click Exit. Click Yes to confirm exit.

Testing Your Installation

To test that your installation completed successfully, perform the following steps:

1. Open a browser and enter the following URL:

https://<hostname>:1158/em

Page | 11
where <hostname> should be changed to your machine name, IP address, or localhost.

Because Enterprise Manager Database Control is a secure site, you need a certificate. Select the Accept
this certificate permanently option, and then click OK.

2. Enter system as the User Name and oracle as the Password, and then click Login

3. The Database Control Home Page appears. Your installation was successful.

Another way to work on ORACLE:


1. Goto https://www.oracle.com/downloads/index.html
2. Create your login and download latest Express Edition of ORACE and install in simple way
3. Run the ORACLE, It will open in Web Browser
4. Click on Application Express

Page | 12
5. Login again and then create a new database user by filling the below entries and click on creating
workspace

6. Login by using your created username and password and start using ORACLE

Page | 13
PRACTICAL -2

TITLE: ER Diagram using Dia Tool

2.1 Objective 2.2 Theory (Installation & Dia Guide) 2.3 Assignment 2.4 Solution to Assignment

2.1 OBJECTIVE: applying tool to create ER model

2.2 THEORY AND CONCEPTS:


Introduction to Dia Diagram Editor:

a. Installation Guide

1. Download the installation file for your platform from http://dia-installer.de/.


2. Open the downloaded file, select preferred installation language, and press “OK”.

3. The Dia “Setup Wizard” window will appear. Click “Next”.

Page | 14
4. In the “License Agreement” window click “Next” to continue installation.

5. Choose the components you want to install and click “Next”.

Page | 15
6. Choose the installation location on your computer and click “Install”.

7. After the installation process is completed, click “Finish”.

Page | 16
b. Dia User Guide

Create an ER Diagram

In this section, basic guidelines are given on how to create ER database diagrams. An ER diagram consists of
entity sets, attributes, and the relationship sets between entity sets. Let us create an ER diagram for a
database called “Courses and Students”. The database will have two main entity sets, i.e., “Course” and
“Student”. The relation between them defines which students belong to which course.

1. Start Dia Diagram Editor.

2. On the left side of the menu click on the dropdown menu, select “Other sheets” and click on “ER”.

Page | 17
3. Now the menu consists only of shapes that are relevant to an ER diagram.

4. Let us create an entity called “Course”. Choose the “E” icon with a single frame in the shapes menu and
click on the drawing space at the center. A rectangle with the name “Entity” will appear.

Page | 18
5. Double-click on the new entity set and the properties window will show up (or right-click and choose
“Properties”). Change the name of the entity set to “Course” and click “OK”. The entity sets name will be
changed.

6. The “Course” entity set has several attributes: “courseId” (primary key), “title”, “ECTS”, “level”,
“language”. In the shape menu select the “A” icon with an oval around it and click near the created
“Course” entity set. An oval with the name “Attribute” will appear.

Page | 19
7. Double-click on the attribute and in the properties window change the name to “courseId”. Since this
attribute is also a primary key, select “Key” value “Yes”. Click “OK”.

8. In the shape menu click on the “Participation” icon and connect the entity set with the attribute.

Page | 20
9. It is also possible to connect an entity set with an attribute using different connectors. Choose the
appropriate style at the end of a new connector by clicking on “arrow style at the end of the line new
lines”. Select “line (L)” connector.

10. Proceed with the rest of the attributes of the entity set “Course”.

Page | 21
11. Attributes of the “Student” entity set are: “studentId”, “firstName”, “lastName”, “startDate”.

12. Create the relationship set between “Course” and “Student” with the name “Belongs” that also
has an attribute “signUpDate”. In the shape menu select “R” with a diamond around it and click
between the two entity sets in the drawing area.

4
13. Change the name to “Belongs” and assign attribute “signUpDate” to it.

The ER diagram for database “Courses and Students” was created successfully!

Note: save your diagram several times through all the creation process!

Export Created Diagram

1. Open the diagram you want to export.


2. Click on “File > Export“. Enter the name of the file, select the location you want the file to be
saved, determine file type (e.g. JPG), and click “Save”.

5
2.3 Assignment:
A university wants to set up a database to record details about its staff, and the departments they
belong to. They intend to record the following information.
• For each member of staff, their staff identity number, name, job title, and salary.
• For each department, its name and address.
• For each member of staff, all departments that they belong to. It is required that every member of
staff belongs to at least one department.
• For each department, the head of department. It is required that each department has exactly one
head of department.
Draw an ER diagram that expresses the requirements for the database. Make sure that you capture
all the constraints on the data mentioned above.

2.4 Solution to Assignment:


Here is one possible ER diagram:

6
PRACTICAL -3

TITLE : CREATING TABLES, INSERT INTO TABLES & SELECT FROM TABLES

3.1 Objective 3.2 Theory 3.3 Assignment 3.4. Solutions

3.1 OBJECTIVE:Create tables and specify the queries in SQL

3.2 THEORY& CONCEPTS:


Introduction about SQL-
SQL (Structured Query Language) is a nonprocedural language, you specify what you want, not how
to get it. A block structured format of English key words is used in this query language. It has the
following components.

DDL (Data Definition Language)-


The SQL DDL provides command for defining relation schemas, deleting relations and modifying
relation schema.

DML (DATA Manipulation Language)-


It includes commands to insert tuples into, delete tuples from and modify tuples in the database.

View definition-
The SQL DDL includes commands for defining views.
Transaction Control- SQL includes for specifying the beginning and ending of transactions.

Embedded SQL and Dynamic SQL-


Embedded and Dynamic SQL define how SQL statements can be embedded with in general purpose
programming languages, such as C, C++, JAVA, COBOL, Pascal and Fortran.

Integrity-
The SQL DDL includes commands for specifying integrity constraints that the data stored in the
database must specify. Updates that violate integrity constraints are allowed.

Authorization-
The SQL DDL includes commands for specifying access rights to relations and views.

Data Definition Language-

The SQL DDL allows specification of not only a set of relations but also information about each
relation, including-
• Schema for each relation
• The domain of values associated with each attribute.
• The integrity constraints.
• The set of indices to be maintained for each relation.
• The security and authorization information for each relation.
• The physical storage structure of each relation on disk.

7
Domain types in SQL-

The SQL standard supports a variety of built in domain types, including-


• Char (n)- A fixed length character length string with user specified length .
• Varchar (n)- A variable character length string with user specified maximum length n.
• Int- An integer.
• Small integer- A small integer.
• Numeric (p, d)-A Fixed point number with user defined precision.
• Real, double precision- Floating point and double precision floating point numbers with
machine dependent precision.
• Float (n)- A floating point number, with precision of at least n digits.
• Date- A calendar date containing a (four digit) year, month and day of the month.
• Time- The time of day, in hours, minutes and seconds Eg. Time ’09:30:00’.
• Number- Number is used to store numbers (fixed or floating point).

DDL statement for creating a table-

Syntax-
Create table tablename
(columnname datatype(size), columnname datatype(size));

Creating a table from a table-

Syntax-
CREATE TABLE TABLENAME
[(columnname, columnname, ………)]
AS SELECT columnname, columnname……..FROM tablename;

Insertion of data into tables-

Syntax-
INSERT INTO tablename
[(columnname, columnname, ………)]
Values(expression, expression);

Inserting data into a table from another table:

Syntax-
INSERT INTO tablename
SELECT columnname, columnname, …….
FROM tablename;

Insertion of selected data into a table from another table:

Syntax-
INSERT INTO tablename
SELECT columnname, columnname……..
FROM tablename
WHERE columnname= expression;

8
Retrieving of data from the tables-

Syntax-
SELECT * FROM tablename;

The retrieving of specific columns from a table-

Syntax-
SELECT columnname, columnname, ….
FROM tablename;

Elimination of duplicates from the select statement-

Syntax-
SELECT DISTINCT columnname, columnname
FROM tablename;

Selecting a data set from table data-

Syntax-
SELECT columnname, columnname
FROM tablename
WHERE searchcondition;

3.3 ASSIGNMENT

Q1. Create the following tables:


i) client_master

columnname datatype size


client_no varchar2 6
name varchar2 20
address1 varchar2 30
address2 varchar2 30
city varchar2 15
state varchar2 15
pincode number 6
bal_due number 10,2

ii) Product_master
Columnname datatype size
Product_no varchar2 6
Description varchar2 20
Profit_percent number 10,2
Unit_measure varchar2 10
Qty_on_hand number 10
Reoder_lvl number 10
Sell_price number 10
Cost_price number 10

9
Q2- Insert the following data into their respective tables:

Clientno Name city pincode state bal.due

0001 Ivan Bombay 400054 Maharashtra 15000


0002 Vandana Madras 780001 Tamilnadu 0
0003 Pramada Bombay 400057 Maharashtra 5000
0004 Basu Bombay 400056 Maharashtra 0
0005 Ravi Delhi 100001 Delhi 2000
0006 Rukmini Bombay 400050 Maharashtra 0

Data for Product Master:

Product No. Desciption Profit % Unit Qty Reorder Sell Cost


Percent measured on hand lvl price
price

P00001 1.44floppies 5 piece 100 20 525 500


P03453 Monitors 6 piece 10 3 12000 11200
P06734 Mouse 5 piece 20 5 1050 500
P07865 1.22 floppies 5 piece 100 20 525 500
P07868 Keyboards 2 piece 10 3 3150 3050
P07885 CD Drive 2.5 piece 10 3 5250 5100
P07965 540 HDD 4 piece 10 3 8400 8000
P07975 1.44 Drive 5 piece 10 3 1050 1000
P08865 1.22 Drive 5 piece 2 3 1050 1000

Q3:- On the basis of above two tables answer the following queries:
i) Find out the names of all the clients.
ii) Retrieve the list of names and cities of all the clients.
iii) List the various products available from the product_master table.
iv) List all the clients who are located in Bombay.
v) Display the information for client no 0001 and 0002.
vi) Find the products with description as ‘1.44 drive’ and ‘1.22 Drive’.
vii) Find all the products whose sell price is greater then 5000.
viii) Find the list of all clients who stay in in city ‘Bombay’ or city ‘Delhi’ or ‘Madras’.
ix) Find the product whose selling price is greater than 2000 and less than or equal to 5000.
x) List the name, city and state of clients not in the state of ‘Maharashtra’.

10
3.4. SOLUTION TO ASSIGNMENT

Q.1. Create the following tables:


(i) create table client_master
( client_no varchar2(6),
name varchar2(20),
address1 varchar2(30),
address2 varchar2(30),
city varchar2(15),
state varchar2(15),
pincode number(6),
bal_due number(10,2));

(ii) create table product_master


( product_no varchar2(6),
Description varchar2(20),
Profit_percent number(10,2),
Unit_measure varchar2(10),
Qty_on_hand number(10),
Reorder_level_number number(10),
Sell_price number(10),
Cost_price_number number(10));

Q.2. Insert the following data into their respective tables:


(i) Insert into client_master
Values(‘0001’,’ivan’,’bombay’,’maharastra’,’201001’,’15000’);

(ii) Insert into product_master


Values(‘P00001’,’1.44floppies’,’5’,’piece’,’100’,’20’,’525’,’500’);

Q.3. Solutions
i. select name from client_master;
ii. select name, city from client_master;
iii. select description from product_master;
iv. select * from client_master where city = ‘bombay’;
v. select * from client_master where client_no = ‘0001’ orclient_no = ‘ ‘0002’;
vi. select * from product_master where description=’1.44 drive’ or ‘1.22 drive’;
vii. select * from product_master where sell_price > 5000;
viii. select * from client_master where city = ‘bombay’ or city = ‘madras’;
ix. select * from product_master where sell_price > 2000 and sell_price <= 5000;
x. select name, city , state from client_master where state not in (‘maharastra’);

11
TITLE :DATA MANIPULATION LANGUAGE

3.1 Objective 3.2 Theory 3.3 Assignment 3.4. Solution to Assignment

3.1 OBJECTIVE:Perform manipulation operations on created tables.

3.2 THEORY AND CONCEPTS:DML ( Data Manipulation Language) Data manipulation is

• The retrieval of information stored in the database.


• The insertion of new information into the database.
• The deletion of information from the database.
• The modification of information stored by the appropriate data model. There are basically
two types.
(i) Procedural DML:- require a user to specify what data are needed and how to get those
data.
(ii) Non Procedural DML : require a user to specify what data are needed without specifying
how to get those data.

Updating the content of a table:


In creation situation we may wish to change a value in table without changing all values in the tuple .
For this purpose the update statement can be used.

Update table name


Set columnname = experision, columnname =expression……
Where columnname = expression;

Deletion Operation:-
A delete request is expressed in much the same way as query. We can delete whole tuple ( rows) we
can delete values on only particulars attributes.

Deletion of all rows

Syntax:
Delete from tablename :

Deletion of specified number of rows


Syntax:

Delete from table name


Where search condition ;

Computation in expression lists used to select data

+ Addition - Subtraction
* multiplication ** exponentiation
/ Division () Enclosed operation

Renaming columns used with Expression Lists: - The default output column names can be renamed
by the user if required

12
Syntax:

Select column name result_columnname,


Columnname result_columnname,
From table name;

Logical Operators:
The logical operators that can be used in SQL sentenced are

AND all of must be included


OR any of may be included
NOT none of could be included

Range Searching: Between operation is used for range searching.

Pattern Searching:
Themost commonly used operation on string is pattern matching using the operation ‘like’ we
describe patterns by using two special characters.

• Percent (%) ; the % character matches any substring we consider the following examples.
• ‘Perry %’ matches any string beginning with perry
• ‘% idge % matches any string containing’ idge as substring.
• ‘ - - - ‘ matches any string exactly three characters.
• ‘ - - - % matches any string of at least of three characters.

Oracle functions:
Functions are used to manipulate data items and return result. function follow the format of
function _name (argument1, argument2 ..) .An arrangement is user defined variable or constant.
The structure of function is such that it accepts zero or more arguments.
Examples:
Avg return average value of n

Syntax:
Avg ([distinct/all]n)
Min return minimum value of expr.

Syntax:
MIN((distict/all )expr)
Count Returns the no of rows where expr is not null

Syntax:

Count ([distinct/all)expr]
Count (*) Returns the no rows in the table, including duplicates and those with nulls.
Max Return max value of expr

Syntax:

13
Max ([distinct/all]expr)
Sum Returns sum of values of n

Syntax:
Sum ([distinct/all]n)

Sorting of data in table


Syntax:
Select columnname, columnname
From table
Order by columnname;

3.3 ASSIGNMENT

Que.1 Using the table client master and product master answer the following queries.

i. Change the selling price of ‘1.44 floppy drive to Rs.1150.00


ii. Delete the record with client 0001 from the client master table.
iii. Change the city of client_no’0005’ to Bombay.
iv. Change the bal_due of client_no ‘0001, to 1000.
v. Find the products whose selling price is more than 1500 and also find the new selling price
as original selling price *15.
vi. Find out the clients who stay in a city whose second letter is a.
vii. Find out the name of all clients having ‘a’ as the second letter in their names.
viii. List the products in sorted order of their description.
ix. Count the total number of orders
x. Calculate the average price of all the products.
xi. Calculate the minimum price of products.
xii. Determine the maximum and minimum prices . Rename the tittle as ‘max_price’ and
min_price respectively.
xiii. Count the number of products having price greater than or equal to 1500.

3.4 SOLUTION TO ASSIGNMENT:

i. update table client_master set sell_price = ‘1150’ where description=’1.44 drive’;


ii. Delete from client_master where client_no = ‘0001’;
iii. update table client_master set city=’bombay’ where client_no=’0001’;
iv. update table client_master set bal_due=1000 where client_no=’0001’;
v. select description from product_master where sell_price > 1500;
vi. select sell_price*15 “New Selling Price” from product_master;
vii. select * from client_master where city like ‘_a%’;
viii. select name from client_master where name=’_a%’;
ix. select * from product_master order by description;
x. select count(*) from product_master;
xi. select avg(sell_price) from product_master;
xii. select min(sell_price) from product_master;
xiii. select max(sell_price) “Max_price” , min(sell_price) “Min_price”;
xiv. select count(*) from product_master where sell_price >= 1500;

14
TITLE:TO IMPLEMENT CONSTRAINTS ON TABLES.

4.1 Objective 4.2 Theory 4.3 Assignment 4.4. Solution to Assignment

4.1 OBJECTIVE:applying constraints on the columns

4.2 THEORY AND CONCEPTS:


Data constraints: Besides the cell name, cell length and cell data type there are other parameters
i.e. other data constrains that can be passed to the DBA at check creation time. The constraints can
either be placed at column level or at the table level.

i. Column Level Constraints: If the constraints are defined along with the column definition, it
is called a column level constraint.
ii. Table Level Constraints: If the data constraint attached to a specify cell in a table reference
the contents of another cell in the table then the user will have to use table level
constraints.

Null Value Concepts:- while creating tables if a row locks a data value for particular column that
value is said to be null . Column of any data types may contain null values unless the column was
defined as not null when the table was created

Syntax:

Create table tablename


(columnname data type (size) not null ……)

Primary Key: primary key is one or more columns is a table used to uniquickly identity each row in
the table. Primary key values must not be null and must be unique across the column. A multicolumn
primary key is called composite primary key.

Syntax: primary key as a column constraint


Create table tablename
(columnname datatype (size) primary key,….)

Primary key as a table constraint


Create table tablename
(columnname datatype (size), columnname datatype( size)…
Primary key (columnname,columnname));

Unique key concept:-A unique is similar to a primary key except that the purpose of a unique key is
to ensure that information in the column for each record is unique as with telephone or devices
license numbers. A table may have many unique keys.

Syntax: Unique as a column constraint.


Create table table name
(columnname datatype (size) unique);

Unique as table constraint:


Create table tablename
(columnname datatype (size),columnname datatype (size)…unique (columnname,columnname));

15
Default value concept: At the line of cell creation a default value can be assigned to it. When the
user is loading a record with values and leaves this cell empty, the DBA wil automatically load this
cell with the default value specified. The data type of the default value should match the data type
of the column

Syntax:

Create table tablename


(columnname datatype (size) default value,….);

Foreign Key Concept : Foreign key represents relationship between tables. A foreign key is column
whose values are derived from the primary key of the same of some other table . the existence of
foreign key implies that the table with foreign key is related to the primary key table from which the
foreign key is derived .A foreign key must have corresponding primary key value in the primary key
table to have meaning.
Foreign key as a column constraint

Syntax :
Create table table name
(columnname datatype (size) references another table name);

Foreign key as a table constraint:

Syntax :
Create table name
(columnname datatype (size)….
primary key (columnname);
foreign key (columnname)references table name);

Check Integrity Constraints: Use the check constraints when you need to enforce intergrity rules
that can be evaluated based on a logical expression following are a few examples of appropriate
check constraints.
• A check constraints name column of the coient_master so that the name is entered
in upper case.
• A check constraint on the client_no column of the client _master so that no
client_no value starts with ‘c’

Syntax:
Create table tablename
(columnname datatype (size) CONSTRAINT constraintname)
Check (expression));

4.3 ASSIGNMENTS:
Que.1 Create the following tables:
i. Sales_master
Columnname Datatype Size Attributes
Salesman_no varchar2 6 Primary key/first letter
must start with ‘S’
Sal_name varchar2 20 Not null
Address varchar2 Not null

16
City varchar2 20
State varchar2 20
Pincode Number 6
Sal_amt Number 8,2 Not null, cannot be 0
Tgt_to_get Number 6,2 Not null, cannot be 0
Ytd_sales Number 6,2 Not null, cannot be 0
Remarks Varchar2 30

ii. Sales_order
Columnname Datatype Size Attributes
S_order_no varchar2 6 Primary/first letter must be 0
S_order_date Date 6 Primary key reference clientno of
client_master table
Client_no Varchar2 25
Dely_add Varchar2 6
Salesman_no Varchar2 6 Foreign key references
salesman_no of salesman_master
table
Dely_type Char 1 Delivery part(p)/full(f),default f
Billed_yn Char 1
Dely_date Date Can not be lessthan s_order_date
Order_status Varchar2 10 Values (‘in process’;’fulfilled’;back
order’;’canceled

I. Sales_order_details
Column Datatype Size Attributes

S_order_no Varchar2 6 Primary key/foreign


key references
s_order_no of
sales_order
Product_no Varchar2 6 Primary key/foreign
key references
product_no of
product_master
Qty_order Number 8
Qty_disp Number 8
Product_rate Number 10,2

Insert the following data into their respective tables using insert statement:
Data for sales_man master table

Salesman_n Salesma Address City Pin code State Salamt Tgt_to_ Ytd Remark
o n name get Sales
S00001 Kiran A/14 Bom 400002 Mah 3000 100 50 Good
worli bay

17
S00002 Manish 65,narim Bom 400001 Mah 3000 200 100 Good
an bay
S00003 Ravi P-7 Bom 400032 Mah 3000 200 100 Good
Bandra bay
S00004 Ashish A/5 Juhu Bom 400044 Mah 3500 200 150 Good
bay

(ii)
Data for salesorder table:
S_orderno S_orderdate Client no Dely Bill Salesman no Delay Orderstatus
type yn date
019001 12-jan-96 0001 F N 50001 20-jan- Ip
96
019002 25-jan-96 0002 P N 50002 27-jan- C
96
016865 18-feb-96 0003 F Y 500003 20-feb- F
96
019003 03-apr-96 0001 F Y 500001 07-apr- F
96
046866 20-may-96 0004 P N 500002 22-may- C
96
010008 24-may-96 0005 F N 500004 26-may- Ip
96

(iii)
Data for sales_order_details table:

S_order no Product no Qty ordered Qty disp Product_rate


019001 P00001 4 4 525
019001 P07965 2 1 8400
019001 P07885 2 1 5250
019002 P00001 10 0 525
046865 P07868 3 3 3150
046865 P07885 10 10 5250
019003 P00001 4 4 1050
019003 P03453 2 2 1050
046866 P06734 1 1 12000
046866 P07965 1 0 8400
010008 P07975 1 0 1050
010008 P00001 10 5 525

4.4 SOLUTION TO ASSIGNMENT:

Q.1. create the following tables:

18
(i) Create table sales_master
(salesman_no varchar2(6) primary key check salesman_no in ‘S%’,
sal_name varchar2(20) not null,
address varchar2(20) not null,
city varchar2(20),
state varchar2(20),
pincode number(8),
sal_amt number(8,2) not null check(sal_amt >0),
tgt_to get number(6,2) not null check(sal_amt >0),
ytd_sales number(6,2) not null check(sal_amt >0),
remarks varchar2(30));

(ii) create table sales_order


s_order_no varchar2(6) primary key check s_order_no in ‘0%’,
s_order_date date,
client_no varchar2(25),
dely_add varchar2(6),
salesman_no varchar2(6) foreign key references salesman_no(sales_master),
dely_type char(1) check delt_type in ‘p’ or ‘f’ default ‘f’,
billed_yn char(1),
dely_date date check not in(dely_date<order_date),
order_status varchar2(10) check order_status in (‘in_process’ or ‘fulfilled’ or ‘back_order’ or
‘canceled’));

Q.2. Insert the following data into their respective tables using insert statement:
(i) Insert into sales_master
Values(‘S0001’,’kiran’,’a/14 worli’,’bombay ’,’400002 ’,’mah ’,’3000 ’,’100 ’,’50 ’,’good’);

(ii) Insert into sales_order


Values(‘019001’,’12-jan-96’,’0001 ’,’F ’,’N ’,’50001 ’,’20-jan-96’,’IP’);

19
TITLE : MODIFYING THE STRUCTURES OF THE TABLE.

5.1 Objective 5.2 Theory 5.3 Assignment 5.4. Solution to Assignment

5.1 OBJECTIVE:Use of Alter table statements

5.2 THEORY AND CONCEPTS: Modifying the Structure of Tables- Alter table command is used to
changing the structure of a table. Using the alter table clause you cannot perform the following
tasks:

(i) change the name of table


(ii) change the name of column
(iii) drop a column
(iv) decrease the size of a table if table data exists.

The following tasks you can perform through alter table command.

(i) Adding new columns:


Syntax
ALTER TABLE tablename
ADD (newcolumnname newdatatype (size));

(ii) Modifying existing table


Syntax:
ALTER TABLE tablename
MODIFY (newcolumnname newdatatype (size));

NOTE: Oracle not allow constraints defined using the alter table, if the data in the table, violates
such constraints.

Removing/Deleting Tables- Following command is used for removing or deleting a table.

Syntax:
DROP TABLE tabename:

Defining Integrity constraints in the ALTER TABLE command-

You can also define integrity constraints using the constraint clause in the ALTER TABLE command.
The following examples show the definitions of several integrity constraints.

(1) Add PRIMARY KEY-


Syntax:
ALTER TABLE tablename
ADD PRIMARY KEY(columnname);

(2) Add FOREIGN KEY-


Syntax:
ALTER TABLE tablename
ADD CONSTRAINT constraintname
FOREIGN KEY(columnname) REFERENCES tablename;
Droping integrity constraints in the ALTER TABLE command:

20
You can drop an integrity constraint if the rule that if enforces is no longer true or if the constraint is
no longer needed. Drop the constraint using the ALTER TABLE command with the DROP clause. The
following examples illustrate the droping of integrity constraints.

(1) DROP the PRIMARY KEY-


Syntax:
ALTER TABLE tablename
DROP PRIMARY KEY

(2) DROP FOREIGN KEY-


Syntax:
ALTER TABLE tablename
DROP CONSTRAINT constraintname;

5.3 ASSIGNMENT:

Que 1. Create the following tables:


Challan_Header
Column name data type size Attributes
Challan_no varchar2 6 Primary key
s_order_no varchar2 6 Foreign key references s_order_no of
sales_order table
challan_date date not null
billed_yn char 1 values (‘Y’,’N’). Default ‘N’

Table Name : Challan_Details


Column name data type size Attributes
Challan_no varchar2 6 Primary key/Foreign key references
Product_no of product_master
Qty_disp number 4,2 not null

Q2. Insert the following values into the challan header and challan_details tables:

(i) Challan No S_order No Challan Date Billed


CH9001 019001 12-DEC-95 Y
CH865 046865 12-NOV-95 Y
CH3965 010008 12-OCT-95 Y

Data for challan_details table

Challan No Product No Qty_Disp


CH9001 P00001 4
CH9001 P07965 1
CH9001 P07885 1
CH6865 P07868 3
CH6865 P03453 4
CH6865 P00001 10

21
CH3965 P00001 5
CH3965 P07975 2

Answer the following queries

Q1. Make the primary key to client_no in client_master.


Q2. Add a new column phone_no in the client_master table.
Q3. Add the not null constraint in the product_master table with the columns description, profit
percent , sell price and cost price.
Q4. Change the size of client_no field in the client_master table.
Q5. Select product_no, description where profit percent is between 20 and 30 both inclusive.

5.4 SOLUTION TO ASSIGNMENT:

Q.1. Create the following tables:


Create table challan_header (
Chalan_no varchar2(6) primary key,
S_order_no varchar2(6) foreign key references s_order_no(sales_order),
Challan_date date not null,
Billed_yn char(i) check billed_yn in (‘Y’ or ‘N’) default ‘N’);

create table challan_details(


challan_no varchar2(6) primary key foreign key references product_no(product_master),
qty_disp number(4,2) not null);

Q.2. Insert the following values into the challan header and challan_details tables:
Insert into challan_header
Values(‘ch9001’,’019001’,’12-dec-95’,’Y’);

Insert into challan_details


Values(‘ch9001’,’p00001’,’4’);

22
PRACTICAL - 4

23
PRACTICAL - 5

24
PRACTICAL – 6

TITLE: CURSOR

6.1 Objective 6.2 Theory 6.3 Example for practice

6.1 OBJECTIVE: Use of cursor

6.2 THEORY AND CONCEPTS:


The central purpose of the Oracle PL/SQL language is to make it as easy and efficient as possible to
query and change the contents of tables in a database. You must, of course, use the SQL language to
access tables, and each time you do so, you use a cursor to get the job done. A cursor is a pointer to a
private SQL area that stores information about the processing of a SELECT or data manipulation
language (DML) statement (INSERT, UPDATE, DELETE, or MERGE). Cursor management of
DML statements is handled by Oracle Database, but PL/SQL offers several ways to define and
manipulate cursors to execute SELECT statements.

SELECT-INTO offers the fastest and simplest way to fetch a single row from a SELECT
statement. The syntax of this statement is
SELECT select_list INTO variable_list FROM remainder_of_query;
EXAMPLE:
Get the last name for a specific employee ID (the primary key in the employees table):
DECLARE
l_last_name employees.last_name%TYPE;
BEGIN
SELECT last_name
INTO l_last_name
FROM employees
WHERE employee_id = 138;

DBMS_OUTPUT.put_line (
l_last_name);
END;
Fetch an entire row from the employees table for a specific employee ID:
DECLARE
l_employee employees%ROWTYPE;
BEGIN
SELECT *
INTO l_employee
FROM employees
WHERE employee_id = 138;

DBMS_OUTPUT.put_line (
l_employee.last_name);
END;

Using the Cursor FOR Loop


The cursor FOR loop is an elegant and natural extension of the numeric FOR loop in PL/SQL. With a
numeric FOR loop, the body of the loop executes once for every integer value between the low and

25
high values specified in the range. With a cursor FOR loop, the body of the loop is executed for each
row returned by the query.
The following block uses a cursor FOR loop to display the last names of all employees in
department 10:
BEGIN
FOR employee_rec IN (
SELECT *
FROM employees
WHERE department_id = 10)
LOOP
DBMS_OUTPUT.put_line (
employee_rec.last_name);
END LOOP;
END;

6.3 Example for practice


EXAMPLE:

BEGIN
update abcd set no=22 where name='ramDA';
if SQL%FOUND then
dbms_output.put_line('success');
else
dbms_output.put_line('failed');
end if;
end;

DECLARE
ROWS_AFFECTED CHAR(4);
BEGIN
update abcd set no=23 where name='ram';
ROWS_AFFECTED :=TO_CHAR(SQL%ROWCOUNT);
if SQL%ROWCOUNT>0 then
dbms_output.put_line(ROWS_AFFECTED ||'success');
else
dbms_output.put_line('failed');
end if;
end;

26
PRACTICAL – 7

TITLE: Procedure, Function

7.1 Objective 7.2 Theory 7.3 Exercise

7.1 OBJECTIVE: learning of procedure, functions and packages in SQL

7.2 THEORY AND CONCEPTS:

A procedure is a block that can take parameters (sometimes referred to as arguments) and be invoked.
Procedures promote reusability and maintainability. Once validated, they can be used in number of
applications. If the definition changes, only the procedure are affected, this greatly simplifies maintenance.
Modularized program development:
✓ Group logically related statements within blocks.
✓ Nest sub-blocks inside larger blocks to build powerful programs.
✓ Break down a complex problem into a set of manageable well defined logical modules
and implement the modules with blocks.

Procedure and function blocks:


Procedure:
- No return.
- PROCEDURE name IS
Function:
- Returns a value
- FUNCTION name RETURN data-type IS
Syntax for procedure:
Create [or Replace] PROCEDURE procedur_name
(parameter1 [model1] datatype1,
(parameter2 [model2] datatype2,
…)
IS|AS
PL/SQL Block;

Example:
Create [or Replace] PROCEDURE leave_emp
(v_id IN emp.empno%TYPE)
IS
BEGIN
DELETE FROM emp
WHERE empno=v_id;
END leave_emp;

Syntax for function:


Create [or Replace] function function_name
(parameter1 [model1] datatype1,
(parameter2 [model2] datatype2,
…) return type
IS|AS
PL/SQL Block;

Example:
Create [or Replace] PROCEDURE leave_emp

27
(v_id IN emp.empno%TYPE)
IS
BEGIN
DELETE FROM emp
WHERE empno=v_id;
END leave_emp;

7.3 Exercise

PROCEDURE FOR GCD NUMBERS


SQL> create or replace procedure pro
is
a number(3);
b number(3);
c number(3);
d number(3);
begin
a:=&a;
b:=&b;
if(a>b) then
c:=mod(a,b);
if(c=0) then
dbms_output.put_line('GCD is');
dbms_output.put_line(b);
else
dbms_output.put_line('GCD is');
dbms_output.put_line(c);
end if;
else d:=mod(b,a);
if(d=0) then
dbms_output.put_line('GCD is');
dbms_output.put_line(a);
else
dbms_output.put_line('GCD is');
dbms_output.put_line(d);
end if;
end if;
end;
/

Enter value for a: 8


old 8: a:=&a;
new 8: a:=8;
Enter value for b: 16
old 9: b:=&b;
new 9: b:=16;
Procedure created.

SQL> set serveroutput on;


SQL> execute pro;
GCD is 8
PL/SQL procedure successfully completed.

28
IMPLEMENTATION OF FACTORIAL USING FUNCTION
SQL>create function fnfact(n number)
return number is
b number;
begin
b:=1;
for i in 1..n
loop
b:=b*i;
end loop;
return b;
end;
/

SQL>Declare
n number:=&n;
y number;
begin
y:=fnfact(n);
dbms_output.put_line(y);
end;
/

Function created.

Enter value for n: 5


old 2: n number:=&n;
new 2: n number:=5;
120

PL/SQL procedure successfully completed.

Create a procedure which generate all the prime numbers below the given
number and count the no. of prime numbers.

Create or replace procedure prime_proc(n IN number, tot OUT number) as


i number;
c number;
j number;
Begin
i:=1;
tot:=0;
while(i<=n)
loop
j:=1;
c:=0;
while(j<=i)
loop
if(mod(I,j)=0) then
c:=c+1;
end if;

29
j:=j+1;
end loop;
if(c=2) then
dbms_output.put_line(i);
tot:=tot+1;
end if;
i:=i+1;
end loop;
end;
/
Sql>procedure created.
declare
t number;
begin
prime_proc(10,t);
dbms_output.put_line(‘the total prime no .are’||t);
end;

Valid Test Data:


sql>set serveroutput on

OUTPUT
sql>/
2
3
5
7
The total prime no. are 4

30
PRACTICAL – 8

TITLE: Payroll Processing System

8.1 Objective 8.2 Theory 8.3 Exercise

8.1 OBJECTIVE: Design and implementation of payroll processing system

8.2 THEORY AND CONCEPTS:

Payroll Processing refers to the complete set of steps involved in calculating the total remuneration
of each employee. The process typically involves three to four stages and tasks such as defining
salary structures, gathering employee data, components, deductions, allowances, and setting up the
necessary policies with respect to taxes and other adjustments, and then calculating the total salary
after adjusting all the company policies. After the salaries are disbursed, filing, reporting and providing
payslips to employees also comes under the entire payroll processing cycle.
In simplest words, if payroll is the amount paid by the employer to employee, payroll processing is the
whole methodology to accurately calculate the net pay of the employees as per statutory compliances
and company policies.

-- Database
-- Table structure for table loginn
CREATE TABLE loginn (
idd int(10) NOT NULL PRIMARY KEY AUTO_INCREMENT,
e_mail tinytext NOT NULL,
pass longtext NOT NULL
);
-- Dumping data for table loginn
INSERT INTO loginn (idd, e_mail, pass) VALUES
(1, 'dev', 'dev');
-- Table structure for table empp
CREATE TABLE empp (
idd int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
first_name varchar(100) NOT NULL,
last_name varchar(100) NOT NULL,
e_mail varchar(100) NOT NULL UNIQUE KEY,
pass text NOT NULL,
d_o_b date NOT NULL,
gndr varchar(10) NOT NULL,
contct varchar(20) NOT NULL,
nid int(20) NOT NULL,
addr varchar(100) DEFAULT NULL,
deprtmnt varchar(100) NOT NULL,
deg varchar(100) NOT NULL,
imgg text NOT NULL
);
-- Dumping data for table empp
INSERT INTO empp (idd, first_name, last_name, e_mail, pass, d_o_b, gndr, contct, nid, addr, deprtmnt, deg,
imgg) VALUES
(121, 'Mohit', 'Kumar', '[email protected]', '1234', '1994-04-04', 'Male', '01919', 12221, 'Razarbagh', 'IT', 'Head',
'images/no.jpg'),
(122, 'Mohan', 'Kumar', '[email protected]', '1234', '2018-01-01', 'Male', '0202', 323, 'Ad_______', 'CS', 'CS',
'images/no.jpg'),
(123, 'Ram', 'Singh', '[email protected]', '1234', '1990-02-02', 'Male', '5252', 6222, 'Thames, UK', 'Creative', 'MSc',
'images/sw-google.png'),

31
(124, 'Govind', 'Iyer', '[email protected]', '1234', '1971-12-01', 'Male', '9595', 5929, 'Chemsford, USA',
'Creative', 'MSc', 'images/test.jpg'),
(125, 'Shyam', 'Manja', '[email protected]', '1234', '1971-06-28', 'Male', '8585', 5258, 'LA, USA', 'SpaceTech',
'BSc', 'images/330px-Elon_Musk_Royal_Society.jpg'),
-- Table structure for table emp_leave
CREATE TABLE emp_leave (
idd int(11) DEFAULT NULL,
token int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
start date DEFAULT NULL,
end date DEFAULT NULL,
reason char(100) DEFAULT NULL,
statuss char(50) DEFAULT NULL,
FOREIGN KEY (idd) REFERENCES empp (idd) ON DELETE CASCADE ON UPDATE CASCADE
);
-- Dumping data for table emp_leave
INSERT INTO emp_leave (idd, token, start, end, reason, statuss) VALUES
(101, 301, '2019-04-07', '2019-04-08', 'Sick Leave', 'Approved'),
(102, 302, '2019-04-07', '2019-04-08', 'Urgent Family Cause', 'Approved'),
(103, 303, '2019-04-08', '2019-04-08', 'Concert Tour', 'Approved'),
(105, 304, '2019-04-26', '2019-04-30', 'Launching Tesla Model Y', 'Pending'),
(104, 305, '2019-04-08', '2019-04-09', 'Emergency Leave', 'Pending');
-- Table structure for table projectt
CREATE TABLE projectt (
pidd int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
eidd int(11) DEFAULT NULL,
p_name varchar(100) DEFAULT NULL,
due_date date DEFAULT NULL,
sub_date date DEFAULT '0000-00-00',
markk int(11) NOT NULL,
statuss varchar(50) DEFAULT NULL,
FOREIGN KEY (eidd) REFERENCES empp (idd) ON DELETE CASCADE ON UPDATE CASCADE
);
-- Dumping data for table projectt
INSERT INTO projectt (pidd, eidd, p_name, due_date, sub_date, markk, statuss) VALUES
(213, 101, 'Database', '2019-04-07', '2019-04-04', 10, 'Submitted'),
(214, 102, 'Test', '2019-04-10', '0000-00-00', 0, 'Due'),
(215, 105, 'Maruti Model Y', '2019-04-19', '2019-04-06', 10, 'Submitted'),
(216, 105, 'Maruti Model X', '2019-04-03', '2019-04-03', 10, 'Submitted'),
(217, 103, 'Statistical', '2019-04-19', '2019-04-04', 6, 'Submitted'),
-- Table structure for table rank
CREATE TABLE rankk (
eidd int(11) NOT NULL PRIMARY KEY,
points int(11) DEFAULT 0,
FOREIGN KEY (eidd) REFERENCES empp (idd) ON DELETE CASCADE ON UPDATE CASCADE
);
-- Dumping data for table rank
INSERT INTO rankk (eidd, points) VALUES
(101, 10),(102, 0),(103, 6),(104, 0),(105, 20);
-- Table structure for table salaryy
CREATE TABLE salaryy (
idd int(11) NOT NULL PRIMARY KEY,
basee int(11) NOT NULL,
bonuss int(11) DEFAULT NULL,
tot int(11) DEFAULT NULL,
FOREIGN KEY (idd) REFERENCES empp (idd) ON DELETE CASCADE ON UPDATE CASCADE
);
-- Dumping data for table salaryy
INSERT INTO salaryy (idd, basee, bonuss, tot) VALUES
(101, 55000, 10, 60500), (102, 16500, 0, 16500), (103, 65000, 6, 68900), (104, 78000, 0, 78000), (105, 105000,
20, 126000);

32
COMMIT;
Questions:-
Q1. Print list of all the employees.
Ans1. SQL>SELECT * FROM empp;

Q2. Print name of all employees who lives in Razarbagh.


Ans2. SQL>SELECT CONCAT(first_name, ' ', last_name) as FullName from empp where addr='Razarbagh';

33
PRACTICAL – 9

TITLE: Library information system

9.1 Objective 9.2 Theory 9.3 Exercise

9.1 OBJECTIVE: Design and implementation of Library information system

9.2 THEORY AND CONCEPTS:

A Library Management System is a software built to handle the primary housekeeping functions of a library.
Libraries rely on library management systems to manage asset collections as well as relationships with their
members. Library management systems help libraries keep track of the books and their checkouts, as well as
members’ subscriptions and profiles.
Library management systems also involve maintaining the database for entering new books and recording books
that have been borrowed with their respective due dates.

CREATE TABLE resr_status (


idd INT,
status_val VARCHAR(50),
CONSTRAINT res_status PRIMARY KEY (idd)
);
CREATE TABLE catgry (
idd INT,
catgry_name VARCHAR(100),
CONSTRAINT catgry PRIMARY KEY (idd)
);
INSERT INTO catgry VALUES(101, 'maths'),(102, 'physics'),(103, 'chemistry'),(104, 'biology'),(105, 'english');
CREATE TABLE bokk (
idd INT,
titlee VARCHAR(500),
catgry_id INT,
pub_date DATE,
copies_owned INT,
CONSTRAINT bokk PRIMARY KEY (idd),
CONSTRAINT bokk_catgry FOREIGN KEY (catgry_id) REFERENCES catgry(idd)
);
CREATE TABLE authr (
idd INT,
first_name VARCHAR(300),
last_name VARCHAR(300),
CONSTRAINT authr PRIMARY KEY (idd)
);
CREATE TABLE bok_authr (
bokk_id INT,
author_id INT,
CONSTRAINT bokkauthor_bokk FOREIGN KEY (bokk_id) REFERENCES bokk(idd),
CONSTRAINT bokkauthor_author FOREIGN KEY (author_id) REFERENCES authr(idd)
);
CREATE TABLE membr_status (
idd INT,
status_val VARCHAR(50),
CONSTRAINT membrstatus PRIMARY KEY (idd),
);
CREATE TABLE membr (
idd INT,
first_name VARCHAR(300),

34
last_name VARCHAR(300),
joined_date DATE,
actv_status_id INT,
CONSTRAINT membr PRIMARY KEY (idd),
CONSTRAINT membr_status FOREIGN KEY (actv_status_id) REFERENCES membr_status(idd)
);
CREATE TABLE resrvtn (
idd INT,
bokk_id INT,
membr_id INT,
resrvtn_date DATE,
resrvtn_status_id INT,
CONSTRAINT resrvtn PRIMARY KEY (idd),
CONSTRAINT res_bokk FOREIGN KEY (bokk_id) REFERENCES bokk(idd),
CONSTRAINT res_membr FOREIGN KEY (membr_id) REFERENCES membr(idd)
);
CREATE TABLE finee_paymtn (
idd INT,
membr_id INT,
paymtn_date DATE,
paymtn_amount INT,
CONSTRAINT finee_paymtn PRIMARY KEY (idd),
CONSTRAINT fineepay_membr FOREIGN KEY (membr_id) REFERENCES membr(idd)
);
CREATE TABLE loann (
idd INT,
bokk_id INT,
membr_id INT,
loann_date DATE,
retrned_date DATE,
CONSTRAINT loann PRIMARY KEY (idd),
CONSTRAINT loann_bokk FOREIGN KEY (bokk_id) REFERENCES bokk(idd),
CONSTRAINT loann_membr FOREIGN KEY (membr_id) REFERENCES membr(idd)
);
CREATE TABLE finee (
idd INT,
bokk_id INT,
loann_id INT,
finee_date DATE,
finee_amount INT,
CONSTRAINT finee PRIMARY KEY (idd),
CONSTRAINT finee_bokk FOREIGN KEY (bokk_id) REFERENCES bokk(idd),
CONSTRAINT finee_loann FOREIGN KEY (loann_id) REFERENCES loann(idd)
);
COMMIT;
Questions:-
Q1. Print all types of books available in Library.
Ans1. SQL>SELECT catgry_name from catgry;
Q2. Print the fullname of all the authors.
Ans2. SQL>SELECT CONCAT(first_name, ' ', last_name) as FullName FROM authr;

35
PRACTICAL – 10

TITLE: Student information system

10.1 Objective 10.2 Theory 10.3 Exercise

10.1 OBJECTIVE: Design and implementation of student information system

10.2 THEORY AND CONCEPTS:


A Student Information System, or SIS, is a web-based platform that helps schools and colleges take data online
for easier management and better clarity. That's at its most basic.
The SIS system is able to collect school-wide data online so that it can be easily accessed by teachers, parents,
students, and administrators. That includes records of tests, attendance, appraisal performance, and plenty more.
Essentially, a SIS allows the school to make data points for lots of areas in one place so that it's easy to keep
track of progress and performance.
Code:-
-- Database
-- Table structure for table dev
CREATE TABLE dev (
idd int(10) NOT NULL PRIMARY KEY AUTO_INCREMENT,
name varchar(40) NOT NULL,
e_mail varchar(40) NOT NULL,
pass varchar(40) NOT NULL
);
-- Dumping data for table dev
INSERT INTO dev (idd, name, e_mail, pass) VALUES
(1, 'Mohan Kumar', '[email protected]', 'kumar'), (2, 'Rohan Singh', '[email protected]', 'kumar');
-- Table structure for table coursee
CREATE TABLE coursee (
coursee_id int(10) NOT NULL PRIMARY KEY AUTO_INCREMENT,
coursee_short_name varchar(250) NOT NULL,
coursee_full_name varchar(250) NOT NULL,
coursee_date varchar(50) NOT NULL
);
INSERT INTO coursee (coursee_id, coursee_short_name, coursee_full_name, coursee_date) VALUES
(44, 'M.C.A', 'MASTER OF COMPUTER APPLICATION', '25-04-2019'), (45, 'M.S.C', 'MASTER OF
SCIENCE', '25-04-2019'), (46, 'B.COM', 'BACHELOR OF COMMERCE', '25-04-2019'), (48, 'M.B.A ',
'MASTER OF BUSINESS ADMINISTRATION', '25-04-2019');
-- Table structure for table folow
CREATE TABLE folow (
idd int(10) NOT NULL PRIMARY KEY AUTO_INCREMENT,
to_user_id int(20) NOT NULL,
from_user_id int(20) NOT NULL
);
-- Dumping data for table folow
INSERT INTO folow (idd, to_user_id, from_user_id) VALUES
(29, 23, 20), (33, 20, 32), (37, 0, 21), (38, 21, 21), (40, 21, 20), (45, 30, 20), (46, 40, 20), (47, 20, 20);
-- Table structure for table folowing
CREATE TABLE folowing (
idd int(10) NOT NULL PRIMARY KEY AUTO_INCREMENT,
from_user_id varchar(20) NOT NULL,
to_user_id varchar(20) NOT NULL
);
-- Table structure for table folows
CREATE TABLE folows (
idd int(10) NOT NULL PRIMARY KEY AUTO_INCREMENT,
to_user_id int(20) NOT NULL,

36
from_user_id int(20) NOT NULL
);
-- Table structure for table postss
CREATE TABLE postss (
post_id int(10) NOT NULL PRIMARY KEY AUTO_INCREMENT,
from_user_id varchar(3) NOT NULL, content longtext NOT NULL,
image varchar(255) NOT NULL,
timestamp timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
);
-- Dumping data for table postss
INSERT INTO postss (post_id, from_user_id, content, image, timestamp) VALUES
(10, '1', 'Priyanka chopra', 'priyanka chopra.jpg', '2019-05-08 15:37:52'),
(70, '1', 'This website is developed by Social Codia.', 'socialcodia.png', '2020-04-27 21:15:56'),
(15, '1', 'The results of the best video ever try to get the way this can be its own incomplete website and I will be
its own incomplete website and I will be its own incomplete website and I will be its own incomplete website
and I will be its own incomplete websit', 'Screenshot_2019-05-05-20-08-26-
893_com.mxtech.videoplayer.ad.png', '2019-05-08 17:12:44'),
(17, '8', 'True Love &hearts;︕', '918369709214_status_eace0e54cee646309b0da5f908d6731f.jpg', '2019-05-08
19:14:13'),
(21, '8', 'Wow , Looking great Mohan... 😘😘😘', 'IMG_20190513_223507454.jpg', '2019-05-13
22:22:56'),
(22, '8', 'Ramzan Mubarak Mohan... 😘😘😘', 'B612_20190509_075024_942.jpg', '2019-05-13 22:24:01'),
(25, '20', 'Mohan Kumar The Boss', '6.jpg', '2019-05-19 05:55:07'),
(35, '20', 'Your genes decide whether you will own a dog or not, pawsible? Although dogs and other pets are
common household membrs across the globe, little is known how they impact our daily life and health.',
'dogsgenes.jpeg', '2019-05-20 00:28:40'),
(47, '21', 'demo post from student_id = 21', 'mohit.png', '2019-10-10 17:07:40'),
(48, '21', 'stack image', 'stock-vector-editable-square-frame-banner-template-for-social-media-post-red-black-
and-white-geometric-shape-1415216360.jpg', '2019-10-10 17:06:33'),
(59, '21', 'Rohan Singh', 'rohan - Copy.jpg', '2019-10-21 05:19:12');
-- Table structure for table stdnts
CREATE TABLE stdnts (
idd int(10) NOT NULL PRIMARY KEY AUTO_INCREMENT,
rollno varchar(255) NOT NULL,
standerd varchar(255) NOT NULL,
user_name varchar(40) NOT NULL,
name varchar(255) NOT NULL,
gndr varchar(255) NOT NULL,
contct varchar(255) NOT NULL,
e_mail varchar(255) NOT NULL,
pass varchar(255) NOT NULL,
cityy varchar(255) NOT NULL,
image varchar(255) NOT NULL
);
-- Dumping data for table stdnts
INSERT INTO stdnts (idd, rollno, standerd, user_name, name, gndr, contct, e_mail, pass, cityy, image)
VALUES
(20, '1', 'BCA', 'mohit', 'Mohan Kumar', 'male', '9867503256', '[email protected]', 'kumar', 'Thane',
'mohit.png'), (21, '2', 'Botanology', 'rohan', 'Rohan Singh', 'female', '9867503256', '[email protected]',
'kumar', 'Sipah', 'rohan.jpg'), (22, '6', '3', 'sohan', 'Sohan Kumar', 'male', '82684000646',
'[email protected]', 'kumar', 'Thane', '6.jpg'), (27, '10', '1', 'ibbu', 'Ram Kumar', 'male', '9920322293',
'[email protected]', 'kumar', 'Mumbra, Thane', '');
-- Table structure for table teacher
CREATE TABLE teacher (
idd int(10) NOT NULL PRIMARY KEY AUTO_INCREMENT,
name varchar(40) NOT NULL,
e_mail varchar(30) NOT NULL,
contct varchar(13) NOT NULL,
gndr varchar(7) NOT NULL,
position varchar(50) NOT NULL,

37
pass varchar(20) NOT NULL,
addr varchar(255) NOT NULL,
image varchar(60) NOT NULL
);
-- Dumping data for table teacher
INSERT INTO teacher (idd, name, e_mail, contct, gndr, position, pass, addr, image) VALUES
(1, 'Mohan Kumar', '[email protected]', '9555555256', 'male', 'Manager', 'kumar', 'kausa, mumbra, thane',
'mohan.png'),
(8, 'Rohan Kumar', '[email protected]', '7156478954', 'female', 'Head Teacher', 'kumara', 'Sipah', 'rohan.jpg');
COMMIT;

Questions:-
Q1. Print all the information regarding courses.
Ans1. SQL> SELECT * FROM coursee;
Q2. Print all information of teachers.
Ans2. SQL> SELECT * FROM teacher;

38
PRACTICAL – 11

TITLE: Automatic Backup of Files and Recovery of Files

11.1 Objective 11.2 Theory 11.3 Exercise

11.1 OBJECTIVE: Automatic Backup of Files and Recovery of Files

39
PRACTICAL – 12

40

You might also like