Lab Manual Dbms
Lab Manual Dbms
Lab Manual Dbms
B.TECH
(III YEAR – ODD SEM)
(2022-23)
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
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
PSO1: To apply standard software engineering practices & strategies in real-time software
project development.
Page | 3
Program Outcomes
Engineering Graduates will be able to:
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
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
Page | 8
PRACTICAL -1
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.
Page | 10
9. When the database has been created, you can unlock the users you want to use. Click OK.
To test that your installation completed successfully, perform the following steps:
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.
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
2.1 Objective 2.2 Theory (Installation & Dia Guide) 2.3 Assignment 2.4 Solution to Assignment
a. Installation Guide
Page | 14
4. In the “License Agreement” window click “Next” to continue installation.
Page | 15
6. Choose the installation location on your computer and click “Install”.
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.
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!
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.
6
PRACTICAL -3
TITLE : CREATING TABLES, INSERT INTO TABLES & SELECT FROM TABLES
View definition-
The SQL DDL includes commands for defining views.
Transaction Control- SQL includes for specifying the beginning and ending of transactions.
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.
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-
Syntax-
Create table tablename
(columnname datatype(size), columnname datatype(size));
Syntax-
CREATE TABLE TABLENAME
[(columnname, columnname, ………)]
AS SELECT columnname, columnname……..FROM tablename;
Syntax-
INSERT INTO tablename
[(columnname, columnname, ………)]
Values(expression, expression);
Syntax-
INSERT INTO tablename
SELECT columnname, columnname, …….
FROM tablename;
Syntax-
INSERT INTO tablename
SELECT columnname, columnname……..
FROM tablename
WHERE columnname= expression;
8
Retrieving of data from the tables-
Syntax-
SELECT * FROM tablename;
Syntax-
SELECT columnname, columnname, ….
FROM tablename;
Syntax-
SELECT DISTINCT columnname, columnname
FROM tablename;
Syntax-
SELECT columnname, columnname
FROM tablename
WHERE searchcondition;
3.3 ASSIGNMENT
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:
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.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
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.
Syntax:
Delete from tablename :
+ 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:
Logical Operators:
The logical operators that can be used in SQL sentenced are
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)
3.3 ASSIGNMENT
Que.1 Using the table client master and product master answer the following queries.
14
TITLE:TO IMPLEMENT CONSTRAINTS ON TABLES.
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:
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.
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.
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:
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);
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
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:
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));
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’);
19
TITLE : MODIFYING THE STRUCTURES OF THE TABLE.
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:
The following tasks you can perform through alter table command.
NOTE: Oracle not allow constraints defined using the alter table, if the data in the table, violates
such constraints.
Syntax:
DROP TABLE tabename:
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.
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.
5.3 ASSIGNMENT:
Q2. Insert the following values into the challan header and challan_details tables:
21
CH3965 P00001 5
CH3965 P07975 2
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’);
22
PRACTICAL - 4
23
PRACTICAL - 5
24
PRACTICAL – 6
TITLE: CURSOR
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;
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;
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
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.
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;
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
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.
Create a procedure which generate all the prime numbers below the given
number and count the no. of prime numbers.
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;
OUTPUT
sql>/
2
3
5
7
The total prime no. are 4
30
PRACTICAL – 8
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;
33
PRACTICAL – 9
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.
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
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 ♥︕', '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
39
PRACTICAL – 12
40