Finaldbmsmanual2-240516070243-6d8ac4b6 (1) - Removed
Finaldbmsmanual2-240516070243-6d8ac4b6 (1) - Removed
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
8. TRIGGERS CO3
8. TRIGGERS
AIM:
To implement database creation and do the operations in database using Data Definition
Commands
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:
Example:
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
Example:
alter table employee add (state varchar(100),weight float);
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.
Example:
alter table employee rename to empl;
table employee altered.
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:
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
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;
Example:
insert into student values(3,’alex’,default);
1 rows inserted.
select * from student;
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)
4) DELETE
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')
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
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;
Step 3:
RESULT:
Thus the SQL query the database tables with different 'where clause' conditions also
implement aggregate function are executed successfully.
EXPERIMENT – 3
VIVA QUESTIONS
AIM:
To implement Simple queries, Nested queries, Sub queries using structured query
language
ALGORITHM:
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;
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:
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%';
IN
select * from salary where age in ( 25, 28 );
BETWEEN
select * from salary where salary between 20000 and 30000;
IS NOT NULL
IS NULL
(4,'Kumaran',25,'CBE',24000);
UPDATE CUSTOMERS
SET SALARY = SALARY * 0.25
WHERE AGE IN
(SELECT AGE FROM customers_backup
WHERE AGE >= 27 );
Select * from customers;
Subqueries with the DELETE Statement
JOINS
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:
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:
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
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
SQL> select
employee.empid,employee.name,employee.depid,department.deptname,depa
rtment.location from employee,department where
employee.depid=department.depid;
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';
7 rows selected.
2. Write a query to display the name, salary,depid and deptname of
all employees. Make sure 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;
RESULT:
Thus the SQL commands to execute natural, equi and outer joins are executed successfully.
EXPERIMENT – 5
VIVA QUESTIONS
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.
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:
BEGIN
greetings;
END;
DELETING A PROCEDURE
SYNTAX:
EXAMPLE:
Procedure dropped
EXAMPLE 2
BEGIN
INSERTUSER(101,'Rahul');
dbms_output.put_line('record inserted successfully');
END;
PL/SQL FUNCTIONS
SYNTAX:
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
AIM:
To implement Transaction Control statements using structured Query Language
ALGORITHM:
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);
commit;
Statement executed
savepoint a;
savepoint created
savepoint b;
rollback to a;
RESULT:
Thus Transaction Control and Data Control statements using structured Query Language is
executed successfully
EXPERIMENT – 7
VIVA QUESTIONS
AIM:
To implement PL/SQL triggers and do the operations in database automatically.
ALGORITHM:
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;
RESULT:
Thus the SQL triggers are executed successfully.
EXPERIMENT – 8
VIVA QUESTIONS
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:
OUTPUT:
View created.
SQL> select * from vw_emp80;
ID NAME SALARY
RESULT:
Thus the PL/SQL program for implementing views and index has been successfully executed.
EXPERIMENT – 9
VIVA QUESTIONS
AIM:
PROGRAM
CREATE TABLE t1 (
id NUMBER,
xml XMLTYPE
);
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
Aim:
To design and develop MongoDB queries using CRUD operations.
Algorithm:
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':'3','Name':'Ashley','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.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"
}
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)";
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:
Changing it to 1NF:
Subject:
Score:
Changing it to 2NF: