Dbms Laboratory Mannual (Final)
Dbms Laboratory Mannual (Final)
REGULATION 2021
WRITE EVERYTHING...
DBMS LABORATORY MANNUAL
LIST OF EXPERIMENTS:
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, equip and outer joins.
8. Write SQL Triggers for insert, delete, and update operations in a database table.
9. Create View and index for database tables with many records.
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 – Email
e) Star Small and Medium Banking and Finance ● Build Entity Model diagram.
EXPERIMENT 1
AIM:
To create a database table, add constraints (primary key, unique, check, not null),
insert rows, update, and delete rows using SQL DDL and DML commands.
QUIERIES:
Insert into students (id, name, age) values (‘1.’, ‘ABC’, ‘90’);
Insert into students (id, name, age) values (‘2.’, ‘DEF’, ‘91’);
Insert into students (id, name, age) values (‘3.’, ‘GHI’, ‘92’);
Insert into students (id, name, age) values (‘4.’, ‘JKL’, ‘93’);
Thus the database table with constraints and row operations have been
successfully executed.
EXPERIMENT 2
AIM:
To create a set of tables, add foreign key constraints and incorporate referential
integrity.
QUIERIES:
RESULT:
Thus the set of tables with foreign key constraints and referential integrity have
been successfully executed.
EXPERIMENT 3
AIM:
To query the database tables using different ‘where’ clause conditions and also
implement aggregate functions.
QUIERIES:
RESULT:
Thus the database using where conditions was successfully executed.
EXPERIMENT 4
AIM:
To query the database tables and explore sub queries and simple join operations.
QUEIRES:
RESULT:
Thus the database table with sub queries and simple joins were successfully
executed.
EXPERIMENT 5
AIM:
To query the database tables and explore natural, equip and outer joins.
QUEIRES:
SELECT *
FROM orders
NATURAL JOIN customers;
SELECT emp_name, salary, dept_name
FROM employees, departments
WHERE employees.dept_id = departments.dept_id;
SELECT *
FROM students
FULL OUTER JOIN courses
ON students.course_id = courses.course_id;
RESULT:
Thus the database table with natural, equi - and outer join has been successfully
explored.
EXPERIMENT 6
AIM:
QUEIRES:
-- Example usage:
SELECT dbo.add_numbers(3, 5)
-- Output:
Stored procedures:
-- This stored procedure takes in a customer ID and returns their name
and order history:
-- Example usage:
EXEC get_customer_order_history @customer_id = 1234
-- Output:
RESULT:
Thus the User defined functions and stored procedures in SQL were successfully
executed.
EXPERIMENT 7
AIM:
QUEIRES:
To create a new user in the database, you can use the following DCL
command:
To grant privileges to the new user, you can use the following DCL
command:
Now, let's say you want to create a new table in the database. You can use
the following TCL command:
USE example_db;
CREATE TABLE example_table (
id INT(11) NOT NULL AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
age INT(11) NOT NULL,
PRIMARY KEY (id)
);
To insert data into the new table, you can use the following TCL
command:
To select data from the new table, you can use the following TCL
command:
Thus the Execution of complex transactions and realize DCL and TCL
commands was done successfully.
EXPERIMENT 8
AIM:
To write SQL Triggers for insert, delete, and update operations in a database
table.
QUEIRES:
Insert Trigger:
Delete trigger:
Update Trigger:
CREATE TRIGGER employees_update_trigger
AFTER UPDATE ON employees
FOR EACH ROW
BEGIN
INSERT INTO employee_audit (action, employee_id, first_name,
last_name, age, salary)
VALUES ('UPDATE', NEW.id, NEW.first_name,
NEW.last_name, NEW.age, NEW.salary);
END;
RESULT:
Thus the SQL Triggers for insert, delete, and update operations in a database
table were executed successfully.
EXPERIMENT 9
AIM:
To create View and index for database tables with a large number of records.
QUEIRES:
Index Creation:
RESULT:
Thus the View and index for database tables with a large number of records were
successfully executed.
EXPERIMENT 10
AIM:
QUEIRES:
Let's assume we want to create a database of books. Each book will have
a title, author, publication year, and ISBN. Here's an example XML file
that contains information on three books:
Now that we have our XML database, we can create an XML schema to
validate it. An XML schema is a document that defines the structure,
content, and data types of an XML document. Here's an example XML
schema that we can use to validate our books database:
<xs:element name="books">
<xs:complexType>
<xs:sequence>
<xs:element name="book" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="author" type="xs:string"/>
<xs:element name="year" type="xs:integer"/>
<xs:element name="isbn" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
To validate our XML database against this schema, we can use an XML
validation tool like xmllint. Here's how to do it in the command line:
RESULT:
Thus the XML database and validate it using XML schema were successfully
executed.
EXPERIMENT 11
AIM:
Tocreate Document, column and graph-based data using NOSQL database tools.
QUEIRES:
// Connect to MongoDB
constMongoClient = require('mongodb').MongoClient;
consturi = "mongodb+srv://<username>:<password>@<cluster-
address>/test?retryWrites=true&w=majority";
const client = new MongoClient(uri, { useNewUrlParser: true });
client.connect(err => {
const collection = client.db("test").collection("books");
// Insert a document
collection.insertOne({
title: "The Great Gatsby",
author: "F. Scott Fitzgerald",
year: 1925,
isbn: "9780141182636"
}, function(err, result) {
console.log("Inserted document");
client.close();
});
});
// Connect to Cassandra
constcassandra = require('cassandra-driver');
const client = new cassandra.Client({ contactPoints: ['localhost'],
localDataCenter: 'datacenter1', keyspace: 'mykeyspace' });
client.connect(function(err, result) {
if(err) {
console.log('Error connecting to Cassandra:', err);
} else {
console.log('Connected to Cassandra');
// Create a table
const query = "CREATE TABLE books (id uuid PRIMARY KEY,
title text, author text, year int, isbn text)";
client.execute(query, function(err, result) {
if(err) {
console.log('Error creating table:', err);
} else {
console.log('Created table');
// Insert data into the table
const query = "INSERT INTO books (id, title, author, year, isbn)
VALUES (?, ?, ?, ?, ?)";
const params = [cassandra.types.Uuid.random(), "The Great
Gatsby", "F. Scott Fitzgerald", 1925, "9780141182636"];
client.execute(query, params, function(err, result) {
if(err) {
console.log('Error inserting data:', err);
} else {
console.log('Inserted data');
client.shutdown();
}
});
}
});
}
});
Once the query has finished executing, you can run a simple query
to retrieve all of the people in the graph:
Output:
╒════════════════════════════════════════════════════════════════════════════════╕
│f │
╞════════════════════════════════════════════════════════════════════════════════╝
RESULT:
Thus the Document, column and graph-based data using NOSQL database
tools were successfully executed.
EXPERIMENT 12
AIM:
To develop a simple GUI based database application and incorporate all the
above-mentioned features.
QUEIRES:
Once you have installed the required libraries, you can proceed with the
following steps:
First, we will create a simple GUI that allows the user to enter the
details of a person and add them to the graph database. We will use
a Tkinter form with input fields for the person's name, age, and
gender.
import tkinter as tk
from neo4j import GraphDatabase
class Application(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.pack()
self.create_widgets()
def create_widgets(self):
self.name_label = tk.Label(self, text="Name:")
self.name_label.pack(side="left")
self.name_entry = tk.Entry(self)
self.name_entry.pack(side="left")
def add_person(self):
name = self.name_entry.get()
age = int(self.age_entry.get())
gender = self.gender_entry.get()
root = tk.Tk()
app = Application(master=root)
app.mainloop()
The above code creates a simple GUI form with input fields for the
person's name, age, and gender. It also includes a button that, when
clicked, adds the person to the graph database using the Neo4j
driver.
Next, we will create a feature that allows the user to view all the
people in the database. We will create a new button that, when
clicked, retrieves all the people from the database and displays
them in a new window:
class Application(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.pack()
self.create_widgets()
def create_widgets(self):
self.name_label = tk.Label(self, text="Name:")
self.name_label.pack(side="left")
self.name_entry = tk.Entry(self)
self.name_entry.pack(side="left")
RESULT:
Thus the simple GUI based database application and incorporate all the above-
mentioned features was created and executed successfully.