SlideShare a Scribd company logo
DEPARTMENT OF COMPUTER SCIENCE AND
BUSINESS SYSTEMS
CS3481 - DATABASE MANAGEMENT SYSTEMS
LABORATORY
FOR IV SEMESTER B.TECH. DEGREE COURSE
[REGULATION-2021]
As per the prescribed syllabus by
ANNA UNIVERSITY CHENNAI – 600025
R2021 / CSBS /CS3481 – DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM / 2
DEPARTMENT OF COMPUTER SCIENCE AND
BUSINESS SYSTEMS
LABORATORY MANUAL
SUBJECT CODE : CS3481
SUBJECT NAME : DATABASE MANAGEMENT SYSTEMS
LABORATORY
REGULATION : 2021
ACADEMIC YEAR : 2023-2024
YEAR/SEMESTER : II/IV
BATCH : 2022-2026
Prepared by:
Name:
Date:
Verified by:
Name:
Date:
Approved by:
Name:
Date:
R2021 / CSBS /CS3481 – DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM / 3
INSTITUTION VISION
Emerge as a premier institute producing globally competent
engineers.
INSTITUTION MISSION
IM1: Achieve academic diligence through effective and
innovative teaching – learning
processes using ICT tools.
IM2: Make students employable through rigorous career
guidance and training
programs.
IM3: Strengthen Industry Institute Interaction through MOUs
and collaborations.
IM4: Promote Research & Development by inculcating
creative thinking through
innovative projects incubation.
R2021 / CSBS /CS3481 – DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM / 4
DEPARTMENT VISION
To create skilled, industry ready professionals in the domain of Computer
Science and Business Systems who could make a positive contribution to
society through an understanding of information technology.
DEPARTMENT MISSION
DM 1 : To foster student talent and enable them to compete worldwide
through innovative teaching, research, and consultancy.
DM 2 : To regulate prospectus to reflect changing industry demands.
DM 3 : To instill a variety of skill sets that adhere to industry standards
and to uphold moral principles.
DM 4 : To develop professional ethics and life skills in individuals which
lead them to serve the society.
R2021 / CSBS /CS3481 – DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM / 5
PROGRAMME EDUCATIONAL OBJECTIVES (PEOs)
PEO1: To guarantee that graduates will be adept in applying the core
knowledge of basic sciences, math, computer science, and business
systems for the applications pertinent to diverse streams of engineering
and technology.
PEO2: To enhance graduates fundamental competencies to apply
computer science and data analytics tools knowledge to store, retrieve,
deploy, and analyse data in the context of corporate enterprise.
PEO3: To help graduates enter the workforce, establish themselves as
professionals, and satisfy the diverse demands of business, academia, and
research by putting their technical expertise and leadership abilities to use.
PEO4: To provide graduates with entrepreneurial abilities and traits that
will enable them to comprehend how businesses run, recognise business
issues, look for business possibilities, and become ready to manage
businesses successfully.
R2021 / CSBS /CS3481 – DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM / 6
PROGRAM SPECIFIC OUTCOMES (PSOs)
PSO1: To develop, pick, and use relevant methods, resources,
contemporary engineering tools, and business tools, such as data analytics
and prediction, for complicated engineering operations and business
solutions and to develop domain-specific approaches for decision-making
in a number of important real-world problem domains.
PSO2: To be able to use management techniques and entrepreneurial
skills to find, evaluate, and create business opportunities with clever
business ideas and to manage complex IT projects with an awareness of
risk management procedures, operational ramifications, and ethical,
financial, and environmental considerations
R2021 / CSBS /CS3481 – DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM / 7
PROGRAM OUTCOMES (POs)
Engineering Graduates will be able to:
PO 1 Engineering knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization to the solution of complex engineering
problems.
PO 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.
PO 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
PO 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.
PO 5 Modern tool usage: Create, select, and apply appropriate techniques, resources, and
modern engineering and IT tools including prediction and modeling to complex
engineering activities with an understanding of the limitations.
PO 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.
PO 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.
PO 8 Ethics: Apply ethical principles and commit to professional ethics and responsibilities
and norms of the engineering practice.
PO 9 Individual and Team work: Function effectively as an individual, and as a member or
leader in diverse teams, and in multidisciplinary settings.
PO10 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.
PO11 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.
PO12 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.
R2021 / CSBS /CS3481 – DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM / 8
COURSE OBJECTIVE
 To learn and implement important commands in SQL.
 To learn the usage of nested and joint queries.
 To understand functions, procedures and procedural extensions of databases.
 To understand design and implementation of typical database applications.
 To be familiar with the use of a front end tool for GUI based application development.
COURSE OUTCOME
At the end of this course, the students will be able to:
CO1: Write SQL queries using typical data definition language and data manipulation language
with different types of Key constraints in relational database management system
CO2: Construct SQL queries using and using where clause perform different join operations and
apply Data Control Language for complex transactions.
CO3: Apply advanced features of PL/SQL such as stored procedures and triggers, incorporate in
GUI based application development.
CO4: Apply view, index for an SQL database and Create a web application to retrieve data from
XML database with XML Schema validation.
CO5: Create and manipulate NoSQL database to perform CRUD operations, apply the database
design for a real time application.
R2021 / CSBS /CS3481 – DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM / 9
CO-PO&PSO MAPPING
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2 PSO3
CO1 3 2 2 2 - - - - - - - - 2 - -
CO2 3 2 2 2 - - - - - - - - 2 - -
CO3 3 2 2 1 - - - - - - - - 2 - -
CO4 3 2 2 1 - - - - - - - - 2 - -
CO5 3 2 2 1 - - - - - - - - 2 - -
Avg 3 2 2 1.4 - - - - - - - - 2 - -
R2021 / CSBS /CS3481 – DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM / 10
GENERAL INSTRUCTIONS TO THE STUDENTS
1. No food or drink is to be brought into the lab, including gum and candy.
2. No cell phones or electronic devices at the lab stations (i pods, MP3 Players, etc.,).
3. Students must proceed immediately to their assigned position.
4. Students should maintain silence during the Lab session.
5. Students must inspect their position for possible damage and report immediately to the
faculty any damage that may be found.
6. Students must follow the faculty’s instructions explicitly concerning all uses of the lab
equipment.
7. Leave your shoes in the shoes rack before entering into the lab
8. Shut down the computer properly before leaving from the lab.
9. Do not bring college bag inside the lab.
10. Arrange your chairs properly before leaving from the lab
11. Students must wear lab coat during lab session
R2021 / CSBS /CS3481 – DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM / 11
SYLLABUS
CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY L T P C
0 0 3 1.5
COURSE OBJECTIVES:
 To learn and implement important commands in SQL.
 To learn the usage of nested and joint queries.
 To understand functions, procedures and procedural extensions of databases.
 To understand design and implementation of typical database applications.
 To be familiar with the use of a front-end tool for GUI based application development.
LIST OF EXERCISES:
1. Create a database table, add constraints (primary key, unique, check, Not null), insert rows, update and
delete rows using SQL DDL and DML commands.
2. Create a set of tables, add foreign key constraints and incorporate referential integrity.
3. Query the database tables using different ‘where’ clause conditions and also implement aggregate
functions.
4. Query the database tables and explore sub queries and simple join operations.
5. Query the database tables and explore natural, equi and outer joins.
6. Write user defined functions and stored procedures in SQL.
7. Execute complex transactions and realize DCL and TCL commands.
8. Write SQL Triggers for insert, delete, and update operations in a database table.
9. Create View and index for database tables with a large number of records.
10. Create an XML database and validate it using XML schema.
11. Create Document, column and graph based data using NOSQL database tools.
12. Develop a simple GUI based database application and incorporate all the above-mentioned features
13. Case Study using any of the real life database applications from the following list
a) Inventory Management for a EMart Grocery Shop
b) Society Financial Management
c) Cop Friendly App – Eseva
d) Property Management – eMall
e) Star Small and Medium Banking and Finance
● Build Entity Model diagram. The diagram should align with the business and functional goals stated in
the application. 42
● Apply Normalization rules in designing the tables in scope.
● Prepared applicable views, triggers (for auditing purposes), functions for enabling enterprise grade
features.
● Build PL SQL / Stored Procedures for Complex Functionalities, ex EOD Batch Processing for
calculating the EMI for Gold Loan for each eligible Customer.
● Ability to showcase ACID Properties with sample queries with appropriate settings
TOTAL: 45 PERIODS
R2021 / CSBS /CS3481 – DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM / 12
LIST OF EXPERIMENTS – CO MAPPING
S.No TITLE OF THE PROGRAM CO’S
1. DDL AND DML COMMANDS CO1
2. FOREIGN KEY CONSTRAINT CO1
3.
WHERE CLAUSE AND AGGREGATE
FUNCTIONS
CO2
4. SUB QUERIES AND SIMPLE JOIN CO2
5. NATURAL, EQUI, OUTER JOIN CO2
6. FUNCTIONS AND STORED PROCEDURES CO3
7.
DCL AND TCL COMMANDS CO2
8. TRIGGERS CO3
9. VIEW AND INDEX CO4
10. XML DATABSE AND XML SCHEMA CO4
11. NOSQL DATABASE CO5
12. GUI APPLICATION CO5
13. REAL LIFE APPLICATION CO5
R2021 / CSBS /CS3481 – DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM / 13
INDEX
Exp.
No.
Date Experiment
Page
No.
Marks
Faculty
Signature
1. DDL AND DML COMMANDS
2. FOREIGN KEY CONSTRAINT
3.
WHERE CLAUSE AND
AGGREGATE FUNCTIONS
4. SUB QUERIES AND SIMPLE JOIN
5. NATURAL, EQUI, OUTER JOIN
6.
FUNCTIONS AND STORED
PROCEDURES
7. DCL AND TCL COMMANDS
8. TRIGGERS
9. VIEW AND INDEX
10.
XML DATABSE AND XML
SCHEMA
11. NOSQL DATABASE
12. GUI APPLICATION
13. REAL LIFE APPLICATION
EX.NO:1a DATA DEFINITION COMMANDS
DATE:
AIM:
Commands
To implement database creation and do the operations in database using Data Definition
ALGORITHM:
Step 1: Create table by using create table command with column name, data type and size.
Step 2: Display the table by using desc command.
Step 3: Add any new column with the existing table by alter table command.
Step 4: Modify the existing table with modify command.
Step 5: Delete the records in files by truncate command.
Step 6: Delete the Entire table by drop command.
1) CREATE TABLE
Syntax:
create table table_name( column1 datatype, column2 datatype, column3 datatype,
..... columnN datatype);
Example:
create table employee(id int,name varchar(100),age int,address varchar(100),salary float);
Table employee created
2) DESCRIBING THE TABLE
Syntax:
desc table_name;
Example:
desc employee;
3) ALTER TABLE
Syntax:
alter table table_name add column_name datatype;
Example:
alter table employee add dept varchar(10);
table employee altered
select * from employee;
Example:
alter table employee add (state varchar(100),weight float);
table employee altered.
select * from employee;
table employee altered.
4) RENAME
To rename column name
Syntax:
alter table table_name rename column existing _name to new_name;
Example:
alter table employee rename column address to addr;
table employee altered.
select * from employee
To rename table name
Syntax:
alter table table_name rename to new_table_name;
Example:
alter table employee rename to empl;
table employee altered.
select * from employee;
ORA-00942: table or view does not exist
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Error at Line: 21 Column: 15
select * from empl;
5) TRUNCATE
Syntax:
truncate table table_name;
Example:
truncate table emp;
select * from empl;
no data found
6) DROP TABLE
Syntax:
drop table table_name;
Example:
drop table empl;
table customers dropped.
select * from empl;
ORA-00942: table or view does not exist
RESULT:
Thus the queries to implement data definition commands are executed successfully.
EX.NO:1b DATA MANIPULATION COMMANDS
DATE:
AIM:
To implement and execute a query for manipulating & storing data items in a Oracle
database using Structured Query Language commands
ALGORITHM:
Step 1: Create table by using create table command.
Step 2: Insert values into the table
Step 3: Delete any records from the table
Step 4: Update any values in the table.
Step 5: Display the values from the table by using select command.
1) CREATE A TABLE
create table student(id int,Name varchar(30),Department varchar(10));
desc student;
2) INSERT
Syntax:
insert into table_name values(column1,column2,….);
Example:
insert into student values(1,'ABC','CSE');
insert into student values(2,'DEF','CSE');
select * from student;
To insert NULL values to column:
The following syntax is used to insert NULL value to the column.
insert into student values(3,'null','CSE');
select * from student;
To insert default value to the column:
The following syntax is used to insert default value to the table.
Syntax:
insert into table_name values(column1,column2,…);
Example:
insert into student values(3,’alex’,default);
1 rows inserted.
select * from student;
To insert data using select statement:
The following syntax is used insert all the values from another table using select statement.
Syntax:
insert into table_name1 select * from table_name2;
Example:
create table stud(id int,Name varchar(30),Department varchar(10));
insert into stud select * from student;
3) UPDATE
Syntax:
update table_name set column1 = value1, column2 = value2. .., columnn = valuen
where [condition];
Example: (single column)
update stud set Department='ECE' where id=3;
1 rows updated.
Example: (multiple column)
update stud set Name=’XYZ’,Department='CIVIL' where id=2;
4) DELETE
Syntax: (delete particular row)
delete from table_name where condition;
Example:
delete from stud where id=2;
Syntax:
delete from table_name;
Example:
delete from stud;
select * from stud;
no data found
RESULT:
Thus, a query for manipulating & storing data items in an Oracle database using
Structured Query Language commands were implemented and executed successfully.
EXPERIMENT – 1
VIVA QUESTIONS
1. What is DBMS?
Database Management Systems (DBMS) are applications designed especially which
enable user interaction with other applications.
2. What is DDL?
DDL is Data Definition Language which is used to define the database and schema
structure by using some set of SQL Queries like CREATE, ALTER, TRUNCATE,
DROP and RENAME.
3. What is DML?
DML is Data Manipulation Language which is used to do some manipulations in the
database like Insertion, Deletion, etc. by using some set of SQL Queries like SELECT,
INSERT, DELETE and UPDATE.
4. What is purpose of SQL?
SQL stands for Structured Query Language whose main purpose is to interact with the
relational databases in the form of inserting and updating/modifying the data in the
database
5. What is Primary Key & Unique Key?
The main difference between the Primary key and Unique key is that the Primary key
can never have a null value while the Unique key may consist of null value.
6. Write a query to Create a table?
CREATE TABLE table_name( column1 datatype,
column2 datatype, column3 datatype, );
7. What is foreign key?
Foreign Key is mainly used to link two or more tables together, as this is a particular
field(s) in one of the database tables which are the primary key of some other table.
8. What are the various kinds of interactions catered by DBMS?
The various kind of interactions catered by DBMS are:
 Data definition
 Update
 Retrieval
 Administration
9. What is SQL?
Structured Query Language (SQL) being ANSI standard language updates database and
commands for accessing
10. Enlist the various relationships of database?
The various relationships of database are:
 One-to-one: Single table having drawn relationship with another table
having similar kind of columns.
 One-to-many: Two tables having primary and foreign key relation.
 Many-to-many: Junction table having many tables related to many tables.
EX.NO:2 CREATE SET OF TABLES ADD FOREIGN KEY CONSTRAINT AND
DATE: INCORPORATE REFERENTIAL INTEGRITY
Aim:
To create set of tables add foreign key constraint and incorporate referential integrity using SQL.
Algorithm:
 Create two tables with a link that will not work.
 Create two tables with a link that will work.
 Add a foreign key to enforce referential integrity between the two tables.
 Delete data from the tables.
 Update and remove data to show how the foreign key protects the data.
 Use the cascade option of the foreign key.
 Companies table: List of Companies
 Employees table: List of Employees working at the Company
 Rule: Employees can only work at one Company, and a Company can employ multiple
Employees
Program:
Step 1:
--Create the HRDatabase
USE master
GO
DROP DATABASE IF EXISTS HRDatabase
GO
CREATE DATABASE HRDatabase
GO
USE HRDatabase
GO
Step 2:
-1st Try: Create a Companies and an Employees table and link them together
DROP TABLE IF EXISTS Companies;
GO
DROP TABLE IF EXISTS Employees;
GO
-- SQL CREATE TABLE Statement
CREATE TABLE Companies (
ID INT CONSTRAINT PK_Companies PRIMARY KEY IDENTITY,
CompanyName VARCHAR(80) NOT NULL, -- column name, data types and null value
CompAddress VARCHAR(80) NOT NULL,
CompContactNo VARCHAR(20) NOT NULL,
EmpID INT NOT NULL,
CreateDate DATETIME NOT NULL constraint DF_Companies_CreateDate DEFAULT
getdate()
) CREATE TABLE Employees (
ID INT CONSTRAINT PK_Employees PRIMARY KEY IDENTITY,
EmployeeName VARCHAR(80) NOT NULL,
ContactNo VARCHAR(20) NOT NULL,
Email VARCHAR(80) NOT NULL,
CreateDate DATETIME NOT NULL constraint DF_Employees_CreateDate DEFAULT
getdate()
)
INSERT INTO Companies (CompanyName, CompAddress, CompContactNo, EmpID)
VALUES
('Alpha Company', '123 North Street, Garsfontein, Pretoria', '091 523 6987' , 1),
('Bravo Company', '456 South Street, Brooklyn, Pretoria', '091 523 4789' , 1),
('Charlie Company' , '987 West Street, Lynnwood, Pretoria', '091 523 1235' , 1),
('Delta Company', '258 East Street, The Meadows, Pretoria', '091 523 7414' , 1),
('Echo Company', '100 Amber Street, Hatfield, Pretoria', '091 523 9685' , 1)
INSERT INTO Employees (EmployeeName, ContactNo, Email) VALUES
('Joe Blogs' , '012 365 4789', 'joeblogs@gmail.com') ,
('Jane Doe' , '012 365 4789', 'janedoe@gmail.com') ,
('John Smit' , '012 365 4789', 'johnsmit@gmail.com') ,
('Eddy Jones' , '012 365 4789', 'eddyjones@gmail.com'),
('Steve Dobson', '012 365 4789', 'stevedobson@gmail.com')
SELECT * FROM Companies
SELECT * FROM Employees
OUTPUT :
3
RESULT:
Thus, to create a set of tables add foreign key constraint and incorporate referential integrity were
implemented and executed successfully.
EXPERIMENT – 2
VIVA QUESTIONS
1. Define Aggregate functions?
Functions which operate against a collection of values and returning single value is called
aggregate functions
2. Define Scalar functions?
Scalar function is depended on the argument given and returns sole value.
3. Why WHERE clause is used?
The WHERE clause is used to filter records.
It is used to extract only those records that fulfill a specified condition. Syntax
SELECT column1, column2, ... FROM table_name
WHERE condition.
4. What is ACID Properties?
A-Atomicity
C-Consistency I-Isolation
5. Different types of abstraction levels?
There are 3 levels of data abstraction in the DBMS.
Physical level
Logical level
View level
6. What is the concept of sub-query in terms of SQL?
Sub-query is basically the query which is included inside some other query and can also
be called as an inner query which is found inside the outer query
7. What is Correlated Subquery in DBMS?
A Subquery is also known as a nested query i.e. a query written inside some query. When
a Subquery is executed for each of the rows of the outer query then it is termed as a
Correlated Subquery.
8. What is a join in the SQL?
A Join is one of the SQL statements which is used to join the data or the rows from 2 or
more tables on the basis of a common field/column among them.
9. What is simple join?
Join is used to display matching records from both tables. This is also called a simple if
you omit inner the keyword and just use join, this is the type of join you’ll get by default.
10. What are the 4 types of joins in SQL?
a. Inner join
b. Right join
c. Left join
d. Full join
EX.NO:3 DATABASE TABLES WITH DIFFERENT 'WHERE CLAUSE' CONDITIONS
DATE:
Aim:
To using query the database tables with different 'where clause' conditions also implement
aggregate function with algorithm
Algorithm:
Step 1:
There are tables country and city. We’ll use the following statements:
SELECT *
FROM country;
SELECT *
FROM city;
You can see the result in the picture below:
Step 2:
SELECT *
FROM country
INNER JOIN city ON city.country_id = country.id;
SELECT COUNT(*) AS number_of_rows
FROM country
INNER JOIN city ON city.country_id = country.id;
Step 3:
SELECT *FROM country
LEFT JOIN city ON city.country_id = country.id;
SELECT COUNT(*) AS number_of_rows
FROM country
LEFT JOIN city ON city.country_id = country.id;
SELECT COUNT(country.country_name) AS countries, COUNT(city.city_name) AS cities
FROM country
LEFT JOIN city ON city.country_id = country.id;
RESULT:
Thus the SQL query the database tables with different 'where clause' conditions also
implement aggregate function are executed successfully.
EXPERIMENT – 3
VIVA QUESTIONS
1. How do you retrieve data from a table based on a specific condition?
You can use the SELECT statement with the WHERE clause.
2. Explain how you can combine multiple conditions in a WHERE clause.
You can use the AND and OR operators to combine conditions.
3. How do you filter data based on multiple possible values?
You can use the IN operator for this purpose.
4. How can you retrieve data within a specific range?
The BETWEEN operator is used for this.
5. How do you perform a partial string match in a WHERE clause?
The LIKE operator is used, along with wildcards (% for any characters, _ for a single
character).
6. How do you filter records based on the presence or absence of NULL values?
You can use the IS NULL or IS NOT NULL conditions
7. Can you retrieve data with a specific condition and have it ordered in a particular way?
Yes, you can combine WHERE with ORDER BY.
8. How do you handle complex conditions in a WHERE clause?
You can use parentheses to group conditions and control the logic.
9. What is natural joins?
A NATURAL JOIN is a JOIN operation that creates an implicit join clause for you
based on the common columns in the two tables being joined. Common columns are
columns that have the same name in both tables.
10. What is equi in sql?
The EQUI JOIN in SQL performs a JOIN against a column of equality or the matching
column(s) values that have the associated tables. Here, we use an equal sign (=) as a
comparison operator in our ‘where’ clause to refer to equality.
EX.NO:4 SIMPLE QUERIES, SUB QUERIES, JOINS
DATE:
AIM:
To implement Simple queries, Nested queries, Sub queries using structured query
language
ALGORITHM:
STEP 1: Create a table with the columns that are needed
STEP 2: Write simple queries to insert, delete, update and implement some functions
STEP 3: Write nested queries using clauses to retrieve data from the table
STEP 4: The nested queries may have more than one sub queries.
STEP 5: Efficiently retrieve data from the table
QUERIES:
create table salary(id int, Name varchar(20),Age int,Salary float);
insert into salary values(1,'Ajay',25,20000);
insert into salary values(2,'Archana',28,30000);
insert into salary values(3,'Archana',23,25000);
insert into salary values(4,'Sara',24,20000);
insert into salary values(5,'Ajay',25,40000);
insert into salary values(6,'Srinithi',26,35000);
select * from salary;
Sum function
Syntax:
select column_name1,sum(column_name2)from table_name group by column_name3;
Example:
select name, sum(salary) from salary group by name;
Min function
Syntax:
select column_name1,min(column_name2)from table_name group by column_name3;
Example:
select name, min(salary) from salary group by name;
Max function
Syntax:
select column_name1,max(column_name2)from table_name group by column_name3;
Example:
select name, max(salary) from salary group by name;
Count function
Syntax:
select column_name1,count(column_name2)from table_name group by column_name3;
Example:
select name, count(salary) from salary group by name;
Mod function
Syntax:
select column_name1,mod(column_name2)from table_name;
Example:
select name,mod(salary,5) from salary;
DISTINCT and ORDER BY Clause
Syntax:
select distinct column1, column2,.... columnn from table_name;
Example:
select salary from salary order by salary;
select distinct salary from salary order by salary;
HAVING clause
Example:
select min(salary)from salary group by age having max(salary)<30000;
Select using Conditions
AND
Example:
select * from salary where age >= 25 and salary >= 25000;
OR
Example:
select * from salary where age >= 25 or salary >= 25000;
LIKE
select * from salary where name like 'Aj%';
select * from salary where age in ( 25, 28 );
IN
BETWEEN
select * from salary where salary between 20000 and 30000;
IS NOT NULL
select * from salary where age is not null;
IS NULL
select * from salary where age is null;
no data found
(4,'Kumaran',25,'CBE',24000);
SubquerieswiththeINSERTStatement
INSERT INTO customers_backup
SELECT * FROM CUSTOMERS
WHERE ID IN
(SELECT ID
FROM CUSTOMERS) ;
4 rows inserted
select * from customers_backup;
SubquerieswiththeUPDATEStatement
UPDATE CUSTOMERS
SET SALARY = SALARY * 0.25
WHERE AGE IN
(SELECT AGE FROM customers_backup
WHERE AGE >= 27 );
Select * from customers;
SubquerieswiththeDELETEStatement
DELETE FROM CUSTOMERS
WHERE AGE IN
(SELECT AGE FROM CUSTOMERS_backup
WHERE AGE >= 27 );
select * from customers;
select age from customers where exists (select age from salary where salary > 25000);
JOINS
CREATE and INSERT values in TABLE(cust)
create table cust(id int primary key,name varchar(20),age int);
insert into cust values(1,'aaa',32);
insert into cust values(2,'aba',32);
insert into cust values(3,'abc',32);
insert into cust values(4,'ccc',25);
select * from cust;
CREATE and INSERT values in TABLE(order1)
create table order1(oid int primary key,custid int,amount int);
insert into order1 values(101,1,1000);
insert into order1 values(102,2,2000);
insert into order1 values(103,3,3000);
1. INNER JOIN
Syntax:
SELECT table1.column1, table2.column2...
FROM table1
INNER JOIN table2
ON table1.common_filed = table2.common_field;
Example:
select id,name,oid,amount
from cust
inner join order1
on cust.id=order1.custid;
2. LEFT JOIN:
Syntax:
select table1.column1, table2.column2...
from table1
left join table2
on table1.common_filed = table2.common_field;
Example:
select id,name,oid,amount
from cust
left join order1
on cust.id=order1.custid;
3. RIGHT JOIN:
Syntax:
select table1.column1, table2.column2...
from table1
right join table2
on table1.common_filed = table2.common_field;
Example:
select id,name,oid,amount
from cust
right join order1
on cust.id=order1.custid;
4. FULL JOIN:
Syntax:
select table1.column1, table2.column2...
from table1
full join table2
on table1.common_filed = table2.common_field;
Example:
select id,name,oid,amount
from cust
full join order1
on cust.id=order1.custid;
RESULT:
Thus the SQL commands to execute simple queries, sub queries and joins areexecuted
successfully.
EXPERIMENT – 4
VIVA QUESTIONS
1. What is a sub query, and how is it different from a regular query?
A sub query is a query nested inside another query. It can be used within a WHERE
clause to retrieve data that will be used by the main query.
2. Provide an example of a correlated sub query.
A correlated sub query references a column from the outer query.
Example: SELECT employee_name FROM employees WHERE salary > (SELECT
AVG(salary) FROM employees WHERE department_id =
employees.department_id);
3. When would you use a sub query instead of a JOIN?
Sub queries are useful when you need to retrieve a single value or a set of values that
can be used by the main query, while Joins are used to combine columns from two or
more tables.
4. Explain the difference between INNER JOIN and LEFT JOIN.
INNER JOIN returns only the matching rows between two tables, while LEFT JOIN
returns all rows from the left table and the matching rows from the right table.
5. What is a self-join, and in what scenario would you use it?
A self-join is when a table is joined with itself. It is used when you want to compare
records within the same table, such as finding employees who share the same manager.
6. How do you retrieve columns from multiple tables using a JOIN?
Use the SELECT statement with the appropriate JOIN clause.
For example: SELECT employees.employee_name, departments.department_name
FROM employees INNER JOIN departments ON employees.department_id =
departments.department_id;
7. Explain the purpose of the USING clause in a JOIN.
The USING clause is used to specify a column that exists in both tables and should be
used as the join condition.
For example: SELECT * FROM employees JOIN departments USING
(department_id);
8. . Is SELF JOIN an INNER JOIN or OUTER JOIN?
The SELF JOIN can be an INNER JOIN, OUTER JOIN, or can also be CROSS JOIN.
Tables are automatically linked based on columns that contain duplicate data in
multiple rows.
9. IS required that the JOIN condition be based on equality?
No, because JOINS have the conditions of NON-EQUI. Sentence combinations can
be done with common ssymbols such as <, <=, >, >=, !=, BETWEEN, for example,
to represent data. Odd-pair indexing and identifying duplicate data are several cases
where NON-EQUI JOINS performance can be demonstrated.
10. What is index in sql?
Indexes are used to retrieve data from the database more quickly than otherwise. The
users cannot see the indexes, they are just used to speed up searches/queries
EX.NO:5 NATURAL, EQUI AND OUTER JOIN
DATE:
Aim
To write DQL Commands to join, Restrict and Retrieve information from one or more
tables execute it and verify the same.
Algorithm
Selecting Rows with Equijoin using table Aliases
1. Write a query to display empid,name,deptid,deptname and
location for allemployees and verify it.
SQL> select
employee.empid,employee.name,employee.depid,department.deptname,depa
rtment.location from employee,department where
employee.depid=department.depid;
EMPID NAME DEPID DEPTNAME LOCATION
a123 ragu CS000 COMPUTER_SCIENCE CHENNAI
a124 rama CS000 COMPUTER_SCIENCE CHENNAI
a125 ram EE000 ELECT_ELECTRO MUMBAI
a128 sag EE000 ELECT_ELECTRO MUMBAI
c128 dinesh EC000 ELECT_COMM DELHI
d124 abc EC000 ELECT_COMM DELHI
6 rows selected.
2. Write a query to display the “dinesh” depid and deptname and verify it.
SQL> select e.empid,e.name,e.depid,d.deptname from employee
e,department d wheree.depid=d.depid and e.name='dinesh';
EMPID NAME DEPID DEPTNAME
c128 dinesh EC000 ELECT_COMM
Selecting Rows with Non-Equijoin using table Aliases:
[Other Conditions such as >=, <= and BETWEEN, AND ]
1. Write a query to display the name,salary and deptname of all
employees whosesalary is greater than 10000 and verify it.
SQL> select e.name,e.salary,d.deptname from employee e,department d where
e.salary>10000and e.depid=d.depid;
NAME SALARY DEPTNAME
ragu 200000 COMPUTER_SCIENCE
rama 200000 COMPUTER_SCIENCE
ram 30000 ELECT_ELECTRO
Selecting Rows using Outer Joins:[ Left Outerjoin,Right Outerjoin using ”+”
symbol ]
1. Write a query to display the name, depid and deptname of all
employees.Make surethat employees without department are included as
well and verify it.
SQL> select e.name,e.depid,d.deptname from employee e,department d where e.depid
=d.depid(+);
NAME DEPID DEPTNAME
rama CS000 COMPUTER_SCIENCE
ragu CS000 COMPUTER_SCIENCE
sag EE000 ELECT_ELECTRO
ram EE000 ELECT_ELECTRO
abc EC000 ELECT_COMM
dinesh EC000 ELECT_COMM
www
7 rows selected.
2.Write a query to display the name, salary,depid and deptname of
all employees. Makesure that departments without employees are
included as well and verify.
SQL> select e.name,e.salary,e.depid,d.deptname from employee
e,department d where e.depid(+)=d.depid;
NAME SALARY DEPID DEPTNAME
ragu 200000 CS000 COMPUTER_SCIENCE
rama 200000 CS000 COMPUTER_SCIENCE
ram 30000 EE000 ELECT_ELECTRO
sag 10000 EE000 ELECT_ELECTRO
dinesh 10000 EC000 ELECT_COMM
abc 5000 EC000 ELECT_COMM
MECHANICAL
CHEMICAL
8 rows selected
d
RESULT:
Thus the SQL commands to execute natural, equi and outer joins areexecuted successfully.
EXPERIMENT – 5
VIVA QUESTIONS
1. What is a Database system?
The database and DBMS software together is called as Database system.
2. What are the Advantages of DBMS?
Redundancy is controlled.
Unauthorized access is restricted.
Providing multiple user interfaces.
Enforcing integrity constraints. Providing backup and recover.
3. What is functional dependency in DBMS?
This is basically a constraint which is useful in describing the relationship among
the different attributes in a relation.
4. What is stored procedures?
A stored procedure is a prepared SQL code that you can save, so the code can be
reused over and over again. So if you have an SQL query that you write over and
over again, save it as a stored procedure.
5. What is an entity?
It is a `thing’ in the real world with an independent existence.
6. Can you provide an example of when you would use a Natural Join?
Suppose you have a "Customers" table and an "Orders" table, both having a
"CustomerID" column. A Natural Join could be used to retrieve information about
customers and their corresponding orders without explicitly specifying the join
condition.
7. What is the key characteristic of an Equi Join?
The key characteristic of an Equi Join is that it involves the use of the equality
operator (=) to match rows between two tables based on specified columns.
8. Can you give an example of when you might use an Equi Join in a database query?
Let's say you have a "Students" table and a "Courses" table, both having a
"StudentID" column. An Equi Join could be used to find students who are enrolled
in specific courses by matching the "StudentID" values
9. Explain the concept of an Outer Join.
An Outer Join retrieves matching rows from tables and includes non-matching rows
from one or both tables. It ensures that even if there are no matches, rows from one
or both tables are still included in the result set.
10. Write the syntax for view?
CREATE VIEW view_name AS SELECT columns FROM tables [WHERE
conditions]; view_name.
EX.NO:6 PROCEDURES AND FUNCTIONS
DATE:
AIM:
To implement and execute Procedures in Oracle Database using Procedural Language
concepts.
PROCEDURES:
1) Procedure is a sub program used to perform an action.
2) Replace-recreates the procedure if it already exists.
3 MODES:
1) IN – Means you must specify a value for the argument at the time execution of the procedure.
2) OUT-passes back a value to its calling program.
3) INOUT – When calling the procedure, yu must specify the value and that procedures passes value back
to the calling procedure
CREATING A PROCEDURE
SYNTAX:
CREATE [OR REPLACE] PROCEDURE procedure_name
[(column_name [IN | OUT | IN OUT] type [, ...])]
{IS |
AS}
BEGIN
< procedure_body >
END procedure_name;
CREATE OR REPLACE PROCEDURE greetings
AS
BEGIN
dbms_output.put_line('Hello World!');
END;
To run this procedure
BEGIN
greetings;
END;
DELETING A PROCEDURE
SYNTAX:
DROP PROCEDURE procedure-name;
EXAMPLE:
DROP PROCEDURE greetings;
Procedure dropped
EXAMPLE 2
Create a table user1
create table user1(id number(10) primary key,name varchar2(100));
Create the procedure
create or replace procedure
INSERTUSER(id IN NUMBER, name IN VARCHAR2)
is
begin
insert into user1 values(id,name);
end;
To execute the procedure
BEGIN
INSERTUSER(101,'Rahul');
dbms_output.put_line('record inserted successfully');
END;
PL/SQL FUNCTIONS
SYNTAX:
CREATE [OR REPLACE] FUNCTION function_name [parameters]
[(parameter_name [IN | OUT | IN OUT] type [, ...])]
RETURN return_datatype
{IS | AS}
BEGIN
< function_body >
END [function_name];
create or replace function adder(n1 in number, n2 in number)
return number
is
n3 number(8);
begin
n3 :=n1+n2;
return n3;
end;
EXECUTE THE FUNCTION
DECLARE
n3 number(2);
BEGIN
n3 := adder(11,22);
dbms_output.put_line('Addition is: ' || n3);
END;
Output:
Addition is: 33
Statement processed.
RESULT:
Thus the PL/SQL procedures and functions are executed successfully
EXPERIMENT – 6
VIVA QUESTIONS
1. What is a stored procedure?
A stored procedure is a recompiled collection of one or more SQL statements that
can be stored and executed on a database server. It allows for the reuse of code and
helps improve performance by reducing the need to send multiple SQL statements
over the network.
2. How is a stored procedure different from a regular SQL query?
A stored procedure is a saved set of SQL statements with a name and can accept
parameters. It is recompiled and stored on the server, whereas a regular SQL query
is sent to the server for immediate execution.
3. What are the advantages of using stored procedures?
Stored procedures offer advantages such as code re usability, improved
performance due to recompilation, better security control, and easier maintenance.
4. Can you explain how parameters work in stored procedures?
Parameters in stored procedures act as placeholders for values that can be passed
during the procedure's execution. They allow for flexibility and customization of
the procedure's behavior.
5. How do you call a stored procedure?
A stored procedure is called using the CALL or EXECUTE statement, followed by
the procedure name and any necessary parameters.
6. What is a function in the context of a database?
A function is a recompiled set of SQL statements that performs a specific task and
returns a single value. It is similar to a stored procedure but is designed to return a
value rather than perform an action
7. How is a function different from a stored procedure?
While both functions and stored procedures can contain sets of SQL statements,
functions return a value, while stored procedures do not necessarily return a value
but may perform actions.
8. What are the types of functions commonly used in databases?
Common types of functions include scalar functions (returning a single value),
table-valued functions (returning a table), and aggregate functions (performing a
calculation on a set of values).
9. Can functions have side effects?
Ideally, functions are designed to be deterministic and not have side effects.
However, some database systems allow functions to have side effects, which can
impact the consistency of the database.
10. What is TCL?
TCL is abbreviation of Transaction Control Language. It is used to manage different
transactions occurring within a database.
EX.NO.7 TRANSACTION CONTROL AND DATA CONTROL STATEMENTS
DATE:
AIM:
To implement Transaction Control statements using structured Query Language
ALGORITHM:
Step 1: Create table by using create table command.
Step 2: Insert values into the table
Step 3: Commit the table
Step 4: Insert or Update any values in the table.
Step 5: Rollback the table
Step 6: Insert or Update any values in the table.
Step 7: Fix a save point
Step 8: Repeat step 6 and 7
Step 9: Rollback to any save point
1) CREATE A TABLE
create table employeepersonaldetails(id int primary key,name varchar(30) not null,age int not
null,mobilenumber int not null unique);
insert into employeepersonaldetails values(1,'Ajay',20,9876543210);
insert into employeepersonaldetails values(2,'Brindha',20,9874563210);
insert into employeepersonaldetails values(3,'Kumaran',20,9673443210);
select * from employeepersonaldetails;
commit;
Statement executed
insert into employeepersonaldetails values(4,'Archana',20,9876543410);
rollback;
insert into employeepersonaldetails values(5,'Braham',20,9878953210);
savepoint a;
savepoint created
insert into employeepersonaldetails values(6,'Srimathi',20,9678953210);
savepoint b;
rollback to a;
RESULT:
Thus Transaction Control and Data Control statements using structured Query Language is
executed successfully
EXPERIMENT – 7
VIVA QUESTIONS
1. What is a transaction in a database?
A transaction is a sequence of one or more SQL statements that are executed as a
single unit of work, ensuring that either all the statements are executed successfully,
or none of them are.
2. Explain the concept of a save point.
A save point is a point within a transaction to which you can roll back. It allows for
partial rollback of a transaction in case of errors without rolling back the entire
transaction.
3. Why is it important to use transaction control statements?
Transaction control statements ensure the consistency and integrity of the database
by allowing changes to be either fully applied or fully undone. They help maintain
the reliability of the data.
4. What is the purpose of the GRANT statement?
The GRANT statement is used to give specific privileges to a user or a role,
allowing them to perform certain actions on database objects like tables, views, or
procedures.
5. Explain the concept of database privileges.
Database privileges define the actions that a user or role is allowed to perform on a
specific database object. Examples include SELECT, INSERT, UPDATE,
DELETE, and EXECUTE privileges.
6. How is the REVOKE statement used?
The REVOKE statement is used to revoke previously granted privileges from a user
or role, restricting their access to specific database objects.
7. What is the purpose of the DENY statement?
The DENY statement is used to explicitly deny a user or role specific privileges on
a database object. It takes precedence over any previously granted privileges
8. How do data control statements contribute to database security?
Data control statements help manage access to database objects, ensuring that users
have appropriate permissions to perform necessary actions while restricting
unauthorized access. This contributes to the security and integrity of the database.
9. Examples of DCL?
GRANT: This command gives users access privileges to the database.
REVOKE: This command withdraws the user's access privileges given by using
the GRANT command.
COMMIT: Commits a Transaction.
10. What is the difference between DCL & TCL?
By using DDL commands, database transaction cannot be handled. TCL commands
are meant to handle database transaction
EX.NO:8 TRIGGERS
DATE:
AIM:
To implement PL/SQL triggers and do the operations in database automatically.
ALGORITHM:
STEP1: Create a table emply101
STEP2: Insert values into the table
STEP3: Create another table emply102
STEP4: Create trigger
CREATE OR REPLACE TRIGGER <TRIGGER NAME>
{BEFORE/AFTER/INSTEAD OF}
{INSERT/UPDATE/DELETE}
ON <TABLENAME/VIEWNAME>
REFRENCECING {OLD AS OLD /NEW AS NEW}
[FOR EACH STATEMENT /FOR EACH ROW [WHEN <CONDITION>]]
STEP5: Insert and delete record into emply101
STEP6: View the updations in emply102
CREATE TABLE emply101
create table emply101(eid varchar(20),ename char(25), age number(10), salary number(10));
insert into emply101 values(1,'abi',23,25000);
insert into emply101 values(2,'abinaya',22,20000);
insert into emply101 values(3,'abishek',23,25000);
select * from emply101;
CREATE TABLE emply102
create table emply102(eid varchar(20),ename char(25),age number(10),salary number(10));
select * from emply102;
no data found
Creating trigger
create or replace trigger tfg1 before insert on emply101 for each row
begin
insert into emply102 values(:new.eid,:new.ename,:new.age,:new.salary);
end;
Insert values into emply101
insert into emply101 values(4,'bala',23,25000);
select * from emply101;
select * from emply102;
CREATING TRIGGER FOR UPDATING AND DELETING
create or replace trigger trgrr15 after delete or update on emply101 for each row
begin
if deleting then
insert into emply102 values(:old.eid,:old.ename,:old.age,:old.salary);
elsif updating then
insert into emply102 values(:old.eid,:old.ename,:old.age,:old.salary);
end if;
end;
Update a value in emply101
update emply101 set salary=10000 where eid=1;
select * from emply102;
RESULT:
Thus the SQL triggers are executed successfully.
EXPERIMENT – 8
VIVA QUESTIONS
1. What is a database trigger?
A database trigger is a set of instructions or code that is automatically executed
("triggered") in response to a specific event, such as an INSERT, UPDATE,
DELETE, or another action, occurring in a database.
2. What are the types of triggers commonly used in databases?
The two main types of triggers are BEFORE triggers, which are executed before
the triggering event, and AFTER triggers, which are executed after the triggering
event.
3. How does a BEFORE INSERT trigger differ from an AFTER INSERT trigger?
A BEFORE INSERT trigger is executed before the actual insertion of data into the
table, allowing for validation or modification of data. An trigger is executed after
the data has been inserted, and it can perform actions based on the successful
insertion.
4. What is the purpose of using triggers in a database?
Triggers are used to enforce business rules, ensure data integrity, and automate
actions in response to specific events, reducing the need for manual intervention
and enhancing the consistency of the database.
5. Can a trigger be associated with more than one event?
Yes, a trigger can be associated with multiple events. For example, a trigger can be
designed to execute on both
BEFORE INSERT and BEFORE UPDATE events.
6. How do you create a trigger in a database?
To create a trigger, you use the CREATE TRIGGER statement, specifying the
trigger name, timing (BEFORE or AFTER), event (INSERT, UPDATE, DELETE),
and the SQL statements or procedures to be executed.
7. Explain the concept of a FOR EACH ROW trigger.
A FOR EACH ROW trigger is a type of trigger that is executed once for each row
affected by the triggering event. It is commonly used with row-level actions, such
as validating or modifying data on a per-row basis.
8. How do you disable or drop a trigger?
You can disable a trigger using the
TRIGGER. To drop a trigger, you use the
9. Can triggers cause performance issues in a database?
statement and re-enable it using statement.
Poorly designed triggers or triggers with complex logic can potentially cause
performance issues. It's essential to carefully design triggers to ensure they do not
adversely impact database performance
10. Provide an example scenario where a trigger might be useful.
A trigger could be useful in enforcing a rule that prevents the deletion of records
from a critical table, ensuring that a record can only be marked as inactive
(UPDATE instead of DELETE).
EX.NO:9 VIEWS AND INDEX
DATE:
AIM:
To write a DDL command to create views to restrict data access from one or more tables,execute
it and verify the same.
Creating views:
1. Create a view that contains employee id as “ID_NUMBER”, employee name
as “NAME”and salary as ”SALARY” for each employee in department 90.
SQL> create view vw_emp80(id,name,salary) as select empid,name,salary from
employee wheredeptid=90;
OUTPUT:
View created.
SQL> select * from vw_emp80;
ID NAME SALARY
s203 vidhya 29000
2. To create a view to set the salary Rs.15000/- to the employee id ‘a102’ in the
vw_dept_salary and verify the result in vw_emp12_sal and employees table.
SQL> update vw_emp12 set salary=15000 where
empid='a102';1 row updated.
To Verify: SQL> select * from vw_emp12;
SNO NAME SALARY DESIG LAST EMPID DEPTID HIRE_DATE
1 monica 15000 rep a a102 102 13-MAR-08
Creating Index
Create table
CREATE TABLE Colleges ( college_id INT PRIMARY KEY,college_code
VARCHAR(20),NOT NULL college_name VARCHAR(50)
);
create index
CREATE INDEX college_index ON Colleges(college_code);
Colleges
RESULT:
Thus the PL/SQL program for implementing views and index has been successfully executed.
college_id college_code college_name
empty
EXPERIMENT – 9
VIVA QUESTIONS
1. What is an index in a database?
An index is a data structure that improves the speed of data retrieval operations on
a database table. It is created on one or more columns of a table to quickly locate
and access rows based on the indexed columns.
2. Why are indexes used, and what benefits do they provide?
indexes are used to improve the speed of data retrieval operations by facilitating
quicker access to rows. They enhance query performance, especially for SELECT
statements, by minimizing the number of rows that need to be scanned.
3. What is the trade-off associated with using indexes?
While indexes improve query performance, they come with the trade-off of
increased storage space and potential overhead during data modification
operations (INSERT, UPDATE, DELETE), as the indexes also need to be
maintained.
4. Can you create an index on multiple columns?
Yes, a composite index, or multi-column index, can be created on multiple
columns. This type of index is useful when queries involve conditions on multiple
columns.
5. How does an index impact the performance of SELECT queries?
Indexes can significantly improve the performance of SELECT queries by
allowing the database engine to quickly locate and retrieve the relevant rows,
reducing the need for full table scans.
6. When would you consider not using an index?
Indexes may not be necessary for small tables or tables with infrequent queries. In
situations where data modifications (INSERT, UPDATE, DELETE) significantly
outweigh read operations, the overhead of maintaining indexes may outweigh the
benefits.
7. Explain the concept of a clustered index.
A clustered index determines the physical order of data in a table. The rows in the
table are stored on disk in the same order as the index, making it different from a
non-clustered index where the order on disk does not match the index order.
8. What is meant by trigger?
Trigger is one of the very important codes or programs which get executed
automatically in response to the events that occur in a table or a view.
9. What are the operations performed in trigger?
10. Syntax for trigger?
CREATE TRIGGER schema.trigger_name
ON table_name
AFTER {INSERT, UPDATE, DELETE}
[NOT FOR REPLICATION]
AS
{SQL_Statements}
EX.NO:10 XML SCHEMA
DATE:
AIM:
To implement XML Database and validate it using XML Schema.
PROGRAM
CREATE TABLE t1 (
id NUMBER,
xml XMLTYPE
);
INSERT INTO t1 VALUES (1, '<?xml version="1.0" encoding="UTF-8"?>
<shiporder orderid="889923">
<orderperson>John Smith</orderperson>
<shipto>
<name>Ola Nordmann</name>
<address>Langgt 23</address>
<city>4000 Stavanger</city>
<country>Norway</country>
</shipto>
<item>
<title>Empire Burlesque</title>
<note>Special Edition</note>
<quantity>1</quantity>
<price>10.90</price>
</item>
<item>
<title>Hide your heart</title>
<quantity>1</quantity>
<price>9.90</price>
</item>
</shiporder>');
INSERT INTO t1 VALUES (2, '<?xml version="1.0" encoding="UTF-8"?>
<shiporder orderid="889923">
<orderperson>John Smith</orderperson>
<shipto>
<name1>Ola Nordmann</name1>
<address>Langgt 23</address>
<city>4000 Stavanger</city>
<country>Norway</country>
</shipto>
<item>
<title>Empire Burlesque</title>
<note>Special Edition</note>
<quantity>1</quantity>
<price>10.90</price>
</item>
<item>
<title>Hide your heart</title>
<quantity>1</quantity>
<price>9.90</price>
</item>
</shiporder>');
COMMIT;
OUTPUT
SELECT id,
XMLISVALID(xml, 'my_schema.xsd') AS is_valid
FROM t1;
ID IS_VALID
------- ----------
1 1
2 0
RESULT:
Thus the XML Database and validate it using XML Schema is executed successfully.
EXPERIMENT – 10
VIVA QUESTIONS
1. What is an XML Schema?
An XML Schema is a way to describe the structure and constraints of XML
documents. It defines the elements, attributes, data types, and the relationships
between them in an XML document.
2. Why is XML Schema important in the context of XML documents?
XML Schema provides a standardized way to define the structure and data types of
XML documents, ensuring consistency and facilitating interoperability between
systems that exchange XML data.
3. What are the key components of an XML Schema?
The key components of an XML Schema include elements, attributes, data types,
complex types, simple types, and the relationships between them.
4. Explain the difference between a complex type and a simple type in XML Schema.
A complex type can contain other elements and attributes, allowing for a more
complex structure. A simple type, on the other hand, represents atomic data types
like strings, numbers, or dates without containing other elements.
5. How do you define an element in an XML Schema?
Elements are defined using the <element> tag in an XML Schema. You specify the
name, type, and any constraints for the element within this tag.
6. What is the purpose of the XML Schema complexType element?
The complexType element is used to define complex types, which can contain other
elements and attributes. It allows for the creation of more structured and hierarchical
data models.
7. How can you restrict the values of an element using XML Schema?
You can use the restriction element to restrict the values of an element based on a
specific data type, such as restricting a string to a certain length or restricting a
number to a specific range.
8. Explain the concept of XML Schema namespaces.
XML Schema namespaces are used to avoid naming conflicts between elements
and types. They allow different XML vocabularies or applications to define
elements and types with the same name without colliding.
9. What is the purpose of the include and import statements in XML Schema?
The include statement is used to include components from another schema file,
while the import statement is used to import components from another schema
namespace.
10. How does XML Schema contribute to data validation in XML documents?
XML Schema provides a set of rules and constraints that define the structure and
data types of XML documents. During document validation, the XML processor
checks whether the document conforms to the specified schema.
EX.NO:11 NOSQL DATABASE TOOLS
DATE
Aim:
To design and develop MongoDB queries using CRUD operations.
Algorithm:
Step 1: Create table by using create table command.
Step 2: Insert values into the table
Step 3: Delete any records from the table
Step 4: Update any values in the table.
Step 5: Display the values from the table by using select command.
Step 6: Search any value using find.
Query:
> db.createCollection('Student');
{ "ok" : 1 }
> db.Student.insert({'Rno':'1','Name':'Piyush','Class':'TE COMP'});
WriteResult({ "nInserted" : 1 })
> db.Student.insert({'Rno':'2','Name':'Abhi','Class':'TE COMP'});
WriteResult({ "nInserted" : 1 })
> db.Student.insert({'Rno':'3','Name':'Ashley','Class':'TE
COMP'});WriteResult({ "nInserted" : 1 })
> db.Student.insert({'Rno':'4','Name':'Hitesh','Class':'TE COMP'});
WriteResult({ "nInserted" : 1 })
> db.Student.insert({'Rno':'5','Name':'Pratik','Class':'TE COMP'});
WriteResult({ "nInserted" : 1 })
> db.Student.insert({'Rno':'6','Name':'Pratik','Class':'TE COMP'});
WriteResult({ "nInserted" : 1 })
> db.Student.find();
{ "_id" : ObjectId("5b8fad4ef00832a0a50b5036"), "Rno" : "1",
"Name" : "Piyush", "Class" : "TE COMP" }
{ "_id" : ObjectId("5b8fad62f00832a0a50b5037"), "Rno" : "2",
"Name" : "Abhi", "Class" : "TE COMP" }
{ "_id" : ObjectId("5b8fad70f00832a0a50b5038"), "Rno" : "3",
"Name" : "Ashley", "Class" : "TE COMP" }
{ "_id" : ObjectId("5b8fad7ff00832a0a50b5039"), "Rno" : "4",
"Name" : "Hitesh", "Class" : "TE COMP" }
{ "_id" : ObjectId("5b8fad8df00832a0a50b503a"), "Rno" : "5",
"Name" : "Pratik", "Class" : "TE COMP" }
{ "_id" : ObjectId("5b8fada4f00832a0a50b503b"), "Rno" : "6",
"Name" : "Pratik", "Class" : "TE COMP" }
> db.Student.find().pretty();
{
"_id" : ObjectId("5b8fad4ef00832a0a50b5036"),
"Rno" : "1",
"Name" : "Piyush",
"Class" : "TE COMP"
}
{
"_id" : ObjectId("5b8fad62f00832a0a50b5037"),
"Rno" : "2",
"Name" : "Abhi",
"Class" : "TE COMP"}
{
"_id" : ObjectId("5b8fad70f00832a0a50b5038"),
"Rno" : "3",
"Name" : "Ashley",
"Class" : "TE COMP"
}
{
"_id" : ObjectId("5b8fad7ff00832a0a50b5039"),
"Rno" : "4",
"Name" : "Hitesh",
"Class" : "TE COMP"
}
{
"_id" : ObjectId("5b8fad8df00832a0a50b503a"),
"Rno" : "5",
"Name" : "Pratik",
"Class" : "TE COMP"
}
{
"_id" : ObjectId("5b8fada4f00832a0a50b503b"),
"Rno" : "6",
"Name" : "Pratik",
"Class" : "TE COMP"
}
> show dbs;
Abhi 0.078GB
admin (empty)
local 0.078GB
> db.Student.update({'Name':'Hitesh'},{$set:
{'Name':'Henry'}});WriteResult({ "nMatched" : 1, "nUpserted" : 0,
"nModified" : 1
})
> db.Student.find().pretty();
{
"_id" : ObjectId("5b8fad4ef00832a0a50b5036"),
"Rno" : "1",
"Name" : "Piyush",
"Class" : "TE COMP"
}
{
"_id" : ObjectId("5b8fad62f00832a0a50b5037"),
"Rno" : "2",
"Name" : "Abhi",
"Class" : "TE COMP"
}
{
"_id" : ObjectId("5b8fad70f00832a0a50b5038"),
"Rno" : "3",
"Name" : "Ashley",
"Class" : "TE COMP"
}
{
"_id" : ObjectId("5b8fad7ff00832a0a50b5039"),
"Rno" : "4",
"Name" : "Henry",
"Class" : "TE COMP"
}
{
"_id" : ObjectId("5b8fad8df00832a0a50b503a"),
"Rno" : "5",
"Name" : "Pratik",
"Class" : "TE COMP"}
{
"_id" : ObjectId("5b8fada4f00832a0a50b503b"),
"Rno" : "6",
"Name" : "Pratik",
"Class" : "TE COMP"
}
> db.Student.remove({'ADD':'MP'});
WriteResult({ "nRemoved" : 1 })
> db.Student.find().pretty();
{
"_id" : ObjectId("5b8fad62f00832a0a50b5037"),
"Rno" : "2",
"Name" : "Abhi",
"Class" : "TE COMP"
}
{
"_id" : ObjectId("5b8fad70f00832a0a50b5038"),
"Rno" : "3",
"Name" : "Ashley",
"Class" : "TE COMP"
}
{
"_id" : ObjectId("5b8fad7ff00832a0a50b5039"),
"Rno" : "4",
"Name" : "Henry",
"Class" : "TE COMP"
}
{
"_id" : ObjectId("5b8fad8df00832a0a50b503a"),
"Rno" : "5",
"Name" : "Pratik","Class" : "TE COMP"
}
{
"_id" : ObjectId("5b8fada4f00832a0a50b503b"),
"Rno" : "6",
"Name" : "Pratik",
"Class" : "TE COMP"
}
> db.Student.remove({'Name':'Pratik'},1);
WriteResult({ "nRemoved" : 1 })
> db.Student.remove({'Name':'Pratik'},1);
WriteResult({ "nRemoved" : 1 })
> db.Student.find().pretty();
{
"_id" : ObjectId("5b8fad62f00832a0a50b5037"),
"Rno" : "2",
"Name" : "Abhi",
"Class" : "TE COMP"
}
{
"_id" : ObjectId("5b8fad70f00832a0a50b5038"),
"Rno" : "3",
"Name" : "Ashley",
"Class" : "TE COMP"
}
{
"_id" : ObjectId("5b8fad7ff00832a0a50b5039"),
"Rno" : "4",
"Name" : "Henry",
"Class" : "TE COMP"
}
> db.Student.drop();true
> db.Student.find().pretty()
{ "ok" : 1 }
> db.Student.insert({'Rno':'1','Name':'Piyush','Class':'TE COMP'});
WriteResult({ "nInserted" : 1 })
> db.Student.insert({'Rno':'2','Name':'Abhi','Class':'TE COMP'});
WriteResult({ "nInserted" : 1 })
>db.Student.insert({'Rno':'3','Name':'Ashley','Class':'TE COMP'});
WriteResult({ "nInserted" : 1 })
> db.Student.insert({'Rno':'4','Name':'Hitesh','Class':'TE COMP'});
WriteResult({ "nInserted" : 1 })
> db.Student.insert({'Rno':'5','Name':'Pratik','Class':'TE COMP'});
WriteResult({ "nInserted" : 1 })
> db.Student.insert({'Rno':'6','Name':'Pratik','Class':'TE COMP'});
WriteResult({ "nInserted" : 1 })
> db.Student.find();
{ "_id" : ObjectId("5ba1d618f5bbacd4ad81568d"), "Rno" : "1",
"Name" : "Piyush", "Class" : "TE COMP" }
{ "_id" : ObjectId("5ba1d625f5bbacd4ad81568e"), "Rno" : "2",
"Name" : "Abhi", "Class" : "TE COMP" }
{ "_id" : ObjectId("5ba1d63af5bbacd4ad81568f"), "Rno" : "3",
"Name" : "Ashley", "Class" : "TE COMP" }
{ "_id" : ObjectId("5ba1d647f5bbacd4ad815690"), "Rno" : "4",
"Name" : "Hitesh", "Class" : "TE COMP" }
{ "_id" : ObjectId("5ba1d65ef5bbacd4ad815691"), "Rno" : "5",
"Name" : "Pratik", "Class" : "TE COMP" }
{ "_id" : ObjectId("5ba1d66df5bbacd4ad815692"), "Rno" : "6",
"Name" : "Pratik", "Class" : "TE COMP" }
> db.Student.find().pretty();
{
"_id" : ObjectId("5ba1d618f5bbacd4ad81568d"),
"Rno" : "1",
"Name" : "Piyush",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d625f5bbacd4ad81568e"),
"Rno" : "2","Name" : "Abhi",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d63af5bbacd4ad81568f"),
"Rno" : "3",
"Name" : "Ashley",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d647f5bbacd4ad815690"),
"Rno" : "4",
"Name" : "Hitesh",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d65ef5bbacd4ad815691"),
"Rno" : "5",
"Name" : "Pratik",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d66df5bbacd4ad815692"),
"Rno" : "6",
"Name" : "Pratik",
"Class" : "TE COMP"
}
> db.Student.update({'Name':'Hitesh'},{$set: {'Name':'Henry'}});
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1})
> db.Student.find().pretty();
{
"_id" : ObjectId("5b8fad4ef00832a0a50b5036"),
"Rno" : "1",
"Name" : "Piyush",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5b8fad62f00832a0a50b5037"),
"Rno" : "2",
"Name" : "Abhi",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5b8fad70f00832a0a50b5038"),
"Rno" : "3",
"Name" : "Ashley",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5b8fad7ff00832a0a50b5039"),
"Rno" : "4",
"Name" : "Henry",
"Class" : "TE COMP"
}{ "_id" :
ObjectId("5b8fad8df00832a0a50b503a"),
"Rno" : "5",
"Name" : "Pratik",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5b8fada4f00832a0a50b503b"),"Rno" : "6",
"Name" : "Pratik",
"Class" : "TE COMP"
}
> db.Student.remove({'ADD':'MP'});
WriteResult({ "nRemoved" : 1 })
> db.Student.find().pretty();
{
"_id" : ObjectId("5b8fad62f00832a0a50b5037"),
"Rno" : "2",
"Name" : "Abhi",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5b8fad70f00832a0a50b5038"),
"Rno" : "3",
"Name" : "Ashley",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5b8fad7ff00832a0a50b5039"),
"Rno" : "4",
"Name" : "Henry",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5b8fad8df00832a0a50b503a"),
"Rno" : "5",
"Name" : "Pratik",
"Class" : "TE COMP"
} {"_id" :
ObjectId("5b8fada4f00832a0a50b503b"),
"Rno" : "6",
"Name" : "Pratik",
"Class" : "TE COMP"
}
>db.Student.save({_id:ObjectId("5b8fad4ef00832a0a50b5036"),"RNO
":"1","NAME":"PIYUSH","CLASS":"TE COMP","ADD":"MP"});
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1})
> db.Student.find().pretty();
{
"_id" : ObjectId("5b8fad4ef00832a0a50b5036"),
"RNO" : "1",
"NAME" : "PIYUSH",
"CLASS" : "TE COMP",
"ADD" : "MP"
}{
"_id" : ObjectId("5b8fad62f00832a0a50b5037"),
"Rno" : "2",
"Name" : "Abhi",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5b8fad70f00832a0a50b5038"),
"Rno" : "3",
"Name" : "Ashley",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5b8fad7ff00832a0a50b5039"),
"Rno" : "4","Name" : "Henry",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5b8fad8df00832a0a50b503a"),
"Rno" : "5",
"Name" : "Pratik",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5b8fada4f00832a0a50b503b"),
"Rno" : "6",
"Name" : "Pratik",
"Class" : "TE COMP"
}
> db.Student.find({$and:[{"Name":"Piyush"},{"Rno":"2"}]});
> db.Student.find({$and:[{"Name":"Piyush"},
{"Rno":"1"}]}).pretty();
{
"_id" : ObjectId("5ba1d618f5bbacd4ad81568d"),
"Rno" : "1",
"Name" : "Piyush",
"Class" : "TE COMP"
}
> db.Student.find({$and:[{"Name":"Piyush"},{"Rno":"2"}]}).pretty();
> db.Student.find({$or:[{"Name":"Piyush"},{"Rno":"2"}]}).pretty();
{
"_id" : ObjectId("5ba1d618f5bbacd4ad81568d"),
"Rno" : "1",
"Name" : "Piyush","Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d625f5bbacd4ad81568e"),
"Rno" : "2",
"Name" : "Abhi",
"Class" : "TE COMP"
}
> db.Student.find({$or:[{"Name":"Piyush"},{"Class":"TE
COMP"}]}).pretty();
{
"_id" : ObjectId("5ba1d618f5bbacd4ad81568d"),
"Rno" : "1",
"Name" : "Piyush",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d625f5bbacd4ad81568e"),
"Rno" : "2",
"Name" : "Abhi",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d63af5bbacd4ad81568f"),
"Rno" : "3",
"Name" : "Ashley",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d647f5bbacd4ad815690"),
"Rno" : "4",
"Name" : "Hitesh","Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d65ef5bbacd4ad815691"),
"Rno" : "5",
"Name" : "Pratik",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d66df5bbacd4ad815692"),
"Rno" : "6",
"Name" : "Pratik",
"Class" : "TE COMP"
}
> db.Student.find({$nor:[{"Name":"Piyush"},{"Class":"TE
COMP"}]}).pretty();
> db.Student.find({$nor:[{"Name":"Piyush"},
{"Rno":"2"}]}).pretty();
{
"_id" : ObjectId("5ba1d63af5bbacd4ad81568f"),
"Rno" : "3",
"Name" : "Ashley",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d647f5bbacd4ad815690"),
"Rno" : "4",
"Name" : "Hitesh",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d65ef5bbacd4ad815691"),"Rno" : "5",
"Name" : "Pratik",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d66df5bbacd4ad815692"),
"Rno" : "6",
"Name" : "Pratik",
"Class" : "TE COMP"
}
db.Student.find( {"Rno": { $not:{$lt:"3"}}}).pretty();
{
"_id" : ObjectId("5ba1d63af5bbacd4ad81568f"),
"Rno" : "3",
"Name" : "Ashley",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d647f5bbacd4ad815690"),
"Rno" : "4",
"Name" : "Hitesh",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d65ef5bbacd4ad815691"),
"Rno" : "5",
"Name" : "Pratik",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d66df5bbacd4ad815692"),
"Rno" : "6","Name" : "Pratik",
"Class" : "TE COMP"
}
> db.Student.find( {"Rno": { $eq:"5"}}).pretty();
{
"_id" : ObjectId("5ba1d65ef5bbacd4ad815691"),
"Rno" : "5",
"Name" : "Pratik",
"Class" : "TE COMP"
}
> db.Student.find( {"Rno": { $ne:"5"}}).pretty();
{
"_id" : ObjectId("5ba1d618f5bbacd4ad81568d"),
"Rno" : "1",
"Name" : "Piyush",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d625f5bbacd4ad81568e"),
"Rno" : "2",
"Name" : "Abhi",
"Class" : "TE COMP"
}{ "_id" :
ObjectId("5ba1d63af5bbacd4ad81568f"),
"Rno" : "3",
"Name" : "Ashley",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d647f5bbacd4ad815690"),
"Rno" : "4","Name" : "Hitesh",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d66df5bbacd4ad815692"),
"Rno" : "6",
"Name" : "Pratik",
"Class" : "TE COMP"
}
> db.Student.find( {"Rno": { $gt:"5"}}).pretty();
{
"_id" : ObjectId("5ba1d66df5bbacd4ad815692"),
"Rno" : "6",
"Name" : "Pratik",
"Class" : "TE COMP"
}
> db.Student.find( {"Rno": { $gte:"5"}}).pretty();
{
"_id" : ObjectId("5ba1d65ef5bbacd4ad815691"),
"Rno" : "5",
"Name" : "Pratik",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d66df5bbacd4ad815692"),
"Rno" : "6",
"Name" : "Pratik",
"Class" : "TE COMP"
}
> db.Student.find( {"Rno": { $lt:"5"}}).pretty();
{
"_id" : ObjectId("5ba1d618f5bbacd4ad81568d"),"Rno" : "1",
"Name" : "Piyush",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d625f5bbacd4ad81568e"),
"Rno" : "2",
"Name" : "Abhi",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d63af5bbacd4ad81568f"),
"Rno" : "3",
"Name" : "Ashley",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d647f5bbacd4ad815690"),
"Rno" : "4",
"Name" : "Hitesh",
"Class" : "TE COMP"
}
> db.Student.find( {"Rno": { $lte:"5"}}).pretty();
{
"_id" : ObjectId("5ba1d618f5bbacd4ad81568d"),
"Rno" : "1",
"Name" : "Piyush",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d625f5bbacd4ad81568e"),
"Rno" : "2","Name" : "Abhi",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d63af5bbacd4ad81568f"),
"Rno" : "3",
"Name" : "Ashley",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d647f5bbacd4ad815690"),
"Rno" : "4",
"Name" : "Hitesh",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d65ef5bbacd4ad815691"),
"Rno" : "5",
"Name" : "Pratik",
"Class" : "TE COMP"
}
> db.Student.find( {"Rno": { $lt:"5",$gt:"2"}}).pretty();
{
"_id" : ObjectId("5ba1d63af5bbacd4ad81568f"),
"Rno" : "3",
"Name" : "Ashley",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d647f5bbacd4ad815690"),
"Rno" : "4",
"Name" : "Hitesh","Class" : "TE COMP"
}
> db.Student.find( {"Rno": { $lte:"5",$gte:"2"}}).pretty();
{
"_id" : ObjectId("5ba1d625f5bbacd4ad81568e"),
"Rno" : "2",
"Name" : "Abhi",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d63af5bbacd4ad81568f"),
"Rno" : "3",
"Name" : "Ashley",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d647f5bbacd4ad815690"),
"Rno" : "4",
"Name" : "Hitesh",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d65ef5bbacd4ad815691"),
"Rno" : "5",
"Name" : "Pratik",
"Class" : "TE COMP"
}
> db.Student.find( {"Rno": { $lte:"5",$gt:"2"}}).pretty();
{
"_id" : ObjectId("5ba1d63af5bbacd4ad81568f"),
"Rno" : "3",
"Name" : "Ashley","Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d647f5bbacd4ad815690"),
"Rno" : "4",
"Name" : "Hitesh",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d65ef5bbacd4ad815691"),
"Rno" : "5",
"Name" : "Pratik",
"Class" : "TE COMP"
}
> db.Student.find( {"Rno": { $lt:"5",$gte:"2"}}).pretty();
{
"_id" : ObjectId("5ba1d625f5bbacd4ad81568e"),
"Rno" : "2",
"Name" : "Abhi",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d63af5bbacd4ad81568f"),
"Rno" : "3",
"Name" : "Ashley",
"Class" : "TE COMP"
}{
"_id" : ObjectId("5ba1d647f5bbacd4ad815690"),
"Rno" : "4",
"Name" : "Hitesh",
"Class" : "TE COMP"}
RESULT
Thus the CRUD operation in NoSQL database MongoDB has been successfully executed.
EXPERIMENT – 11
VIVA QUESTIONS
1. What is a NoSQL database, and how does it differ from traditional relational databases?
NoSQL databases are non-relational databases designed to handle large volumes of
unstructured or semi- structured data. They differ from traditional relational databases
by not using a fixed schema and offering flexible data models.
2. How do NoSQL databases handle date and time data?
NoSQL databases typically store date and time data in various formats, such as ISO
8601, Unix timestamps, or as native date types. The specific approach depends on the
database type and the data model it supports.
3. Give an example of a NoSQL database that excels in handling time-series data.
One example is InfluxDB, which is known for its efficient handling of time-series data,
making it suitable for applications involving metrics, monitoring, and IoT data.
4. Explain how MongoDB represents date and time data.
MongoDB represents date and time data using the BSON data type called ISODate. It
stores date and time in UTC format and allows for querying and indexing based on
time.
5. What is Apache Cassandra, and how does it handle date-related data?
Apache Cassandra is a distributed NoSQL database. It typically stores date and time
data as timestamps in microseconds or milliseconds, depending on the configuration. It
provides flexibility in handling time-related data.
6. How does CouchDB handle date and time information?
CouchDB stores date and time information as strings in JSON documents. It is left to
the application to choose the appropriate date format, allowing flexibility in
representing time.
7. In a time-series database like OpenTSDB, how is time represented?
OpenTSDB represents time as Unix timestamps (in seconds or milliseconds), providing
a convenient way to work with time-series data and allowing for efficient storage and
retrieval.
8. Can you explain how a graph database like Neo4j deals with date information?
Neo4j does not have a native date data type, but dates can be stored as properties with
appropriate formats ( e.g., strings or numeric representations). Date-related queries can
then be executed using the Cypher query language.
9. How do NoSQL databases handle the indexing of date fields?
NoSQL databases often provide indexing mechanisms for date fields to optimize query
performance. Indexing can be based on specific date attributes or the entire timestamp,
depending on the database.
10. Discuss the challenges and advantages of handling date and time data in NoSQL
databases.
Challenges may include consistency across distributed systems, while advantages
include flexibility in data models, scalability, and efficient handling of time-series data.
EX.NO:12 GUI BASED DATABASE APPLICATIONS
DATE:
AIM:
To implement an online exam registration page with database connectivity using php
ALGORITHM:
STEP 1: Develop a webpage which includes all the fields for registering for an online exam
STEP 2: Develop a PHP page which receives the values that are given as an input in the registration page
STEP 3: Connect the registration page with the PHP page
STEP 4: Receive the values from registration page
STEP 5: Establish a connection with the database
STEP 6: Store the received values in the database
PROGRAM:
Registration.html
<html>
<body bgcolor="lightblue">
<p><center>REGISTRATION FORM</center></p>
<form action="Registration.php" method="post">
<center><pre><b> Student name: <input type="text" name="n" value=" ">
Register Number: <input type="text" name="reg" value=" ">
CGPA: <input type="text" name="cgpa" value=" ">
YEAR: <input type="text" name="y" value=" ">
Branch: <input type="text" name="branch" value=" ">
<input type="submit" name="button" value="SUBMIT">
</b></center></pre>
</body>
</html>
Registration.php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "Online_exam";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
/*else
echo "Connection established";*/
$Name=$_POST['n'];
$RegNo=$_POST['reg'];
$CGPA=$_POST['cgpa'];
$Year=$_POST['y'];
$Branch=$_POST['branch'];
/*echo $Name;
echo $RegNo;
echo $CGPA;
echo $Year;
echo $Branch;*/
$sql = "CREATE TABLE regDetails(Name varchar(30) not null, RegNo int(15) not null,CGPA float
not null, Year varchar(5) not null, Branch varchar(5) not null)";
if ($conn->query($sql) === TRUE)
{
echo "Table regDetails created successfully";
}
else
{
echo "Error creating table: " . $conn->error;
}
$sql = "INSERT INTO regDetails (Name,RegNo,CGPA,Year,Branch)
VALUES ('$Name',$RegNo,$CGPA,'$Year','$Branch')";
if ($conn->query($sql) === TRUE)
{
echo "New record created successfully";
}
else
{
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
RESULT:
Thus the real life database application for exam registration has been successfully executed.
EXPERIMENT – 12
VIVA QUESTIONS
1. What is a GUI-based database application?
A GUI-based database application is a software application that provides a graphical
user interface (GUI) for users to interact with a database. It allows users to perform
database operations, such as querying, inserting, updating, and deleting records, using
visual elements
2. How does a GUI-based database application differ from a command-line interface
(CLI) application?
A GUI-based application uses graphical elements like buttons, forms, and menus to
interact with the database, providing a more user-friendly and visually intuitive
experience compared to a command-line interface that relies on text commands.
3. What are the advantages of using a GUI for database applications?
GUIs offer advantages such as ease of use, reduced learning curve, visual representation
of data, and the ability to provide feedback to users through interactive elements,
enhancing the overall user experience.
4. Can you name a popular GUI-based database application development tool?
Examples include Microsoft Access, Oracle Forms, and File-Maker Pro.
5. How does a user typically interact with a GUI-based database application?
Users interact with a GUI-based database application by clicking buttons, filling out
forms, selecting options from menus, and manipulating visual elements to perform
various database operations.
6. Explain the concept of data binding in the context of GUI-based database applications.
Data binding is the process of connecting the user interface elements (such as text boxes
or tables) directly to the underlying database, allowing changes in the UI to be reflected
in the database and vice versa.
7. What is the role of forms in GUI-based database applications?
Forms in GUI-based database applications serve as a means for users to input and view
data. They typically consist of fields corresponding to database columns, and users
interact with these forms to perform operations on the data.
8. How can GUI-based applications handle database transactions?
GUI-based applications often provide transaction management features, allowing users
to initiate and commit transactions or roll back changes. This ensures data consistency
and integrity.
9. Discuss the importance of validation in GUI-based database applications.
Validation in GUI-based applications is crucial to ensure that data entered by users
meets specified criteria. This helps maintain data integrity and prevents the insertion of
incorrect or inconsistent information into the database.
10. What is view in sql?
In SQL, a view is a virtual table based on the result-set of an SQL statement. A view
contains rows and columns, just like a real table. The fields in a view are fields from
one or more real tables in the database.
EX.NO:13 DATABASE DESIGN USING ER MODELING, NORMALIZATION AND
DATE : IMPLEMENTATION FOR ANY APPLICATION
AIM:
To implement Database Design using ER modeling, normalization for an application
ALGORITHM:
STEP 1: Create a database schema for an application
STEP 2: Draw an E-R diagram for the schema
STEP 3: Check for atomic values and change it to first normal form
STEP 4: Check for functional dependency and modify the schema to second normal form
STEP 5: Check for transitive dependency and convert to third normal form
STEP 6: Check that every determinant is a candidate key and convert to Boyce Codd normal form
STEP 7: Check for multi-valued dependency and change it to fourth normal form
STEP 8: Check whether the table is fully normalized
First Normal Form:
 It should only have single(atomic) valued attributes/columns.
 Values stored in a column should be of the same domain
 All the columns in a table should have unique names
Changing it to 1NF:
Second Normal Form (2NF)
For a table to be in the Second Normal Form,
1. It should be in the First Normal form.
2. And, it should not have Partial Dependency.
Changing it to 2NF:
Student:
Subject:
Score:
Third Normal Form (3NF)
For a table to be in the third normal form,
1. It should be in the Second Normal form.
2. And it should not have Transitive Dependency.
RESULT:
Thus normalization has been implemented for student database successfully
EXPERIMENT – 13
VIVA QUESTIONS
1. What is ER modeling, and why is it important in database design?
ER modeling is a graphical representation technique used to model the data
requirements and relationships in a system. It's essential in database design to visually
depict entities, their attributes, and the relationships between them.
2. Explain the key components of an ER diagram.
The key components of an ER diagram include entities, attributes, relationships, and
cardinality. Entities represent real-world objects, attributes are properties of entities,
relationships describe associations between entities, and cardinality defines the
numerical relationship between entities in a relationship.
3. How do you represent a one-to-many relationship in an ER diagram?
In an ER diagram, a one-to-many relationship is represented by drawing a line
connecting the entities involved in the relationship and adding a crow's foot notation
on the "many" side.
4. What is the purpose of carnality in an ER diagram?
Carnality in an ER diagram defines the number of instances of one entity that can be
associated with the number of instances of another entity in a relationship. It helps
specify the nature and constraints of the relationship.
5. Can an entity have more than one key attribute?
Yes, an entity can have multiple key attributes, and these are often referred to as
composite keys. Composite keys are useful when a single attribute cannot uniquely
identify an entity.
6. What is the difference between a superkey and a candidate key?
A superkey is a set of one or more attributes that, taken collectively, uniquely
identifies an entity. A candidate key is a minimal superkey, meaning no subset of it
can uniquely identify an entity.
7. How does normalization help in reducing data redundancy?
Normalization reduces data redundancy by organizing data in such a way that each
piece of information is stored in only one place. This eliminates the need to update
multiple copies of the same data, reducing the risk of inconsistencies
8. Explain the concept of transitive dependency.
Transitive dependency occurs when a non-prime attribute is functionally dependent
on another non-prime attribute rather than the primary key. Normalization aims to
eliminate transitive dependencies.
9. What is the role of SQL in database implementation?
SQL (Structured Query Language) is used for implementing, querying, and managing
relational databases. It provides commands for creating tables, defining relationships,
inserting, updating, and retrieving data.
10. How do you create a table in a relational database using SQL?
You create a table in SQL using the CREATE TABLE statement, specifying the table
name and its columns along with their data types and constraints.

More Related Content

Similar to Final DBMS Manual (2).pdf final lab manual

AI_LAB_Manual in c with all the programs
AI_LAB_Manual in c with all the programsAI_LAB_Manual in c with all the programs
AI_LAB_Manual in c with all the programs
drsucharu
 
B tech cse syllabus - MITAOE
B tech cse syllabus - MITAOEB tech cse syllabus - MITAOE
B tech cse syllabus - MITAOE
MITAcademy1
 
Presentation on po pshjhhjhekhhkkhkhjpeo
Presentation on po pshjhhjhekhhkkhkhjpeoPresentation on po pshjhhjhekhhkkhkhjpeo
Presentation on po pshjhhjhekhhkkhkhjpeo
epandhari
 
B tech information technology syllabus - MITAOE
B tech information technology syllabus - MITAOEB tech information technology syllabus - MITAOE
B tech information technology syllabus - MITAOE
MITAcademy1
 
DBMS LAB MANUAL RECORD BOOK TO BE USED BY BTECH STUDENTS
DBMS LAB MANUAL RECORD BOOK TO BE USED BY BTECH STUDENTSDBMS LAB MANUAL RECORD BOOK TO BE USED BY BTECH STUDENTS
DBMS LAB MANUAL RECORD BOOK TO BE USED BY BTECH STUDENTS
meghagarg110
 
IT6511 Networks Laboratory
IT6511 Networks LaboratoryIT6511 Networks Laboratory
IT6511 Networks Laboratory
gayathridevprasad
 
Cs8581 networks lab manual 2017
Cs8581 networks lab manual   2017Cs8581 networks lab manual   2017
Cs8581 networks lab manual 2017
Kayathri Devi D
 
CS8461 Operating System Lab Manual S.Selvi
CS8461 Operating System Lab Manual S.SelviCS8461 Operating System Lab Manual S.Selvi
CS8461 Operating System Lab Manual S.Selvi
SELVI SIVAPERUMAL
 
Digital System Design with FPGAs Lab Manual.pdf
Digital System Design with FPGAs Lab Manual.pdfDigital System Design with FPGAs Lab Manual.pdf
Digital System Design with FPGAs Lab Manual.pdf
AmairullahKhanLodhi1
 
M.Sc.Syllabus 17 Nov 2022 (1).pdf
M.Sc.Syllabus 17 Nov 2022 (1).pdfM.Sc.Syllabus 17 Nov 2022 (1).pdf
M.Sc.Syllabus 17 Nov 2022 (1).pdf
hsingh5201
 
Dsp lab manual
Dsp lab manualDsp lab manual
Dsp lab manual
amanabr
 
Cn lab manual sb 19_scsl56 (1)
Cn lab manual sb 19_scsl56 (1)Cn lab manual sb 19_scsl56 (1)
Cn lab manual sb 19_scsl56 (1)
SRINIVASUNIVERSITYEN
 
SE_Computer_Engg__2019_course_28_06_2021 (6).pdf
SE_Computer_Engg__2019_course_28_06_2021 (6).pdfSE_Computer_Engg__2019_course_28_06_2021 (6).pdf
SE_Computer_Engg__2019_course_28_06_2021 (6).pdf
tomlee12821
 
Te computer-syllabus-2015-course-3-4-17
Te computer-syllabus-2015-course-3-4-17Te computer-syllabus-2015-course-3-4-17
Te computer-syllabus-2015-course-3-4-17
abc19789
 
Data base management system LAB MANUAL KCS 551.pdf
Data base management system LAB MANUAL KCS 551.pdfData base management system LAB MANUAL KCS 551.pdf
Data base management system LAB MANUAL KCS 551.pdf
VandanaTripathi32
 
Ade manual with co po-18scheme
Ade manual with co po-18schemeAde manual with co po-18scheme
Ade manual with co po-18scheme
AMC Engineering College
 
vtu data structures lab manual bcs304 pdf
vtu data structures lab manual bcs304 pdfvtu data structures lab manual bcs304 pdf
vtu data structures lab manual bcs304 pdf
LPSChandana
 
B Tech Civil Engineering Syllabus at MITAOE
B Tech Civil Engineering Syllabus at MITAOEB Tech Civil Engineering Syllabus at MITAOE
B Tech Civil Engineering Syllabus at MITAOE
MITAcademy1
 
IT6611 Mobile Application Development Lab Manual
IT6611 Mobile Application Development Lab ManualIT6611 Mobile Application Development Lab Manual
IT6611 Mobile Application Development Lab Manual
pkaviya
 
Te computer syllabus 2015 course 3-4-17 3-5-17
Te computer syllabus 2015 course 3-4-17 3-5-17Te computer syllabus 2015 course 3-4-17 3-5-17
Te computer syllabus 2015 course 3-4-17 3-5-17
VishalButkar2
 

Similar to Final DBMS Manual (2).pdf final lab manual (20)

AI_LAB_Manual in c with all the programs
AI_LAB_Manual in c with all the programsAI_LAB_Manual in c with all the programs
AI_LAB_Manual in c with all the programs
 
B tech cse syllabus - MITAOE
B tech cse syllabus - MITAOEB tech cse syllabus - MITAOE
B tech cse syllabus - MITAOE
 
Presentation on po pshjhhjhekhhkkhkhjpeo
Presentation on po pshjhhjhekhhkkhkhjpeoPresentation on po pshjhhjhekhhkkhkhjpeo
Presentation on po pshjhhjhekhhkkhkhjpeo
 
B tech information technology syllabus - MITAOE
B tech information technology syllabus - MITAOEB tech information technology syllabus - MITAOE
B tech information technology syllabus - MITAOE
 
DBMS LAB MANUAL RECORD BOOK TO BE USED BY BTECH STUDENTS
DBMS LAB MANUAL RECORD BOOK TO BE USED BY BTECH STUDENTSDBMS LAB MANUAL RECORD BOOK TO BE USED BY BTECH STUDENTS
DBMS LAB MANUAL RECORD BOOK TO BE USED BY BTECH STUDENTS
 
IT6511 Networks Laboratory
IT6511 Networks LaboratoryIT6511 Networks Laboratory
IT6511 Networks Laboratory
 
Cs8581 networks lab manual 2017
Cs8581 networks lab manual   2017Cs8581 networks lab manual   2017
Cs8581 networks lab manual 2017
 
CS8461 Operating System Lab Manual S.Selvi
CS8461 Operating System Lab Manual S.SelviCS8461 Operating System Lab Manual S.Selvi
CS8461 Operating System Lab Manual S.Selvi
 
Digital System Design with FPGAs Lab Manual.pdf
Digital System Design with FPGAs Lab Manual.pdfDigital System Design with FPGAs Lab Manual.pdf
Digital System Design with FPGAs Lab Manual.pdf
 
M.Sc.Syllabus 17 Nov 2022 (1).pdf
M.Sc.Syllabus 17 Nov 2022 (1).pdfM.Sc.Syllabus 17 Nov 2022 (1).pdf
M.Sc.Syllabus 17 Nov 2022 (1).pdf
 
Dsp lab manual
Dsp lab manualDsp lab manual
Dsp lab manual
 
Cn lab manual sb 19_scsl56 (1)
Cn lab manual sb 19_scsl56 (1)Cn lab manual sb 19_scsl56 (1)
Cn lab manual sb 19_scsl56 (1)
 
SE_Computer_Engg__2019_course_28_06_2021 (6).pdf
SE_Computer_Engg__2019_course_28_06_2021 (6).pdfSE_Computer_Engg__2019_course_28_06_2021 (6).pdf
SE_Computer_Engg__2019_course_28_06_2021 (6).pdf
 
Te computer-syllabus-2015-course-3-4-17
Te computer-syllabus-2015-course-3-4-17Te computer-syllabus-2015-course-3-4-17
Te computer-syllabus-2015-course-3-4-17
 
Data base management system LAB MANUAL KCS 551.pdf
Data base management system LAB MANUAL KCS 551.pdfData base management system LAB MANUAL KCS 551.pdf
Data base management system LAB MANUAL KCS 551.pdf
 
Ade manual with co po-18scheme
Ade manual with co po-18schemeAde manual with co po-18scheme
Ade manual with co po-18scheme
 
vtu data structures lab manual bcs304 pdf
vtu data structures lab manual bcs304 pdfvtu data structures lab manual bcs304 pdf
vtu data structures lab manual bcs304 pdf
 
B Tech Civil Engineering Syllabus at MITAOE
B Tech Civil Engineering Syllabus at MITAOEB Tech Civil Engineering Syllabus at MITAOE
B Tech Civil Engineering Syllabus at MITAOE
 
IT6611 Mobile Application Development Lab Manual
IT6611 Mobile Application Development Lab ManualIT6611 Mobile Application Development Lab Manual
IT6611 Mobile Application Development Lab Manual
 
Te computer syllabus 2015 course 3-4-17 3-5-17
Te computer syllabus 2015 course 3-4-17 3-5-17Te computer syllabus 2015 course 3-4-17 3-5-17
Te computer syllabus 2015 course 3-4-17 3-5-17
 

Recently uploaded

Mechatronics material . Mechanical engineering
Mechatronics material . Mechanical engineeringMechatronics material . Mechanical engineering
Mechatronics material . Mechanical engineering
sachin chaurasia
 
CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
PKavitha10
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
ijaia
 
5g-5G SA reg. -standalone-access-registration.pdf
5g-5G SA reg. -standalone-access-registration.pdf5g-5G SA reg. -standalone-access-registration.pdf
5g-5G SA reg. -standalone-access-registration.pdf
devtomar25
 
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
nedcocy
 
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
PriyankaKilaniya
 
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
MadhavJungKarki
 
Pressure Relief valve used in flow line to release the over pressure at our d...
Pressure Relief valve used in flow line to release the over pressure at our d...Pressure Relief valve used in flow line to release the over pressure at our d...
Pressure Relief valve used in flow line to release the over pressure at our d...
cannyengineerings
 
Generative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdfGenerative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdf
mahaffeycheryld
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
uqyfuc
 
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICSUNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
vmspraneeth
 
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
ijseajournal
 
5G Radio Network Througput Problem Analysis HCIA.pdf
5G Radio Network Througput Problem Analysis HCIA.pdf5G Radio Network Througput Problem Analysis HCIA.pdf
5G Radio Network Througput Problem Analysis HCIA.pdf
AlvianRamadhani5
 
Object Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOADObject Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOAD
PreethaV16
 
TIME TABLE MANAGEMENT SYSTEM testing.pptx
TIME TABLE MANAGEMENT SYSTEM testing.pptxTIME TABLE MANAGEMENT SYSTEM testing.pptx
TIME TABLE MANAGEMENT SYSTEM testing.pptx
CVCSOfficial
 
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
upoux
 
Supermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdfSupermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdf
Kamal Acharya
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
Gino153088
 
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
upoux
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
Anant Corporation
 

Recently uploaded (20)

Mechatronics material . Mechanical engineering
Mechatronics material . Mechanical engineeringMechatronics material . Mechanical engineering
Mechatronics material . Mechanical engineering
 
CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
 
5g-5G SA reg. -standalone-access-registration.pdf
5g-5G SA reg. -standalone-access-registration.pdf5g-5G SA reg. -standalone-access-registration.pdf
5g-5G SA reg. -standalone-access-registration.pdf
 
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
 
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
 
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
 
Pressure Relief valve used in flow line to release the over pressure at our d...
Pressure Relief valve used in flow line to release the over pressure at our d...Pressure Relief valve used in flow line to release the over pressure at our d...
Pressure Relief valve used in flow line to release the over pressure at our d...
 
Generative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdfGenerative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdf
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICSUNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
 
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
 
5G Radio Network Througput Problem Analysis HCIA.pdf
5G Radio Network Througput Problem Analysis HCIA.pdf5G Radio Network Througput Problem Analysis HCIA.pdf
5G Radio Network Througput Problem Analysis HCIA.pdf
 
Object Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOADObject Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOAD
 
TIME TABLE MANAGEMENT SYSTEM testing.pptx
TIME TABLE MANAGEMENT SYSTEM testing.pptxTIME TABLE MANAGEMENT SYSTEM testing.pptx
TIME TABLE MANAGEMENT SYSTEM testing.pptx
 
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
 
Supermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdfSupermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdf
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
 
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
 

Final DBMS Manual (2).pdf final lab manual

  • 1. DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS CS3481 - DATABASE MANAGEMENT SYSTEMS LABORATORY FOR IV SEMESTER B.TECH. DEGREE COURSE [REGULATION-2021] As per the prescribed syllabus by ANNA UNIVERSITY CHENNAI – 600025
  • 2. R2021 / CSBS /CS3481 – DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM / 2 DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS LABORATORY MANUAL SUBJECT CODE : CS3481 SUBJECT NAME : DATABASE MANAGEMENT SYSTEMS LABORATORY REGULATION : 2021 ACADEMIC YEAR : 2023-2024 YEAR/SEMESTER : II/IV BATCH : 2022-2026 Prepared by: Name: Date: Verified by: Name: Date: Approved by: Name: Date:
  • 3. R2021 / CSBS /CS3481 – DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM / 3 INSTITUTION VISION Emerge as a premier institute producing globally competent engineers. INSTITUTION MISSION IM1: Achieve academic diligence through effective and innovative teaching – learning processes using ICT tools. IM2: Make students employable through rigorous career guidance and training programs. IM3: Strengthen Industry Institute Interaction through MOUs and collaborations. IM4: Promote Research &amp; Development by inculcating creative thinking through innovative projects incubation.
  • 4. R2021 / CSBS /CS3481 – DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM / 4 DEPARTMENT VISION To create skilled, industry ready professionals in the domain of Computer Science and Business Systems who could make a positive contribution to society through an understanding of information technology. DEPARTMENT MISSION DM 1 : To foster student talent and enable them to compete worldwide through innovative teaching, research, and consultancy. DM 2 : To regulate prospectus to reflect changing industry demands. DM 3 : To instill a variety of skill sets that adhere to industry standards and to uphold moral principles. DM 4 : To develop professional ethics and life skills in individuals which lead them to serve the society.
  • 5. R2021 / CSBS /CS3481 – DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM / 5 PROGRAMME EDUCATIONAL OBJECTIVES (PEOs) PEO1: To guarantee that graduates will be adept in applying the core knowledge of basic sciences, math, computer science, and business systems for the applications pertinent to diverse streams of engineering and technology. PEO2: To enhance graduates fundamental competencies to apply computer science and data analytics tools knowledge to store, retrieve, deploy, and analyse data in the context of corporate enterprise. PEO3: To help graduates enter the workforce, establish themselves as professionals, and satisfy the diverse demands of business, academia, and research by putting their technical expertise and leadership abilities to use. PEO4: To provide graduates with entrepreneurial abilities and traits that will enable them to comprehend how businesses run, recognise business issues, look for business possibilities, and become ready to manage businesses successfully.
  • 6. R2021 / CSBS /CS3481 – DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM / 6 PROGRAM SPECIFIC OUTCOMES (PSOs) PSO1: To develop, pick, and use relevant methods, resources, contemporary engineering tools, and business tools, such as data analytics and prediction, for complicated engineering operations and business solutions and to develop domain-specific approaches for decision-making in a number of important real-world problem domains. PSO2: To be able to use management techniques and entrepreneurial skills to find, evaluate, and create business opportunities with clever business ideas and to manage complex IT projects with an awareness of risk management procedures, operational ramifications, and ethical, financial, and environmental considerations
  • 7. R2021 / CSBS /CS3481 – DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM / 7 PROGRAM OUTCOMES (POs) Engineering Graduates will be able to: PO 1 Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals, and an engineering specialization to the solution of complex engineering problems. PO 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. PO 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 PO 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. PO 5 Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern engineering and IT tools including prediction and modeling to complex engineering activities with an understanding of the limitations. PO 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. PO 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. PO 8 Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of the engineering practice. PO 9 Individual and Team work: Function effectively as an individual, and as a member or leader in diverse teams, and in multidisciplinary settings. PO10 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. PO11 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. PO12 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.
  • 8. R2021 / CSBS /CS3481 – DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM / 8 COURSE OBJECTIVE  To learn and implement important commands in SQL.  To learn the usage of nested and joint queries.  To understand functions, procedures and procedural extensions of databases.  To understand design and implementation of typical database applications.  To be familiar with the use of a front end tool for GUI based application development. COURSE OUTCOME At the end of this course, the students will be able to: CO1: Write SQL queries using typical data definition language and data manipulation language with different types of Key constraints in relational database management system CO2: Construct SQL queries using and using where clause perform different join operations and apply Data Control Language for complex transactions. CO3: Apply advanced features of PL/SQL such as stored procedures and triggers, incorporate in GUI based application development. CO4: Apply view, index for an SQL database and Create a web application to retrieve data from XML database with XML Schema validation. CO5: Create and manipulate NoSQL database to perform CRUD operations, apply the database design for a real time application.
  • 9. R2021 / CSBS /CS3481 – DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM / 9 CO-PO&PSO MAPPING PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2 PSO3 CO1 3 2 2 2 - - - - - - - - 2 - - CO2 3 2 2 2 - - - - - - - - 2 - - CO3 3 2 2 1 - - - - - - - - 2 - - CO4 3 2 2 1 - - - - - - - - 2 - - CO5 3 2 2 1 - - - - - - - - 2 - - Avg 3 2 2 1.4 - - - - - - - - 2 - -
  • 10. R2021 / CSBS /CS3481 – DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM / 10 GENERAL INSTRUCTIONS TO THE STUDENTS 1. No food or drink is to be brought into the lab, including gum and candy. 2. No cell phones or electronic devices at the lab stations (i pods, MP3 Players, etc.,). 3. Students must proceed immediately to their assigned position. 4. Students should maintain silence during the Lab session. 5. Students must inspect their position for possible damage and report immediately to the faculty any damage that may be found. 6. Students must follow the faculty’s instructions explicitly concerning all uses of the lab equipment. 7. Leave your shoes in the shoes rack before entering into the lab 8. Shut down the computer properly before leaving from the lab. 9. Do not bring college bag inside the lab. 10. Arrange your chairs properly before leaving from the lab 11. Students must wear lab coat during lab session
  • 11. R2021 / CSBS /CS3481 – DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM / 11 SYLLABUS CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY L T P C 0 0 3 1.5 COURSE OBJECTIVES:  To learn and implement important commands in SQL.  To learn the usage of nested and joint queries.  To understand functions, procedures and procedural extensions of databases.  To understand design and implementation of typical database applications.  To be familiar with the use of a front-end tool for GUI based application development. LIST OF EXERCISES: 1. Create a database table, add constraints (primary key, unique, check, Not null), insert rows, update and delete rows using SQL DDL and DML commands. 2. Create a set of tables, add foreign key constraints and incorporate referential integrity. 3. Query the database tables using different ‘where’ clause conditions and also implement aggregate functions. 4. Query the database tables and explore sub queries and simple join operations. 5. Query the database tables and explore natural, equi and outer joins. 6. Write user defined functions and stored procedures in SQL. 7. Execute complex transactions and realize DCL and TCL commands. 8. Write SQL Triggers for insert, delete, and update operations in a database table. 9. Create View and index for database tables with a large number of records. 10. Create an XML database and validate it using XML schema. 11. Create Document, column and graph based data using NOSQL database tools. 12. Develop a simple GUI based database application and incorporate all the above-mentioned features 13. Case Study using any of the real life database applications from the following list a) Inventory Management for a EMart Grocery Shop b) Society Financial Management c) Cop Friendly App – Eseva d) Property Management – eMall e) Star Small and Medium Banking and Finance ● Build Entity Model diagram. The diagram should align with the business and functional goals stated in the application. 42 ● Apply Normalization rules in designing the tables in scope. ● Prepared applicable views, triggers (for auditing purposes), functions for enabling enterprise grade features. ● Build PL SQL / Stored Procedures for Complex Functionalities, ex EOD Batch Processing for calculating the EMI for Gold Loan for each eligible Customer. ● Ability to showcase ACID Properties with sample queries with appropriate settings TOTAL: 45 PERIODS
  • 12. R2021 / CSBS /CS3481 – DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM / 12 LIST OF EXPERIMENTS – CO MAPPING S.No TITLE OF THE PROGRAM CO’S 1. DDL AND DML COMMANDS CO1 2. FOREIGN KEY CONSTRAINT CO1 3. WHERE CLAUSE AND AGGREGATE FUNCTIONS CO2 4. SUB QUERIES AND SIMPLE JOIN CO2 5. NATURAL, EQUI, OUTER JOIN CO2 6. FUNCTIONS AND STORED PROCEDURES CO3 7. DCL AND TCL COMMANDS CO2 8. TRIGGERS CO3 9. VIEW AND INDEX CO4 10. XML DATABSE AND XML SCHEMA CO4 11. NOSQL DATABASE CO5 12. GUI APPLICATION CO5 13. REAL LIFE APPLICATION CO5
  • 13. R2021 / CSBS /CS3481 – DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM / 13 INDEX Exp. No. Date Experiment Page No. Marks Faculty Signature 1. DDL AND DML COMMANDS 2. FOREIGN KEY CONSTRAINT 3. WHERE CLAUSE AND AGGREGATE FUNCTIONS 4. SUB QUERIES AND SIMPLE JOIN 5. NATURAL, EQUI, OUTER JOIN 6. FUNCTIONS AND STORED PROCEDURES 7. DCL AND TCL COMMANDS 8. TRIGGERS 9. VIEW AND INDEX 10. XML DATABSE AND XML SCHEMA 11. NOSQL DATABASE 12. GUI APPLICATION 13. REAL LIFE APPLICATION
  • 14. EX.NO:1a DATA DEFINITION COMMANDS DATE: AIM: Commands To implement database creation and do the operations in database using Data Definition ALGORITHM: Step 1: Create table by using create table command with column name, data type and size. Step 2: Display the table by using desc command. Step 3: Add any new column with the existing table by alter table command. Step 4: Modify the existing table with modify command. Step 5: Delete the records in files by truncate command. Step 6: Delete the Entire table by drop command. 1) CREATE TABLE Syntax: create table table_name( column1 datatype, column2 datatype, column3 datatype, ..... columnN datatype); Example: create table employee(id int,name varchar(100),age int,address varchar(100),salary float); Table employee created 2) DESCRIBING THE TABLE Syntax: desc table_name; Example: desc employee; 3) ALTER TABLE Syntax: alter table table_name add column_name datatype; Example: alter table employee add dept varchar(10);
  • 15. table employee altered select * from employee; Example: alter table employee add (state varchar(100),weight float); table employee altered. select * from employee; table employee altered. 4) RENAME To rename column name Syntax: alter table table_name rename column existing _name to new_name; Example: alter table employee rename column address to addr; table employee altered. select * from employee To rename table name Syntax: alter table table_name rename to new_table_name; Example: alter table employee rename to empl; table employee altered. select * from employee; ORA-00942: table or view does not exist 00942. 00000 - "table or view does not exist" *Cause: *Action: Error at Line: 21 Column: 15
  • 16. select * from empl; 5) TRUNCATE Syntax: truncate table table_name; Example: truncate table emp; select * from empl; no data found 6) DROP TABLE Syntax: drop table table_name; Example: drop table empl; table customers dropped. select * from empl; ORA-00942: table or view does not exist RESULT: Thus the queries to implement data definition commands are executed successfully.
  • 17. EX.NO:1b DATA MANIPULATION COMMANDS DATE: AIM: To implement and execute a query for manipulating & storing data items in a Oracle database using Structured Query Language commands ALGORITHM: Step 1: Create table by using create table command. Step 2: Insert values into the table Step 3: Delete any records from the table Step 4: Update any values in the table. Step 5: Display the values from the table by using select command. 1) CREATE A TABLE create table student(id int,Name varchar(30),Department varchar(10)); desc student; 2) INSERT Syntax: insert into table_name values(column1,column2,….); Example: insert into student values(1,'ABC','CSE'); insert into student values(2,'DEF','CSE'); select * from student; To insert NULL values to column: The following syntax is used to insert NULL value to the column. insert into student values(3,'null','CSE'); select * from student;
  • 18. To insert default value to the column: The following syntax is used to insert default value to the table. Syntax: insert into table_name values(column1,column2,…); Example: insert into student values(3,’alex’,default); 1 rows inserted. select * from student; To insert data using select statement: The following syntax is used insert all the values from another table using select statement. Syntax: insert into table_name1 select * from table_name2; Example: create table stud(id int,Name varchar(30),Department varchar(10)); insert into stud select * from student; 3) UPDATE Syntax: update table_name set column1 = value1, column2 = value2. .., columnn = valuen where [condition]; Example: (single column) update stud set Department='ECE' where id=3; 1 rows updated.
  • 19. Example: (multiple column) update stud set Name=’XYZ’,Department='CIVIL' where id=2; 4) DELETE Syntax: (delete particular row) delete from table_name where condition; Example: delete from stud where id=2; Syntax: delete from table_name; Example: delete from stud; select * from stud; no data found RESULT: Thus, a query for manipulating & storing data items in an Oracle database using Structured Query Language commands were implemented and executed successfully.
  • 20. EXPERIMENT – 1 VIVA QUESTIONS 1. What is DBMS? Database Management Systems (DBMS) are applications designed especially which enable user interaction with other applications. 2. What is DDL? DDL is Data Definition Language which is used to define the database and schema structure by using some set of SQL Queries like CREATE, ALTER, TRUNCATE, DROP and RENAME. 3. What is DML? DML is Data Manipulation Language which is used to do some manipulations in the database like Insertion, Deletion, etc. by using some set of SQL Queries like SELECT, INSERT, DELETE and UPDATE. 4. What is purpose of SQL? SQL stands for Structured Query Language whose main purpose is to interact with the relational databases in the form of inserting and updating/modifying the data in the database 5. What is Primary Key & Unique Key? The main difference between the Primary key and Unique key is that the Primary key can never have a null value while the Unique key may consist of null value. 6. Write a query to Create a table? CREATE TABLE table_name( column1 datatype, column2 datatype, column3 datatype, ); 7. What is foreign key? Foreign Key is mainly used to link two or more tables together, as this is a particular field(s) in one of the database tables which are the primary key of some other table. 8. What are the various kinds of interactions catered by DBMS? The various kind of interactions catered by DBMS are:  Data definition  Update  Retrieval  Administration 9. What is SQL? Structured Query Language (SQL) being ANSI standard language updates database and commands for accessing 10. Enlist the various relationships of database? The various relationships of database are:  One-to-one: Single table having drawn relationship with another table having similar kind of columns.  One-to-many: Two tables having primary and foreign key relation.  Many-to-many: Junction table having many tables related to many tables.
  • 21. EX.NO:2 CREATE SET OF TABLES ADD FOREIGN KEY CONSTRAINT AND DATE: INCORPORATE REFERENTIAL INTEGRITY Aim: To create set of tables add foreign key constraint and incorporate referential integrity using SQL. Algorithm:  Create two tables with a link that will not work.  Create two tables with a link that will work.  Add a foreign key to enforce referential integrity between the two tables.  Delete data from the tables.  Update and remove data to show how the foreign key protects the data.  Use the cascade option of the foreign key.  Companies table: List of Companies  Employees table: List of Employees working at the Company  Rule: Employees can only work at one Company, and a Company can employ multiple Employees Program: Step 1: --Create the HRDatabase USE master GO DROP DATABASE IF EXISTS HRDatabase GO CREATE DATABASE HRDatabase GO USE HRDatabase GO Step 2: -1st Try: Create a Companies and an Employees table and link them together DROP TABLE IF EXISTS Companies; GO DROP TABLE IF EXISTS Employees; GO -- SQL CREATE TABLE Statement CREATE TABLE Companies ( ID INT CONSTRAINT PK_Companies PRIMARY KEY IDENTITY, CompanyName VARCHAR(80) NOT NULL, -- column name, data types and null value CompAddress VARCHAR(80) NOT NULL, CompContactNo VARCHAR(20) NOT NULL, EmpID INT NOT NULL, CreateDate DATETIME NOT NULL constraint DF_Companies_CreateDate DEFAULT getdate() ) CREATE TABLE Employees ( ID INT CONSTRAINT PK_Employees PRIMARY KEY IDENTITY, EmployeeName VARCHAR(80) NOT NULL, ContactNo VARCHAR(20) NOT NULL, Email VARCHAR(80) NOT NULL,
  • 22. CreateDate DATETIME NOT NULL constraint DF_Employees_CreateDate DEFAULT getdate() ) INSERT INTO Companies (CompanyName, CompAddress, CompContactNo, EmpID) VALUES ('Alpha Company', '123 North Street, Garsfontein, Pretoria', '091 523 6987' , 1), ('Bravo Company', '456 South Street, Brooklyn, Pretoria', '091 523 4789' , 1), ('Charlie Company' , '987 West Street, Lynnwood, Pretoria', '091 523 1235' , 1), ('Delta Company', '258 East Street, The Meadows, Pretoria', '091 523 7414' , 1), ('Echo Company', '100 Amber Street, Hatfield, Pretoria', '091 523 9685' , 1) INSERT INTO Employees (EmployeeName, ContactNo, Email) VALUES ('Joe Blogs' , '012 365 4789', 'joeblogs@gmail.com') , ('Jane Doe' , '012 365 4789', 'janedoe@gmail.com') , ('John Smit' , '012 365 4789', 'johnsmit@gmail.com') , ('Eddy Jones' , '012 365 4789', 'eddyjones@gmail.com'), ('Steve Dobson', '012 365 4789', 'stevedobson@gmail.com') SELECT * FROM Companies SELECT * FROM Employees OUTPUT :
  • 23. 3 RESULT: Thus, to create a set of tables add foreign key constraint and incorporate referential integrity were implemented and executed successfully.
  • 24. EXPERIMENT – 2 VIVA QUESTIONS 1. Define Aggregate functions? Functions which operate against a collection of values and returning single value is called aggregate functions 2. Define Scalar functions? Scalar function is depended on the argument given and returns sole value. 3. Why WHERE clause is used? The WHERE clause is used to filter records. It is used to extract only those records that fulfill a specified condition. Syntax SELECT column1, column2, ... FROM table_name WHERE condition. 4. What is ACID Properties? A-Atomicity C-Consistency I-Isolation 5. Different types of abstraction levels? There are 3 levels of data abstraction in the DBMS. Physical level Logical level View level 6. What is the concept of sub-query in terms of SQL? Sub-query is basically the query which is included inside some other query and can also be called as an inner query which is found inside the outer query 7. What is Correlated Subquery in DBMS? A Subquery is also known as a nested query i.e. a query written inside some query. When a Subquery is executed for each of the rows of the outer query then it is termed as a Correlated Subquery. 8. What is a join in the SQL? A Join is one of the SQL statements which is used to join the data or the rows from 2 or more tables on the basis of a common field/column among them. 9. What is simple join? Join is used to display matching records from both tables. This is also called a simple if you omit inner the keyword and just use join, this is the type of join you’ll get by default. 10. What are the 4 types of joins in SQL? a. Inner join b. Right join c. Left join d. Full join
  • 25. EX.NO:3 DATABASE TABLES WITH DIFFERENT 'WHERE CLAUSE' CONDITIONS DATE: Aim: To using query the database tables with different 'where clause' conditions also implement aggregate function with algorithm Algorithm: Step 1: There are tables country and city. We’ll use the following statements: SELECT * FROM country; SELECT * FROM city; You can see the result in the picture below:
  • 26. Step 2: SELECT * FROM country INNER JOIN city ON city.country_id = country.id; SELECT COUNT(*) AS number_of_rows FROM country INNER JOIN city ON city.country_id = country.id; Step 3: SELECT *FROM country LEFT JOIN city ON city.country_id = country.id; SELECT COUNT(*) AS number_of_rows FROM country LEFT JOIN city ON city.country_id = country.id; SELECT COUNT(country.country_name) AS countries, COUNT(city.city_name) AS cities FROM country LEFT JOIN city ON city.country_id = country.id; RESULT: Thus the SQL query the database tables with different 'where clause' conditions also implement aggregate function are executed successfully.
  • 27. EXPERIMENT – 3 VIVA QUESTIONS 1. How do you retrieve data from a table based on a specific condition? You can use the SELECT statement with the WHERE clause. 2. Explain how you can combine multiple conditions in a WHERE clause. You can use the AND and OR operators to combine conditions. 3. How do you filter data based on multiple possible values? You can use the IN operator for this purpose. 4. How can you retrieve data within a specific range? The BETWEEN operator is used for this. 5. How do you perform a partial string match in a WHERE clause? The LIKE operator is used, along with wildcards (% for any characters, _ for a single character). 6. How do you filter records based on the presence or absence of NULL values? You can use the IS NULL or IS NOT NULL conditions 7. Can you retrieve data with a specific condition and have it ordered in a particular way? Yes, you can combine WHERE with ORDER BY. 8. How do you handle complex conditions in a WHERE clause? You can use parentheses to group conditions and control the logic. 9. What is natural joins? A NATURAL JOIN is a JOIN operation that creates an implicit join clause for you based on the common columns in the two tables being joined. Common columns are columns that have the same name in both tables. 10. What is equi in sql? The EQUI JOIN in SQL performs a JOIN against a column of equality or the matching column(s) values that have the associated tables. Here, we use an equal sign (=) as a comparison operator in our ‘where’ clause to refer to equality.
  • 28. EX.NO:4 SIMPLE QUERIES, SUB QUERIES, JOINS DATE: AIM: To implement Simple queries, Nested queries, Sub queries using structured query language ALGORITHM: STEP 1: Create a table with the columns that are needed STEP 2: Write simple queries to insert, delete, update and implement some functions STEP 3: Write nested queries using clauses to retrieve data from the table STEP 4: The nested queries may have more than one sub queries. STEP 5: Efficiently retrieve data from the table QUERIES: create table salary(id int, Name varchar(20),Age int,Salary float); insert into salary values(1,'Ajay',25,20000); insert into salary values(2,'Archana',28,30000); insert into salary values(3,'Archana',23,25000); insert into salary values(4,'Sara',24,20000); insert into salary values(5,'Ajay',25,40000); insert into salary values(6,'Srinithi',26,35000); select * from salary; Sum function Syntax: select column_name1,sum(column_name2)from table_name group by column_name3; Example: select name, sum(salary) from salary group by name; Min function Syntax: select column_name1,min(column_name2)from table_name group by column_name3; Example: select name, min(salary) from salary group by name;
  • 29. Max function Syntax: select column_name1,max(column_name2)from table_name group by column_name3; Example: select name, max(salary) from salary group by name; Count function Syntax: select column_name1,count(column_name2)from table_name group by column_name3; Example: select name, count(salary) from salary group by name; Mod function Syntax: select column_name1,mod(column_name2)from table_name; Example: select name,mod(salary,5) from salary; DISTINCT and ORDER BY Clause Syntax: select distinct column1, column2,.... columnn from table_name; Example: select salary from salary order by salary;
  • 30. select distinct salary from salary order by salary; HAVING clause Example: select min(salary)from salary group by age having max(salary)<30000; Select using Conditions AND Example: select * from salary where age >= 25 and salary >= 25000; OR Example: select * from salary where age >= 25 or salary >= 25000; LIKE select * from salary where name like 'Aj%';
  • 31. select * from salary where age in ( 25, 28 ); IN BETWEEN
  • 32. select * from salary where salary between 20000 and 30000; IS NOT NULL select * from salary where age is not null; IS NULL select * from salary where age is null; no data found (4,'Kumaran',25,'CBE',24000); SubquerieswiththeINSERTStatement INSERT INTO customers_backup SELECT * FROM CUSTOMERS WHERE ID IN (SELECT ID FROM CUSTOMERS) ; 4 rows inserted select * from customers_backup; SubquerieswiththeUPDATEStatement UPDATE CUSTOMERS SET SALARY = SALARY * 0.25 WHERE AGE IN (SELECT AGE FROM customers_backup WHERE AGE >= 27 ); Select * from customers;
  • 33. SubquerieswiththeDELETEStatement DELETE FROM CUSTOMERS WHERE AGE IN (SELECT AGE FROM CUSTOMERS_backup WHERE AGE >= 27 ); select * from customers;
  • 34. select age from customers where exists (select age from salary where salary > 25000); JOINS CREATE and INSERT values in TABLE(cust) create table cust(id int primary key,name varchar(20),age int); insert into cust values(1,'aaa',32); insert into cust values(2,'aba',32); insert into cust values(3,'abc',32); insert into cust values(4,'ccc',25); select * from cust; CREATE and INSERT values in TABLE(order1) create table order1(oid int primary key,custid int,amount int); insert into order1 values(101,1,1000); insert into order1 values(102,2,2000); insert into order1 values(103,3,3000); 1. INNER JOIN Syntax: SELECT table1.column1, table2.column2... FROM table1 INNER JOIN table2 ON table1.common_filed = table2.common_field; Example: select id,name,oid,amount
  • 35. from cust inner join order1 on cust.id=order1.custid; 2. LEFT JOIN: Syntax: select table1.column1, table2.column2... from table1 left join table2 on table1.common_filed = table2.common_field; Example: select id,name,oid,amount from cust left join order1 on cust.id=order1.custid; 3. RIGHT JOIN: Syntax: select table1.column1, table2.column2... from table1 right join table2 on table1.common_filed = table2.common_field; Example: select id,name,oid,amount from cust right join order1 on cust.id=order1.custid;
  • 36. 4. FULL JOIN: Syntax: select table1.column1, table2.column2... from table1 full join table2 on table1.common_filed = table2.common_field; Example: select id,name,oid,amount from cust full join order1 on cust.id=order1.custid; RESULT: Thus the SQL commands to execute simple queries, sub queries and joins areexecuted successfully.
  • 37. EXPERIMENT – 4 VIVA QUESTIONS 1. What is a sub query, and how is it different from a regular query? A sub query is a query nested inside another query. It can be used within a WHERE clause to retrieve data that will be used by the main query. 2. Provide an example of a correlated sub query. A correlated sub query references a column from the outer query. Example: SELECT employee_name FROM employees WHERE salary > (SELECT AVG(salary) FROM employees WHERE department_id = employees.department_id); 3. When would you use a sub query instead of a JOIN? Sub queries are useful when you need to retrieve a single value or a set of values that can be used by the main query, while Joins are used to combine columns from two or more tables. 4. Explain the difference between INNER JOIN and LEFT JOIN. INNER JOIN returns only the matching rows between two tables, while LEFT JOIN returns all rows from the left table and the matching rows from the right table. 5. What is a self-join, and in what scenario would you use it? A self-join is when a table is joined with itself. It is used when you want to compare records within the same table, such as finding employees who share the same manager. 6. How do you retrieve columns from multiple tables using a JOIN? Use the SELECT statement with the appropriate JOIN clause. For example: SELECT employees.employee_name, departments.department_name FROM employees INNER JOIN departments ON employees.department_id = departments.department_id; 7. Explain the purpose of the USING clause in a JOIN. The USING clause is used to specify a column that exists in both tables and should be used as the join condition. For example: SELECT * FROM employees JOIN departments USING (department_id); 8. . Is SELF JOIN an INNER JOIN or OUTER JOIN? The SELF JOIN can be an INNER JOIN, OUTER JOIN, or can also be CROSS JOIN. Tables are automatically linked based on columns that contain duplicate data in multiple rows. 9. IS required that the JOIN condition be based on equality? No, because JOINS have the conditions of NON-EQUI. Sentence combinations can be done with common ssymbols such as <, <=, >, >=, !=, BETWEEN, for example, to represent data. Odd-pair indexing and identifying duplicate data are several cases where NON-EQUI JOINS performance can be demonstrated. 10. What is index in sql? Indexes are used to retrieve data from the database more quickly than otherwise. The users cannot see the indexes, they are just used to speed up searches/queries
  • 38. EX.NO:5 NATURAL, EQUI AND OUTER JOIN DATE: Aim To write DQL Commands to join, Restrict and Retrieve information from one or more tables execute it and verify the same. Algorithm Selecting Rows with Equijoin using table Aliases 1. Write a query to display empid,name,deptid,deptname and location for allemployees and verify it. SQL> select employee.empid,employee.name,employee.depid,department.deptname,depa rtment.location from employee,department where employee.depid=department.depid; EMPID NAME DEPID DEPTNAME LOCATION a123 ragu CS000 COMPUTER_SCIENCE CHENNAI a124 rama CS000 COMPUTER_SCIENCE CHENNAI a125 ram EE000 ELECT_ELECTRO MUMBAI a128 sag EE000 ELECT_ELECTRO MUMBAI c128 dinesh EC000 ELECT_COMM DELHI d124 abc EC000 ELECT_COMM DELHI 6 rows selected. 2. Write a query to display the “dinesh” depid and deptname and verify it. SQL> select e.empid,e.name,e.depid,d.deptname from employee e,department d wheree.depid=d.depid and e.name='dinesh'; EMPID NAME DEPID DEPTNAME c128 dinesh EC000 ELECT_COMM Selecting Rows with Non-Equijoin using table Aliases: [Other Conditions such as >=, <= and BETWEEN, AND ] 1. Write a query to display the name,salary and deptname of all employees whosesalary is greater than 10000 and verify it. SQL> select e.name,e.salary,d.deptname from employee e,department d where e.salary>10000and e.depid=d.depid; NAME SALARY DEPTNAME ragu 200000 COMPUTER_SCIENCE rama 200000 COMPUTER_SCIENCE ram 30000 ELECT_ELECTRO
  • 39. Selecting Rows using Outer Joins:[ Left Outerjoin,Right Outerjoin using ”+” symbol ] 1. Write a query to display the name, depid and deptname of all employees.Make surethat employees without department are included as well and verify it. SQL> select e.name,e.depid,d.deptname from employee e,department d where e.depid =d.depid(+); NAME DEPID DEPTNAME rama CS000 COMPUTER_SCIENCE ragu CS000 COMPUTER_SCIENCE sag EE000 ELECT_ELECTRO ram EE000 ELECT_ELECTRO abc EC000 ELECT_COMM dinesh EC000 ELECT_COMM www 7 rows selected. 2.Write a query to display the name, salary,depid and deptname of all employees. Makesure that departments without employees are included as well and verify. SQL> select e.name,e.salary,e.depid,d.deptname from employee e,department d where e.depid(+)=d.depid; NAME SALARY DEPID DEPTNAME ragu 200000 CS000 COMPUTER_SCIENCE rama 200000 CS000 COMPUTER_SCIENCE ram 30000 EE000 ELECT_ELECTRO sag 10000 EE000 ELECT_ELECTRO dinesh 10000 EC000 ELECT_COMM abc 5000 EC000 ELECT_COMM MECHANICAL CHEMICAL 8 rows selected d RESULT: Thus the SQL commands to execute natural, equi and outer joins areexecuted successfully.
  • 40. EXPERIMENT – 5 VIVA QUESTIONS 1. What is a Database system? The database and DBMS software together is called as Database system. 2. What are the Advantages of DBMS? Redundancy is controlled. Unauthorized access is restricted. Providing multiple user interfaces. Enforcing integrity constraints. Providing backup and recover. 3. What is functional dependency in DBMS? This is basically a constraint which is useful in describing the relationship among the different attributes in a relation. 4. What is stored procedures? A stored procedure is a prepared SQL code that you can save, so the code can be reused over and over again. So if you have an SQL query that you write over and over again, save it as a stored procedure. 5. What is an entity? It is a `thing’ in the real world with an independent existence. 6. Can you provide an example of when you would use a Natural Join? Suppose you have a "Customers" table and an "Orders" table, both having a "CustomerID" column. A Natural Join could be used to retrieve information about customers and their corresponding orders without explicitly specifying the join condition. 7. What is the key characteristic of an Equi Join? The key characteristic of an Equi Join is that it involves the use of the equality operator (=) to match rows between two tables based on specified columns. 8. Can you give an example of when you might use an Equi Join in a database query? Let's say you have a "Students" table and a "Courses" table, both having a "StudentID" column. An Equi Join could be used to find students who are enrolled in specific courses by matching the "StudentID" values 9. Explain the concept of an Outer Join. An Outer Join retrieves matching rows from tables and includes non-matching rows from one or both tables. It ensures that even if there are no matches, rows from one or both tables are still included in the result set. 10. Write the syntax for view? CREATE VIEW view_name AS SELECT columns FROM tables [WHERE conditions]; view_name.
  • 41. EX.NO:6 PROCEDURES AND FUNCTIONS DATE: AIM: To implement and execute Procedures in Oracle Database using Procedural Language concepts. PROCEDURES: 1) Procedure is a sub program used to perform an action. 2) Replace-recreates the procedure if it already exists. 3 MODES: 1) IN – Means you must specify a value for the argument at the time execution of the procedure. 2) OUT-passes back a value to its calling program. 3) INOUT – When calling the procedure, yu must specify the value and that procedures passes value back to the calling procedure CREATING A PROCEDURE SYNTAX: CREATE [OR REPLACE] PROCEDURE procedure_name [(column_name [IN | OUT | IN OUT] type [, ...])] {IS | AS} BEGIN < procedure_body > END procedure_name; CREATE OR REPLACE PROCEDURE greetings AS BEGIN dbms_output.put_line('Hello World!'); END; To run this procedure BEGIN greetings; END; DELETING A PROCEDURE SYNTAX: DROP PROCEDURE procedure-name; EXAMPLE: DROP PROCEDURE greetings; Procedure dropped
  • 42. EXAMPLE 2 Create a table user1 create table user1(id number(10) primary key,name varchar2(100)); Create the procedure create or replace procedure INSERTUSER(id IN NUMBER, name IN VARCHAR2) is begin insert into user1 values(id,name); end; To execute the procedure BEGIN INSERTUSER(101,'Rahul'); dbms_output.put_line('record inserted successfully'); END; PL/SQL FUNCTIONS SYNTAX: CREATE [OR REPLACE] FUNCTION function_name [parameters] [(parameter_name [IN | OUT | IN OUT] type [, ...])] RETURN return_datatype {IS | AS} BEGIN < function_body > END [function_name]; create or replace function adder(n1 in number, n2 in number) return number is n3 number(8); begin n3 :=n1+n2; return n3; end; EXECUTE THE FUNCTION DECLARE n3 number(2); BEGIN n3 := adder(11,22); dbms_output.put_line('Addition is: ' || n3); END;
  • 43. Output: Addition is: 33 Statement processed. RESULT: Thus the PL/SQL procedures and functions are executed successfully
  • 44. EXPERIMENT – 6 VIVA QUESTIONS 1. What is a stored procedure? A stored procedure is a recompiled collection of one or more SQL statements that can be stored and executed on a database server. It allows for the reuse of code and helps improve performance by reducing the need to send multiple SQL statements over the network. 2. How is a stored procedure different from a regular SQL query? A stored procedure is a saved set of SQL statements with a name and can accept parameters. It is recompiled and stored on the server, whereas a regular SQL query is sent to the server for immediate execution. 3. What are the advantages of using stored procedures? Stored procedures offer advantages such as code re usability, improved performance due to recompilation, better security control, and easier maintenance. 4. Can you explain how parameters work in stored procedures? Parameters in stored procedures act as placeholders for values that can be passed during the procedure's execution. They allow for flexibility and customization of the procedure's behavior. 5. How do you call a stored procedure? A stored procedure is called using the CALL or EXECUTE statement, followed by the procedure name and any necessary parameters. 6. What is a function in the context of a database? A function is a recompiled set of SQL statements that performs a specific task and returns a single value. It is similar to a stored procedure but is designed to return a value rather than perform an action 7. How is a function different from a stored procedure? While both functions and stored procedures can contain sets of SQL statements, functions return a value, while stored procedures do not necessarily return a value but may perform actions. 8. What are the types of functions commonly used in databases? Common types of functions include scalar functions (returning a single value), table-valued functions (returning a table), and aggregate functions (performing a calculation on a set of values). 9. Can functions have side effects? Ideally, functions are designed to be deterministic and not have side effects. However, some database systems allow functions to have side effects, which can impact the consistency of the database. 10. What is TCL? TCL is abbreviation of Transaction Control Language. It is used to manage different transactions occurring within a database.
  • 45. EX.NO.7 TRANSACTION CONTROL AND DATA CONTROL STATEMENTS DATE: AIM: To implement Transaction Control statements using structured Query Language ALGORITHM: Step 1: Create table by using create table command. Step 2: Insert values into the table Step 3: Commit the table Step 4: Insert or Update any values in the table. Step 5: Rollback the table Step 6: Insert or Update any values in the table. Step 7: Fix a save point Step 8: Repeat step 6 and 7 Step 9: Rollback to any save point 1) CREATE A TABLE create table employeepersonaldetails(id int primary key,name varchar(30) not null,age int not null,mobilenumber int not null unique); insert into employeepersonaldetails values(1,'Ajay',20,9876543210); insert into employeepersonaldetails values(2,'Brindha',20,9874563210); insert into employeepersonaldetails values(3,'Kumaran',20,9673443210); select * from employeepersonaldetails; commit; Statement executed insert into employeepersonaldetails values(4,'Archana',20,9876543410);
  • 46. rollback; insert into employeepersonaldetails values(5,'Braham',20,9878953210); savepoint a; savepoint created insert into employeepersonaldetails values(6,'Srimathi',20,9678953210); savepoint b; rollback to a; RESULT: Thus Transaction Control and Data Control statements using structured Query Language is executed successfully
  • 47. EXPERIMENT – 7 VIVA QUESTIONS 1. What is a transaction in a database? A transaction is a sequence of one or more SQL statements that are executed as a single unit of work, ensuring that either all the statements are executed successfully, or none of them are. 2. Explain the concept of a save point. A save point is a point within a transaction to which you can roll back. It allows for partial rollback of a transaction in case of errors without rolling back the entire transaction. 3. Why is it important to use transaction control statements? Transaction control statements ensure the consistency and integrity of the database by allowing changes to be either fully applied or fully undone. They help maintain the reliability of the data. 4. What is the purpose of the GRANT statement? The GRANT statement is used to give specific privileges to a user or a role, allowing them to perform certain actions on database objects like tables, views, or procedures. 5. Explain the concept of database privileges. Database privileges define the actions that a user or role is allowed to perform on a specific database object. Examples include SELECT, INSERT, UPDATE, DELETE, and EXECUTE privileges. 6. How is the REVOKE statement used? The REVOKE statement is used to revoke previously granted privileges from a user or role, restricting their access to specific database objects. 7. What is the purpose of the DENY statement? The DENY statement is used to explicitly deny a user or role specific privileges on a database object. It takes precedence over any previously granted privileges 8. How do data control statements contribute to database security? Data control statements help manage access to database objects, ensuring that users have appropriate permissions to perform necessary actions while restricting unauthorized access. This contributes to the security and integrity of the database. 9. Examples of DCL? GRANT: This command gives users access privileges to the database. REVOKE: This command withdraws the user's access privileges given by using the GRANT command. COMMIT: Commits a Transaction. 10. What is the difference between DCL & TCL? By using DDL commands, database transaction cannot be handled. TCL commands are meant to handle database transaction
  • 48. EX.NO:8 TRIGGERS DATE: AIM: To implement PL/SQL triggers and do the operations in database automatically. ALGORITHM: STEP1: Create a table emply101 STEP2: Insert values into the table STEP3: Create another table emply102 STEP4: Create trigger CREATE OR REPLACE TRIGGER <TRIGGER NAME> {BEFORE/AFTER/INSTEAD OF} {INSERT/UPDATE/DELETE} ON <TABLENAME/VIEWNAME> REFRENCECING {OLD AS OLD /NEW AS NEW} [FOR EACH STATEMENT /FOR EACH ROW [WHEN <CONDITION>]] STEP5: Insert and delete record into emply101 STEP6: View the updations in emply102 CREATE TABLE emply101 create table emply101(eid varchar(20),ename char(25), age number(10), salary number(10)); insert into emply101 values(1,'abi',23,25000); insert into emply101 values(2,'abinaya',22,20000); insert into emply101 values(3,'abishek',23,25000); select * from emply101; CREATE TABLE emply102 create table emply102(eid varchar(20),ename char(25),age number(10),salary number(10)); select * from emply102; no data found Creating trigger create or replace trigger tfg1 before insert on emply101 for each row begin insert into emply102 values(:new.eid,:new.ename,:new.age,:new.salary); end;
  • 49. Insert values into emply101 insert into emply101 values(4,'bala',23,25000); select * from emply101; select * from emply102; CREATING TRIGGER FOR UPDATING AND DELETING create or replace trigger trgrr15 after delete or update on emply101 for each row begin if deleting then insert into emply102 values(:old.eid,:old.ename,:old.age,:old.salary); elsif updating then insert into emply102 values(:old.eid,:old.ename,:old.age,:old.salary); end if; end; Update a value in emply101 update emply101 set salary=10000 where eid=1; select * from emply102; RESULT: Thus the SQL triggers are executed successfully.
  • 50. EXPERIMENT – 8 VIVA QUESTIONS 1. What is a database trigger? A database trigger is a set of instructions or code that is automatically executed ("triggered") in response to a specific event, such as an INSERT, UPDATE, DELETE, or another action, occurring in a database. 2. What are the types of triggers commonly used in databases? The two main types of triggers are BEFORE triggers, which are executed before the triggering event, and AFTER triggers, which are executed after the triggering event. 3. How does a BEFORE INSERT trigger differ from an AFTER INSERT trigger? A BEFORE INSERT trigger is executed before the actual insertion of data into the table, allowing for validation or modification of data. An trigger is executed after the data has been inserted, and it can perform actions based on the successful insertion. 4. What is the purpose of using triggers in a database? Triggers are used to enforce business rules, ensure data integrity, and automate actions in response to specific events, reducing the need for manual intervention and enhancing the consistency of the database. 5. Can a trigger be associated with more than one event? Yes, a trigger can be associated with multiple events. For example, a trigger can be designed to execute on both BEFORE INSERT and BEFORE UPDATE events. 6. How do you create a trigger in a database? To create a trigger, you use the CREATE TRIGGER statement, specifying the trigger name, timing (BEFORE or AFTER), event (INSERT, UPDATE, DELETE), and the SQL statements or procedures to be executed. 7. Explain the concept of a FOR EACH ROW trigger. A FOR EACH ROW trigger is a type of trigger that is executed once for each row affected by the triggering event. It is commonly used with row-level actions, such as validating or modifying data on a per-row basis. 8. How do you disable or drop a trigger? You can disable a trigger using the TRIGGER. To drop a trigger, you use the 9. Can triggers cause performance issues in a database? statement and re-enable it using statement. Poorly designed triggers or triggers with complex logic can potentially cause performance issues. It's essential to carefully design triggers to ensure they do not adversely impact database performance 10. Provide an example scenario where a trigger might be useful. A trigger could be useful in enforcing a rule that prevents the deletion of records from a critical table, ensuring that a record can only be marked as inactive (UPDATE instead of DELETE).
  • 51. EX.NO:9 VIEWS AND INDEX DATE: AIM: To write a DDL command to create views to restrict data access from one or more tables,execute it and verify the same. Creating views: 1. Create a view that contains employee id as “ID_NUMBER”, employee name as “NAME”and salary as ”SALARY” for each employee in department 90. SQL> create view vw_emp80(id,name,salary) as select empid,name,salary from employee wheredeptid=90; OUTPUT: View created. SQL> select * from vw_emp80; ID NAME SALARY s203 vidhya 29000 2. To create a view to set the salary Rs.15000/- to the employee id ‘a102’ in the vw_dept_salary and verify the result in vw_emp12_sal and employees table. SQL> update vw_emp12 set salary=15000 where empid='a102';1 row updated. To Verify: SQL> select * from vw_emp12; SNO NAME SALARY DESIG LAST EMPID DEPTID HIRE_DATE 1 monica 15000 rep a a102 102 13-MAR-08 Creating Index Create table CREATE TABLE Colleges ( college_id INT PRIMARY KEY,college_code VARCHAR(20),NOT NULL college_name VARCHAR(50) ); create index CREATE INDEX college_index ON Colleges(college_code); Colleges RESULT: Thus the PL/SQL program for implementing views and index has been successfully executed. college_id college_code college_name empty
  • 52. EXPERIMENT – 9 VIVA QUESTIONS 1. What is an index in a database? An index is a data structure that improves the speed of data retrieval operations on a database table. It is created on one or more columns of a table to quickly locate and access rows based on the indexed columns. 2. Why are indexes used, and what benefits do they provide? indexes are used to improve the speed of data retrieval operations by facilitating quicker access to rows. They enhance query performance, especially for SELECT statements, by minimizing the number of rows that need to be scanned. 3. What is the trade-off associated with using indexes? While indexes improve query performance, they come with the trade-off of increased storage space and potential overhead during data modification operations (INSERT, UPDATE, DELETE), as the indexes also need to be maintained. 4. Can you create an index on multiple columns? Yes, a composite index, or multi-column index, can be created on multiple columns. This type of index is useful when queries involve conditions on multiple columns. 5. How does an index impact the performance of SELECT queries? Indexes can significantly improve the performance of SELECT queries by allowing the database engine to quickly locate and retrieve the relevant rows, reducing the need for full table scans. 6. When would you consider not using an index? Indexes may not be necessary for small tables or tables with infrequent queries. In situations where data modifications (INSERT, UPDATE, DELETE) significantly outweigh read operations, the overhead of maintaining indexes may outweigh the benefits. 7. Explain the concept of a clustered index. A clustered index determines the physical order of data in a table. The rows in the table are stored on disk in the same order as the index, making it different from a non-clustered index where the order on disk does not match the index order. 8. What is meant by trigger? Trigger is one of the very important codes or programs which get executed automatically in response to the events that occur in a table or a view. 9. What are the operations performed in trigger? 10. Syntax for trigger? CREATE TRIGGER schema.trigger_name ON table_name AFTER {INSERT, UPDATE, DELETE} [NOT FOR REPLICATION] AS {SQL_Statements}
  • 53. EX.NO:10 XML SCHEMA DATE: AIM: To implement XML Database and validate it using XML Schema. PROGRAM CREATE TABLE t1 ( id NUMBER, xml XMLTYPE ); INSERT INTO t1 VALUES (1, '<?xml version="1.0" encoding="UTF-8"?> <shiporder orderid="889923"> <orderperson>John Smith</orderperson> <shipto> <name>Ola Nordmann</name> <address>Langgt 23</address> <city>4000 Stavanger</city> <country>Norway</country> </shipto> <item> <title>Empire Burlesque</title> <note>Special Edition</note> <quantity>1</quantity> <price>10.90</price> </item> <item> <title>Hide your heart</title> <quantity>1</quantity> <price>9.90</price> </item> </shiporder>'); INSERT INTO t1 VALUES (2, '<?xml version="1.0" encoding="UTF-8"?> <shiporder orderid="889923"> <orderperson>John Smith</orderperson> <shipto> <name1>Ola Nordmann</name1> <address>Langgt 23</address> <city>4000 Stavanger</city> <country>Norway</country> </shipto> <item> <title>Empire Burlesque</title> <note>Special Edition</note> <quantity>1</quantity> <price>10.90</price> </item> <item> <title>Hide your heart</title> <quantity>1</quantity> <price>9.90</price> </item>
  • 54. </shiporder>'); COMMIT; OUTPUT SELECT id, XMLISVALID(xml, 'my_schema.xsd') AS is_valid FROM t1; ID IS_VALID ------- ---------- 1 1 2 0 RESULT: Thus the XML Database and validate it using XML Schema is executed successfully.
  • 55. EXPERIMENT – 10 VIVA QUESTIONS 1. What is an XML Schema? An XML Schema is a way to describe the structure and constraints of XML documents. It defines the elements, attributes, data types, and the relationships between them in an XML document. 2. Why is XML Schema important in the context of XML documents? XML Schema provides a standardized way to define the structure and data types of XML documents, ensuring consistency and facilitating interoperability between systems that exchange XML data. 3. What are the key components of an XML Schema? The key components of an XML Schema include elements, attributes, data types, complex types, simple types, and the relationships between them. 4. Explain the difference between a complex type and a simple type in XML Schema. A complex type can contain other elements and attributes, allowing for a more complex structure. A simple type, on the other hand, represents atomic data types like strings, numbers, or dates without containing other elements. 5. How do you define an element in an XML Schema? Elements are defined using the <element> tag in an XML Schema. You specify the name, type, and any constraints for the element within this tag. 6. What is the purpose of the XML Schema complexType element? The complexType element is used to define complex types, which can contain other elements and attributes. It allows for the creation of more structured and hierarchical data models. 7. How can you restrict the values of an element using XML Schema? You can use the restriction element to restrict the values of an element based on a specific data type, such as restricting a string to a certain length or restricting a number to a specific range. 8. Explain the concept of XML Schema namespaces. XML Schema namespaces are used to avoid naming conflicts between elements and types. They allow different XML vocabularies or applications to define elements and types with the same name without colliding. 9. What is the purpose of the include and import statements in XML Schema? The include statement is used to include components from another schema file, while the import statement is used to import components from another schema namespace. 10. How does XML Schema contribute to data validation in XML documents? XML Schema provides a set of rules and constraints that define the structure and data types of XML documents. During document validation, the XML processor checks whether the document conforms to the specified schema.
  • 56. EX.NO:11 NOSQL DATABASE TOOLS DATE Aim: To design and develop MongoDB queries using CRUD operations. Algorithm: Step 1: Create table by using create table command. Step 2: Insert values into the table Step 3: Delete any records from the table Step 4: Update any values in the table. Step 5: Display the values from the table by using select command. Step 6: Search any value using find. Query: > db.createCollection('Student'); { "ok" : 1 } > db.Student.insert({'Rno':'1','Name':'Piyush','Class':'TE COMP'}); WriteResult({ "nInserted" : 1 }) > db.Student.insert({'Rno':'2','Name':'Abhi','Class':'TE COMP'}); WriteResult({ "nInserted" : 1 }) > db.Student.insert({'Rno':'3','Name':'Ashley','Class':'TE COMP'});WriteResult({ "nInserted" : 1 }) > db.Student.insert({'Rno':'4','Name':'Hitesh','Class':'TE COMP'}); WriteResult({ "nInserted" : 1 }) > db.Student.insert({'Rno':'5','Name':'Pratik','Class':'TE COMP'}); WriteResult({ "nInserted" : 1 }) > db.Student.insert({'Rno':'6','Name':'Pratik','Class':'TE COMP'}); WriteResult({ "nInserted" : 1 }) > db.Student.find(); { "_id" : ObjectId("5b8fad4ef00832a0a50b5036"), "Rno" : "1", "Name" : "Piyush", "Class" : "TE COMP" } { "_id" : ObjectId("5b8fad62f00832a0a50b5037"), "Rno" : "2", "Name" : "Abhi", "Class" : "TE COMP" } { "_id" : ObjectId("5b8fad70f00832a0a50b5038"), "Rno" : "3", "Name" : "Ashley", "Class" : "TE COMP" } { "_id" : ObjectId("5b8fad7ff00832a0a50b5039"), "Rno" : "4", "Name" : "Hitesh", "Class" : "TE COMP" } { "_id" : ObjectId("5b8fad8df00832a0a50b503a"), "Rno" : "5", "Name" : "Pratik", "Class" : "TE COMP" } { "_id" : ObjectId("5b8fada4f00832a0a50b503b"), "Rno" : "6", "Name" : "Pratik", "Class" : "TE COMP" } > db.Student.find().pretty(); { "_id" : ObjectId("5b8fad4ef00832a0a50b5036"), "Rno" : "1", "Name" : "Piyush", "Class" : "TE COMP" } { "_id" : ObjectId("5b8fad62f00832a0a50b5037"), "Rno" : "2", "Name" : "Abhi", "Class" : "TE COMP"} { "_id" : ObjectId("5b8fad70f00832a0a50b5038"),
  • 57. "Rno" : "3", "Name" : "Ashley", "Class" : "TE COMP" } { "_id" : ObjectId("5b8fad7ff00832a0a50b5039"), "Rno" : "4", "Name" : "Hitesh", "Class" : "TE COMP" } { "_id" : ObjectId("5b8fad8df00832a0a50b503a"), "Rno" : "5", "Name" : "Pratik", "Class" : "TE COMP" } { "_id" : ObjectId("5b8fada4f00832a0a50b503b"), "Rno" : "6", "Name" : "Pratik", "Class" : "TE COMP" } > show dbs; Abhi 0.078GB admin (empty) local 0.078GB > db.Student.update({'Name':'Hitesh'},{$set: {'Name':'Henry'}});WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 }) > db.Student.find().pretty(); { "_id" : ObjectId("5b8fad4ef00832a0a50b5036"), "Rno" : "1", "Name" : "Piyush", "Class" : "TE COMP" } { "_id" : ObjectId("5b8fad62f00832a0a50b5037"), "Rno" : "2", "Name" : "Abhi", "Class" : "TE COMP" } { "_id" : ObjectId("5b8fad70f00832a0a50b5038"), "Rno" : "3", "Name" : "Ashley", "Class" : "TE COMP" } { "_id" : ObjectId("5b8fad7ff00832a0a50b5039"), "Rno" : "4", "Name" : "Henry", "Class" : "TE COMP" } { "_id" : ObjectId("5b8fad8df00832a0a50b503a"),
  • 58. "Rno" : "5", "Name" : "Pratik", "Class" : "TE COMP"} { "_id" : ObjectId("5b8fada4f00832a0a50b503b"), "Rno" : "6", "Name" : "Pratik", "Class" : "TE COMP" } > db.Student.remove({'ADD':'MP'}); WriteResult({ "nRemoved" : 1 }) > db.Student.find().pretty(); { "_id" : ObjectId("5b8fad62f00832a0a50b5037"), "Rno" : "2", "Name" : "Abhi", "Class" : "TE COMP" } { "_id" : ObjectId("5b8fad70f00832a0a50b5038"), "Rno" : "3", "Name" : "Ashley", "Class" : "TE COMP" } { "_id" : ObjectId("5b8fad7ff00832a0a50b5039"), "Rno" : "4", "Name" : "Henry", "Class" : "TE COMP" } { "_id" : ObjectId("5b8fad8df00832a0a50b503a"), "Rno" : "5", "Name" : "Pratik","Class" : "TE COMP" } { "_id" : ObjectId("5b8fada4f00832a0a50b503b"), "Rno" : "6", "Name" : "Pratik", "Class" : "TE COMP" } > db.Student.remove({'Name':'Pratik'},1); WriteResult({ "nRemoved" : 1 }) > db.Student.remove({'Name':'Pratik'},1); WriteResult({ "nRemoved" : 1 }) > db.Student.find().pretty(); { "_id" : ObjectId("5b8fad62f00832a0a50b5037"), "Rno" : "2", "Name" : "Abhi", "Class" : "TE COMP" } { "_id" : ObjectId("5b8fad70f00832a0a50b5038"), "Rno" : "3", "Name" : "Ashley", "Class" : "TE COMP"
  • 59. } { "_id" : ObjectId("5b8fad7ff00832a0a50b5039"), "Rno" : "4", "Name" : "Henry", "Class" : "TE COMP" } > db.Student.drop();true > db.Student.find().pretty() { "ok" : 1 } > db.Student.insert({'Rno':'1','Name':'Piyush','Class':'TE COMP'}); WriteResult({ "nInserted" : 1 }) > db.Student.insert({'Rno':'2','Name':'Abhi','Class':'TE COMP'}); WriteResult({ "nInserted" : 1 }) >db.Student.insert({'Rno':'3','Name':'Ashley','Class':'TE COMP'}); WriteResult({ "nInserted" : 1 }) > db.Student.insert({'Rno':'4','Name':'Hitesh','Class':'TE COMP'}); WriteResult({ "nInserted" : 1 }) > db.Student.insert({'Rno':'5','Name':'Pratik','Class':'TE COMP'}); WriteResult({ "nInserted" : 1 }) > db.Student.insert({'Rno':'6','Name':'Pratik','Class':'TE COMP'}); WriteResult({ "nInserted" : 1 }) > db.Student.find(); { "_id" : ObjectId("5ba1d618f5bbacd4ad81568d"), "Rno" : "1", "Name" : "Piyush", "Class" : "TE COMP" } { "_id" : ObjectId("5ba1d625f5bbacd4ad81568e"), "Rno" : "2", "Name" : "Abhi", "Class" : "TE COMP" } { "_id" : ObjectId("5ba1d63af5bbacd4ad81568f"), "Rno" : "3", "Name" : "Ashley", "Class" : "TE COMP" } { "_id" : ObjectId("5ba1d647f5bbacd4ad815690"), "Rno" : "4", "Name" : "Hitesh", "Class" : "TE COMP" } { "_id" : ObjectId("5ba1d65ef5bbacd4ad815691"), "Rno" : "5", "Name" : "Pratik", "Class" : "TE COMP" } { "_id" : ObjectId("5ba1d66df5bbacd4ad815692"), "Rno" : "6", "Name" : "Pratik", "Class" : "TE COMP" } > db.Student.find().pretty(); { "_id" : ObjectId("5ba1d618f5bbacd4ad81568d"), "Rno" : "1", "Name" : "Piyush", "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d625f5bbacd4ad81568e"), "Rno" : "2","Name" : "Abhi", "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d63af5bbacd4ad81568f"), "Rno" : "3", "Name" : "Ashley", "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d647f5bbacd4ad815690"),
  • 60. "Rno" : "4", "Name" : "Hitesh", "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d65ef5bbacd4ad815691"), "Rno" : "5", "Name" : "Pratik", "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d66df5bbacd4ad815692"), "Rno" : "6", "Name" : "Pratik", "Class" : "TE COMP" } > db.Student.update({'Name':'Hitesh'},{$set: {'Name':'Henry'}}); WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1}) > db.Student.find().pretty(); { "_id" : ObjectId("5b8fad4ef00832a0a50b5036"), "Rno" : "1", "Name" : "Piyush", "Class" : "TE COMP" }{ "_id" : ObjectId("5b8fad62f00832a0a50b5037"), "Rno" : "2", "Name" : "Abhi", "Class" : "TE COMP" }{ "_id" : ObjectId("5b8fad70f00832a0a50b5038"), "Rno" : "3", "Name" : "Ashley", "Class" : "TE COMP" }{ "_id" : ObjectId("5b8fad7ff00832a0a50b5039"), "Rno" : "4", "Name" : "Henry", "Class" : "TE COMP" }{ "_id" : ObjectId("5b8fad8df00832a0a50b503a"), "Rno" : "5", "Name" : "Pratik", "Class" : "TE COMP" }{ "_id" : ObjectId("5b8fada4f00832a0a50b503b"),"Rno" : "6", "Name" : "Pratik", "Class" : "TE COMP" } > db.Student.remove({'ADD':'MP'}); WriteResult({ "nRemoved" : 1 }) > db.Student.find().pretty(); { "_id" : ObjectId("5b8fad62f00832a0a50b5037"), "Rno" : "2", "Name" : "Abhi", "Class" : "TE COMP" }{ "_id" : ObjectId("5b8fad70f00832a0a50b5038"), "Rno" : "3",
  • 61. "Name" : "Ashley", "Class" : "TE COMP" }{ "_id" : ObjectId("5b8fad7ff00832a0a50b5039"), "Rno" : "4", "Name" : "Henry", "Class" : "TE COMP" }{ "_id" : ObjectId("5b8fad8df00832a0a50b503a"), "Rno" : "5", "Name" : "Pratik", "Class" : "TE COMP" } {"_id" : ObjectId("5b8fada4f00832a0a50b503b"), "Rno" : "6", "Name" : "Pratik", "Class" : "TE COMP" } >db.Student.save({_id:ObjectId("5b8fad4ef00832a0a50b5036"),"RNO ":"1","NAME":"PIYUSH","CLASS":"TE COMP","ADD":"MP"}); WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1}) > db.Student.find().pretty(); { "_id" : ObjectId("5b8fad4ef00832a0a50b5036"), "RNO" : "1", "NAME" : "PIYUSH", "CLASS" : "TE COMP", "ADD" : "MP" }{ "_id" : ObjectId("5b8fad62f00832a0a50b5037"), "Rno" : "2", "Name" : "Abhi", "Class" : "TE COMP" }{ "_id" : ObjectId("5b8fad70f00832a0a50b5038"), "Rno" : "3", "Name" : "Ashley", "Class" : "TE COMP" }{ "_id" : ObjectId("5b8fad7ff00832a0a50b5039"), "Rno" : "4","Name" : "Henry", "Class" : "TE COMP" }{ "_id" : ObjectId("5b8fad8df00832a0a50b503a"), "Rno" : "5", "Name" : "Pratik", "Class" : "TE COMP" }{ "_id" : ObjectId("5b8fada4f00832a0a50b503b"), "Rno" : "6", "Name" : "Pratik", "Class" : "TE COMP" } > db.Student.find({$and:[{"Name":"Piyush"},{"Rno":"2"}]}); > db.Student.find({$and:[{"Name":"Piyush"}, {"Rno":"1"}]}).pretty(); { "_id" : ObjectId("5ba1d618f5bbacd4ad81568d"),
  • 62. "Rno" : "1", "Name" : "Piyush", "Class" : "TE COMP" } > db.Student.find({$and:[{"Name":"Piyush"},{"Rno":"2"}]}).pretty(); > db.Student.find({$or:[{"Name":"Piyush"},{"Rno":"2"}]}).pretty(); { "_id" : ObjectId("5ba1d618f5bbacd4ad81568d"), "Rno" : "1", "Name" : "Piyush","Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d625f5bbacd4ad81568e"), "Rno" : "2", "Name" : "Abhi", "Class" : "TE COMP" } > db.Student.find({$or:[{"Name":"Piyush"},{"Class":"TE COMP"}]}).pretty(); { "_id" : ObjectId("5ba1d618f5bbacd4ad81568d"), "Rno" : "1", "Name" : "Piyush", "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d625f5bbacd4ad81568e"), "Rno" : "2", "Name" : "Abhi", "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d63af5bbacd4ad81568f"), "Rno" : "3", "Name" : "Ashley", "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d647f5bbacd4ad815690"), "Rno" : "4", "Name" : "Hitesh","Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d65ef5bbacd4ad815691"), "Rno" : "5", "Name" : "Pratik", "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d66df5bbacd4ad815692"), "Rno" : "6", "Name" : "Pratik", "Class" : "TE COMP" } > db.Student.find({$nor:[{"Name":"Piyush"},{"Class":"TE COMP"}]}).pretty(); > db.Student.find({$nor:[{"Name":"Piyush"}, {"Rno":"2"}]}).pretty(); { "_id" : ObjectId("5ba1d63af5bbacd4ad81568f"), "Rno" : "3", "Name" : "Ashley",
  • 63. "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d647f5bbacd4ad815690"), "Rno" : "4", "Name" : "Hitesh", "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d65ef5bbacd4ad815691"),"Rno" : "5", "Name" : "Pratik", "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d66df5bbacd4ad815692"), "Rno" : "6", "Name" : "Pratik", "Class" : "TE COMP" } db.Student.find( {"Rno": { $not:{$lt:"3"}}}).pretty(); { "_id" : ObjectId("5ba1d63af5bbacd4ad81568f"), "Rno" : "3", "Name" : "Ashley", "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d647f5bbacd4ad815690"), "Rno" : "4", "Name" : "Hitesh", "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d65ef5bbacd4ad815691"), "Rno" : "5", "Name" : "Pratik", "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d66df5bbacd4ad815692"), "Rno" : "6","Name" : "Pratik", "Class" : "TE COMP" } > db.Student.find( {"Rno": { $eq:"5"}}).pretty(); { "_id" : ObjectId("5ba1d65ef5bbacd4ad815691"), "Rno" : "5", "Name" : "Pratik", "Class" : "TE COMP" } > db.Student.find( {"Rno": { $ne:"5"}}).pretty(); { "_id" : ObjectId("5ba1d618f5bbacd4ad81568d"), "Rno" : "1", "Name" : "Piyush", "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d625f5bbacd4ad81568e"), "Rno" : "2", "Name" : "Abhi", "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d63af5bbacd4ad81568f"), "Rno" : "3", "Name" : "Ashley", "Class" : "TE COMP" }{
  • 64. "_id" : ObjectId("5ba1d647f5bbacd4ad815690"), "Rno" : "4","Name" : "Hitesh", "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d66df5bbacd4ad815692"), "Rno" : "6", "Name" : "Pratik", "Class" : "TE COMP" } > db.Student.find( {"Rno": { $gt:"5"}}).pretty(); { "_id" : ObjectId("5ba1d66df5bbacd4ad815692"), "Rno" : "6", "Name" : "Pratik", "Class" : "TE COMP" } > db.Student.find( {"Rno": { $gte:"5"}}).pretty(); { "_id" : ObjectId("5ba1d65ef5bbacd4ad815691"), "Rno" : "5", "Name" : "Pratik", "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d66df5bbacd4ad815692"), "Rno" : "6", "Name" : "Pratik", "Class" : "TE COMP" } > db.Student.find( {"Rno": { $lt:"5"}}).pretty(); { "_id" : ObjectId("5ba1d618f5bbacd4ad81568d"),"Rno" : "1", "Name" : "Piyush", "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d625f5bbacd4ad81568e"), "Rno" : "2", "Name" : "Abhi", "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d63af5bbacd4ad81568f"), "Rno" : "3", "Name" : "Ashley", "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d647f5bbacd4ad815690"), "Rno" : "4", "Name" : "Hitesh", "Class" : "TE COMP" } > db.Student.find( {"Rno": { $lte:"5"}}).pretty(); { "_id" : ObjectId("5ba1d618f5bbacd4ad81568d"), "Rno" : "1", "Name" : "Piyush", "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d625f5bbacd4ad81568e"), "Rno" : "2","Name" : "Abhi", "Class" : "TE COMP"
  • 65. }{ "_id" : ObjectId("5ba1d63af5bbacd4ad81568f"), "Rno" : "3", "Name" : "Ashley", "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d647f5bbacd4ad815690"), "Rno" : "4", "Name" : "Hitesh", "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d65ef5bbacd4ad815691"), "Rno" : "5", "Name" : "Pratik", "Class" : "TE COMP" } > db.Student.find( {"Rno": { $lt:"5",$gt:"2"}}).pretty(); { "_id" : ObjectId("5ba1d63af5bbacd4ad81568f"), "Rno" : "3", "Name" : "Ashley", "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d647f5bbacd4ad815690"), "Rno" : "4", "Name" : "Hitesh","Class" : "TE COMP" } > db.Student.find( {"Rno": { $lte:"5",$gte:"2"}}).pretty(); { "_id" : ObjectId("5ba1d625f5bbacd4ad81568e"), "Rno" : "2", "Name" : "Abhi", "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d63af5bbacd4ad81568f"), "Rno" : "3", "Name" : "Ashley", "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d647f5bbacd4ad815690"), "Rno" : "4", "Name" : "Hitesh", "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d65ef5bbacd4ad815691"), "Rno" : "5", "Name" : "Pratik", "Class" : "TE COMP" } > db.Student.find( {"Rno": { $lte:"5",$gt:"2"}}).pretty(); { "_id" : ObjectId("5ba1d63af5bbacd4ad81568f"), "Rno" : "3", "Name" : "Ashley","Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d647f5bbacd4ad815690"), "Rno" : "4", "Name" : "Hitesh", "Class" : "TE COMP" }{
  • 66. "_id" : ObjectId("5ba1d65ef5bbacd4ad815691"), "Rno" : "5", "Name" : "Pratik", "Class" : "TE COMP" } > db.Student.find( {"Rno": { $lt:"5",$gte:"2"}}).pretty(); { "_id" : ObjectId("5ba1d625f5bbacd4ad81568e"), "Rno" : "2", "Name" : "Abhi", "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d63af5bbacd4ad81568f"), "Rno" : "3", "Name" : "Ashley", "Class" : "TE COMP" }{ "_id" : ObjectId("5ba1d647f5bbacd4ad815690"), "Rno" : "4", "Name" : "Hitesh", "Class" : "TE COMP"} RESULT Thus the CRUD operation in NoSQL database MongoDB has been successfully executed.
  • 67. EXPERIMENT – 11 VIVA QUESTIONS 1. What is a NoSQL database, and how does it differ from traditional relational databases? NoSQL databases are non-relational databases designed to handle large volumes of unstructured or semi- structured data. They differ from traditional relational databases by not using a fixed schema and offering flexible data models. 2. How do NoSQL databases handle date and time data? NoSQL databases typically store date and time data in various formats, such as ISO 8601, Unix timestamps, or as native date types. The specific approach depends on the database type and the data model it supports. 3. Give an example of a NoSQL database that excels in handling time-series data. One example is InfluxDB, which is known for its efficient handling of time-series data, making it suitable for applications involving metrics, monitoring, and IoT data. 4. Explain how MongoDB represents date and time data. MongoDB represents date and time data using the BSON data type called ISODate. It stores date and time in UTC format and allows for querying and indexing based on time. 5. What is Apache Cassandra, and how does it handle date-related data? Apache Cassandra is a distributed NoSQL database. It typically stores date and time data as timestamps in microseconds or milliseconds, depending on the configuration. It provides flexibility in handling time-related data. 6. How does CouchDB handle date and time information? CouchDB stores date and time information as strings in JSON documents. It is left to the application to choose the appropriate date format, allowing flexibility in representing time. 7. In a time-series database like OpenTSDB, how is time represented? OpenTSDB represents time as Unix timestamps (in seconds or milliseconds), providing a convenient way to work with time-series data and allowing for efficient storage and retrieval. 8. Can you explain how a graph database like Neo4j deals with date information? Neo4j does not have a native date data type, but dates can be stored as properties with appropriate formats ( e.g., strings or numeric representations). Date-related queries can then be executed using the Cypher query language. 9. How do NoSQL databases handle the indexing of date fields? NoSQL databases often provide indexing mechanisms for date fields to optimize query performance. Indexing can be based on specific date attributes or the entire timestamp, depending on the database. 10. Discuss the challenges and advantages of handling date and time data in NoSQL databases. Challenges may include consistency across distributed systems, while advantages include flexibility in data models, scalability, and efficient handling of time-series data.
  • 68. EX.NO:12 GUI BASED DATABASE APPLICATIONS DATE: AIM: To implement an online exam registration page with database connectivity using php ALGORITHM: STEP 1: Develop a webpage which includes all the fields for registering for an online exam STEP 2: Develop a PHP page which receives the values that are given as an input in the registration page STEP 3: Connect the registration page with the PHP page STEP 4: Receive the values from registration page STEP 5: Establish a connection with the database STEP 6: Store the received values in the database PROGRAM: Registration.html <html> <body bgcolor="lightblue"> <p><center>REGISTRATION FORM</center></p> <form action="Registration.php" method="post"> <center><pre><b> Student name: <input type="text" name="n" value=" "> Register Number: <input type="text" name="reg" value=" "> CGPA: <input type="text" name="cgpa" value=" "> YEAR: <input type="text" name="y" value=" "> Branch: <input type="text" name="branch" value=" "> <input type="submit" name="button" value="SUBMIT"> </b></center></pre> </body> </html> Registration.php <?php $servername = "localhost"; $username = "root"; $password = ""; $dbname = "Online_exam"; $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } /*else echo "Connection established";*/ $Name=$_POST['n']; $RegNo=$_POST['reg'];
  • 69. $CGPA=$_POST['cgpa']; $Year=$_POST['y']; $Branch=$_POST['branch']; /*echo $Name; echo $RegNo; echo $CGPA; echo $Year; echo $Branch;*/ $sql = "CREATE TABLE regDetails(Name varchar(30) not null, RegNo int(15) not null,CGPA float not null, Year varchar(5) not null, Branch varchar(5) not null)"; if ($conn->query($sql) === TRUE) { echo "Table regDetails created successfully"; } else { echo "Error creating table: " . $conn->error; } $sql = "INSERT INTO regDetails (Name,RegNo,CGPA,Year,Branch) VALUES ('$Name',$RegNo,$CGPA,'$Year','$Branch')"; if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } $conn->close(); ?> RESULT: Thus the real life database application for exam registration has been successfully executed.
  • 70. EXPERIMENT – 12 VIVA QUESTIONS 1. What is a GUI-based database application? A GUI-based database application is a software application that provides a graphical user interface (GUI) for users to interact with a database. It allows users to perform database operations, such as querying, inserting, updating, and deleting records, using visual elements 2. How does a GUI-based database application differ from a command-line interface (CLI) application? A GUI-based application uses graphical elements like buttons, forms, and menus to interact with the database, providing a more user-friendly and visually intuitive experience compared to a command-line interface that relies on text commands. 3. What are the advantages of using a GUI for database applications? GUIs offer advantages such as ease of use, reduced learning curve, visual representation of data, and the ability to provide feedback to users through interactive elements, enhancing the overall user experience. 4. Can you name a popular GUI-based database application development tool? Examples include Microsoft Access, Oracle Forms, and File-Maker Pro. 5. How does a user typically interact with a GUI-based database application? Users interact with a GUI-based database application by clicking buttons, filling out forms, selecting options from menus, and manipulating visual elements to perform various database operations. 6. Explain the concept of data binding in the context of GUI-based database applications. Data binding is the process of connecting the user interface elements (such as text boxes or tables) directly to the underlying database, allowing changes in the UI to be reflected in the database and vice versa. 7. What is the role of forms in GUI-based database applications? Forms in GUI-based database applications serve as a means for users to input and view data. They typically consist of fields corresponding to database columns, and users interact with these forms to perform operations on the data. 8. How can GUI-based applications handle database transactions? GUI-based applications often provide transaction management features, allowing users to initiate and commit transactions or roll back changes. This ensures data consistency and integrity. 9. Discuss the importance of validation in GUI-based database applications. Validation in GUI-based applications is crucial to ensure that data entered by users meets specified criteria. This helps maintain data integrity and prevents the insertion of incorrect or inconsistent information into the database. 10. What is view in sql? In SQL, a view is a virtual table based on the result-set of an SQL statement. A view contains rows and columns, just like a real table. The fields in a view are fields from one or more real tables in the database.
  • 71. EX.NO:13 DATABASE DESIGN USING ER MODELING, NORMALIZATION AND DATE : IMPLEMENTATION FOR ANY APPLICATION AIM: To implement Database Design using ER modeling, normalization for an application ALGORITHM: STEP 1: Create a database schema for an application STEP 2: Draw an E-R diagram for the schema STEP 3: Check for atomic values and change it to first normal form STEP 4: Check for functional dependency and modify the schema to second normal form STEP 5: Check for transitive dependency and convert to third normal form STEP 6: Check that every determinant is a candidate key and convert to Boyce Codd normal form STEP 7: Check for multi-valued dependency and change it to fourth normal form STEP 8: Check whether the table is fully normalized First Normal Form:  It should only have single(atomic) valued attributes/columns.  Values stored in a column should be of the same domain  All the columns in a table should have unique names Changing it to 1NF: Second Normal Form (2NF) For a table to be in the Second Normal Form, 1. It should be in the First Normal form. 2. And, it should not have Partial Dependency.
  • 72. Changing it to 2NF: Student: Subject: Score: Third Normal Form (3NF) For a table to be in the third normal form, 1. It should be in the Second Normal form. 2. And it should not have Transitive Dependency.
  • 73. RESULT: Thus normalization has been implemented for student database successfully
  • 74. EXPERIMENT – 13 VIVA QUESTIONS 1. What is ER modeling, and why is it important in database design? ER modeling is a graphical representation technique used to model the data requirements and relationships in a system. It's essential in database design to visually depict entities, their attributes, and the relationships between them. 2. Explain the key components of an ER diagram. The key components of an ER diagram include entities, attributes, relationships, and cardinality. Entities represent real-world objects, attributes are properties of entities, relationships describe associations between entities, and cardinality defines the numerical relationship between entities in a relationship. 3. How do you represent a one-to-many relationship in an ER diagram? In an ER diagram, a one-to-many relationship is represented by drawing a line connecting the entities involved in the relationship and adding a crow's foot notation on the "many" side. 4. What is the purpose of carnality in an ER diagram? Carnality in an ER diagram defines the number of instances of one entity that can be associated with the number of instances of another entity in a relationship. It helps specify the nature and constraints of the relationship. 5. Can an entity have more than one key attribute? Yes, an entity can have multiple key attributes, and these are often referred to as composite keys. Composite keys are useful when a single attribute cannot uniquely identify an entity. 6. What is the difference between a superkey and a candidate key? A superkey is a set of one or more attributes that, taken collectively, uniquely identifies an entity. A candidate key is a minimal superkey, meaning no subset of it can uniquely identify an entity. 7. How does normalization help in reducing data redundancy? Normalization reduces data redundancy by organizing data in such a way that each piece of information is stored in only one place. This eliminates the need to update multiple copies of the same data, reducing the risk of inconsistencies 8. Explain the concept of transitive dependency. Transitive dependency occurs when a non-prime attribute is functionally dependent on another non-prime attribute rather than the primary key. Normalization aims to eliminate transitive dependencies. 9. What is the role of SQL in database implementation? SQL (Structured Query Language) is used for implementing, querying, and managing relational databases. It provides commands for creating tables, defining relationships, inserting, updating, and retrieving data. 10. How do you create a table in a relational database using SQL? You create a table in SQL using the CREATE TABLE statement, specifying the table name and its columns along with their data types and constraints.