Manual Cs3481database Management Systems Laboratory
Manual Cs3481database Management Systems Laboratory
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, equi 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 a large number of 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
● Build Entity Model diagram. The diagram should align with the business and functional
● Prepared applicable views, triggers (for auditing purposes), functions for enabling
● 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
Ex No:1Create a database table, add constraints (primary key, unique, check, Not null), insert rows,
update and delete rows using SQL DDL and DML commands.
Aim :
Procedure
Create a database
Create a table
Insert the values into table
USE ALTER,DELETE and UPDATE Command
Creating a Database
Creating a Table
alter command is used for altering the table structure, such as,
ALTER command can also be used to drop or remove columns. ALTER TABLE
table_name DROP(column_name);
TRUNCATE query
RENAME query
RENAME command is used to set a new name for any existing table. RENAME TABLE
old_table_name to new_table_name;
DML COMMAND
Data Manipulation Language (DML) statements are used for managing data in database. DML
commands are not auto-committed. It means changes made by DML command are not permanent
to database, it can be rolled back.
INSERT command
Insert command is used to insert data into a table. Following is its general syntax,
The above SQL query will only insert id and name values in the newly inserted record.
Both the statements below will insert NULL value into age column of the student
table.
Or,
INSERT INTO Student VALUES(102,'Alex', null);
The above command will insert only two column values and the other column is set to null.
Suppose the column age in our tabel has a default value of 14.
Also, if you run the below query, it will insert default value into the age column, whatever the
default value may be.
UPDATE command
In the above statement, if we do not use the WHERE clause, then our update query will update
age for all the columns of the table to 18.
The above command will update two columns of the record which has s_id 103.
DELETE command
DELETE FROM table_name;
101 Adam 15
102 Alex 18
103 Abhi 17
The above command will delete the record where s_id is 103 from the table student.
The SQL SELECT statement is used to fetch the data from a database table which returns this
data in the form of a result table. These result tables are called result-sets.
Syntax
Here, column1, column2... are the fields of a table whose values you want to fetch. If you want to
fetch all the fields available in the field, then you can use the following syntax.
The following code is an example, which would fetch the ID, Name and Salary fields of the
customers available in CUSTOMERS table.
If you want to fetch all the fields of the CUSTOMERS table, then you should use the following
query.
VIVA QUESTIONS:
1. Differentiate DDL and DML commands
2. What is the use of select command?
3. Difference between alter and update command
4. How will you delete a column from table?
5. Difference between drop and truncate command
6. Explain different ways to insert rows in a table.
Ex.No:2 Foreign Key And Referential Integrity Constraints
Aim
To create a set of tables and add foreign key and referential integrity constraints.
Procedure
Step 1:Start
Step 2:Create Table Department and Employee with necessary Step 3:Add Foreign
Step 5: Stop
Department
Employees
Output
ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constrai
VIVA QUESTIONS:
Procedure
Step 1: Start
Step 4:stop
WHERE Clause
Syntax:
+----+----------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 6 | Komal | 22 | MP | 4500.00 |
| 7 | Muffy | 24 | Indore | 10000.00 |
+----+----------+-----+-----------+----------+
+----+--------+-----+---------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+--------+-----+---------+----------+
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 7 | Muffy | 24 | Indore | 10000.00 |
+----+--------+-----+---------+----------+
+----+--------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+--------+-----+-----------+----------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 7 | Muffy | 24 | Indore | 10000.00 |
+----+--------+-----+-----------+----------+
AGGREGATE FUNCTIONS
Item1 Com1 2 10 20
Item2 Com2 3 25 75
Item3 Com1 2 30 60
Item4 Com3 5 10 50
Item5 Com2 2 20 40
Item6 Cpm1 3 25 75
Item8 Com1 3 10 30
Item9 Com2 2 25 50
COUNT FUNCTION
Syntax
select count(*) from product_mast;
Output:
10
SUM FUNCTION
Syntax
select sum(cost) from product_mast;
Output:
670
AVG FUNCTION
Syntax
select avg(cost) from product_mast;
Output:
67.00
MAX FUNCTION
Syntax
select max(rate) from product_mast;
Output:
30
MIN FUNCTION
Syntax
select min(rate) from product_mast;
Output:
10
RESULT
Thus the queries were executed successfully.
VIVA QUESTIONS:
1. What is the use of where clause?
2. What is the use of count function?
3. What is the use of sum function?
4. How will you find the small and large value in a table?
5. How will you find the average value in a table?
Ex no 4: Query the Database Tables and Explore Sub Queries and Simple Join Operations.
Aim:
To create a sub queries and simple join operations.
Procedure
Step 1: Start
Step 4:stop
Syntax
Example
Consider the following two tables.
Table 1 − CUSTOMERS Table is as follows.
+----+----------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 6 | Komal | 22 | MP | 4500.00 |
| 7 | Muffy | 24 | Indore | 10000.00 |
+----+----------+-----+-----------+----------+
+-----+---------------------+-------------+--------+
| OID | DATE | CUSTOMER_ID | AMOUNT |
+-----+---------------------+-------------+--------+
| 102 | 2009-10-08 00:00:00 | 3| 3000 |
| 100 | 2009-10-08 00:00:00 | 3| 1500 |
| 101 | 2009-11-20 00:00:00 | 2| 1560 |
| 103 | 2008-05-20 00:00:00 | 4| 2060 |
+-----+---------------------+-------------+--------+
Now, let us join these two tables using the INNER JOIN as follows −
SQL> SELECT ID, NAME,
AMOUNT, DATE FROM
CUSTOMERS
INNER JOIN ORDERS
ON CUSTOMERS.ID = ORDERS.CUSTOMER_ID;
This would produce the following result.
+----+----------+--------+---------------------+
| ID | NAME | AMOUNT | DATE |
+----+----------+--------+---------------------+
| 3 | kaushik | 3000 | 2009-10-08 00:00:00 |
| 3 | kaushik | 1500 | 2009-10-08 00:00:00 |
| 2 | Khilan | 1560 | 2009-11-20 00:00:00 |
| 4 | Chaitali | 2060 | 2008-05-20 00:00:00 |
+----+----------+--------+---------------------+
SQL - LEFT JOINS
Syntax
The basic syntax of a LEFT JOIN is as follows.
SELECT table1.column1, table2.column2...
FROM table1
LEFT JOIN table2
ON table1.common_field = table2.common_field;
Example
Consider the following two tables,
The SQL RIGHT JOIN returns all rows from the right table, even if there are no matches in the
left table. This means that if the ON clause matches 0 (zero) records in the left table; the join will
still return a row in the result, but with NULL in each column from the left table.
Syntax
The basic syntax of a RIGHT JOIN is as follow.
SELECT table1.column1, table2.column2...
FROM table1
RIGHT JOIN table2
ON table1.common_field = table2.common_field;
Table 1 − CUSTOMERS Table is as follows.
+----+----------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 6 | Komal | 22 | MP | 4500.00 |
| 7 | Muffy | 24 | Indore | 10000.00 |
+----+----------+-----+-----------+----------+
Table 2 − ORDERS Table is as follows.
+-----+---------------------+-------------+--------+
|OID | DATE | CUSTOMER_ID | AMOUNT |
+-----+---------------------+-------------+--------+
| 102 | 2009-10-08 00:00:00 | 3| 3000 |
| 100 | 2009-10-08 00:00:00 | 3| 1500 |
| 101 | 2009-11-20 00:00:00 | 2| 1560 |
| 103 | 2008-05-20 00:00:00 | 4| 2060 |
+-----+---------------------+-------------+--------+
Now, let us join these two tables using the RIGHT JOIN as follows.
SQL> SELECT ID, NAME,
AMOUNT, DATE FROM
CUSTOMERS
RIGHT JOIN ORDERS
ON CUSTOMERS.ID = ORDERS.CUSTOMER_ID;
This would produce the following result −
+------+----------+--------+---------------------+
| ID | NAME | AMOUNT | DATE |
+------+----------+--------+---------------------+
| 3 | kaushik | 3000 | 2009-10-08 00:00:00 |
| 3 | kaushik | 1500 | 2009-10-08 00:00:00 |
| 2 | Khilan | 1560 | 2009-11-20 00:00:00 |
| 4 | Chaitali | 2060 | 2008-05-20 00:00:00 |
+------+----------+--------+---------------------+
SQL - FULL JOINS
The SQL FULL JOIN combines the results of both left and right outer joins.
Syntax
The basic syntax of a FULL JOIN is as follows −
SELECT table1.column1, table2.column2...
FROM table1
FULL JOIN table2
ON table1.common_field = table2.common_field;
Table 1 − CUSTOMERS Table is as follows.
+----+----------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 6 | Komal | 22 | MP | 4500.00 |
| 7 | Muffy | 24 | Indore | 10000.00 |
+----+----------+-----+-----------+----------+
Table 2 − ORDERS Table is as follows.
+-----+---------------------+-------------+--------+
|OID | DATE | CUSTOMER_ID | AMOUNT |
+-----+---------------------+-------------+--------+
| 102 | 2009-10-08 00:00:00 | 3| 3000 |
| 100 | 2009-10-08 00:00:00 | 3| 1500 |
| 101 | 2009-11-20 00:00:00 | 2| 1560 |
| 103 | 2008-05-20 00:00:00 | 4| 2060 |
+-----+---------------------+-------------+--------+
Now, let us join these two tables using FULL JOIN as follows.
SQL> SELECT ID, NAME,
AMOUNT, DATE FROM
CUSTOMERS
FULL JOIN ORDERS
ON CUSTOMERS.ID = ORDERS.CUSTOMER_ID;
+------+----------+--------+---------------------+
| ID | NAME | AMOUNT | DATE |
+------+----------+--------+---------------------+
| 1 | Ramesh | NULL | NULL |
| 2 | Khilan | 1560 | 2009-11-20 00:00:00 |
| 3 | kaushik | 3000 | 2009-10-08 00:00:00 |
| 3 | kaushik | 1500 | 2009-10-08 00:00:00 |
| 4 | Chaitali | 2060 | 2008-05-20 00:00:00 |
| 5 | Hardik | NULL | NULL |
| 6 | Komal | NULL | NULL |
7 | Muffy | NULL | NULL |
| 3 | kaushik | 3000 | 2009-10-08 00:00:00 |
| 3 | kaushik | 1500 | 2009-10-08 00:00:00 |
| 2 | Khilan | 1560 | 2009-11-20 00:00:00 |
| 4 | Chaitali | 2060 | 2008-05-20 00:00:00 |
+------+----------+--------+---------------------+
RESULT:
Thus the queries were executed successfully.
VIVA QUESTIONS:
1. Define Join.
2. List out different types of join
3. Write the syntax for inner join.
4. Difference between inner and outer join.
5. Use of full join.
Ex.No :5 Natural Join, Equi Join And Outer Join
Aim
To write a query to perform natural join , equi join and outer join.
Procedure
Step 1: Start
Step 3: Perform natural join,equi join and outer join operations with queries.
Step 4: Stop
Syntax:
Table-1: department
1 Sumit Hr
2 Joel It
3 Biswa Marketing
4 Vaibhav It
5 Sagar Sales
Table-2: mployee –
It Rohan
Sales Rahul
Hr Tanmay
Finance Ashish
Marketing Samay
Natural Join :
1 Sumit Hr Tanmay
2 Joel It Rohan
4 Vaibhav It Rohan
EQUI JOIN
CATEGORY_ID CATEGORY_NAME
1 Mobiles
2 Laptops
3 Laptops
4 Cameras
5 Gaming
select * from product;
CATEGORY_ID PRODUCT_NAME
1 Nokia
1 Samsung
2 HP
2 Dell
3 Apple
4 Nikon
Null Playstation
SQL> select *
from product join category
on product.category_id = category.category_id;
CATEGORY_ID PRODUCT_NAME CATEGORY_ID CATEGORY_NAME
----------- --------------------- ----------- --------------------- --------------------- ---------------------
1 Nokia 1 Mobiles
1 Samsung 1 Mobiles
2 HP 2 Laptops
2 Dell 2 Laptops
3 Apple 3 Tablet
4 Nikon 4 Cameras
6 rows selected.
OUTER JOIN
1 Aryan 51 56000
2 Arohi 21 25000
3 Vineet 24 31000
4 Ajeet 23 32000
5 Ravi 23 42000
ORDER TABLE:
O_ID DATE CUSTOMER_ID AMOUNT
TABLE_A
A M
1 m
2 n
4 o
TABLE_B
A N
2 p
3 q
5 r
RESULTING TABLE
A M A N
2 n 2 p
1 m - -
4 o - -
- - 3 q
- - 5 r
RESULT
VIVA QUESTIONS:
1. Define Join.
2. What is the use of Equi join?
3. Define Natural Join.
4. Difference between inner and outer join.
5. Use of full join.
60%.
Algorithm
STEP 1:Start
STEP 3:Insert the values into the table and Calculate total and average of each student
STEP 4: Execute the procedure function the student who get above 60%.
STEP 6: End
Program:
Output
Procedure created.
Table created
SQL> insert into student values (101,'priya', 78, 88,77,60,89); 1
row created.
SQL> insert into student values (102,'surya', 99,77,69,81,99);
1 row created.
SQL> insert into student values (103,'suryapriya', 100,90,97,89,91);
1 row created.
SQL> select * from student;
101 priya 78 88 77 60 89
102 surya 99 77 69 81 99
103 suryapriya 100 90 97 89 91
SQL> declare
2 ave number(5,2);
3 tot number(3);
4 cursor c_mark is select*from student where mark1>=40 and mark2>=40 and
5 mark3>=40 and mark4>=40 and mark5>=40;
6 begin
7 dbms_output.put_line('regno name mark1 mark2 mark3 mark4 mark4 mark5 total
8 average');
9 dbms_output.put_line(' ');
10 for student in c_mark
11 loop
12 tot:=student.mark1+student.mark2+student.mark3+student.mark4+student.mark5;
13 ave:=tot/5;
14 dbms_output.put_line(student.regno||rpad(student.name,15)
15 ||rpad(student.mark1,6)||rpad(student.mark2,6)||rpad(student.mark3,6)
16 ||rpad(student.mark4,6)||rpad(student.mark5,6)||rpad(tot,8)||rpad(ave,5));
17 end loop;
18 end;
19 /
OUTPUT
Aim To write a Functional procedure to search an address from the given database.
Procedure
STEP 1: Start
STEP 4: Frame the searching procedure for both positive and negative searching.
STEP 5: Execute the Function for both positive and negative result .
STEP 6: Stop
SQL> create table phonebook (phone_no number (6) primary key,username varchar2(30),doorno
varchar2(10),
street varchar2(30),place varchar2(30),pincode char(6));
Table created.
1 row created.
1 row created.
Function created.
SQL>declare
2 address varchar2(100);
3 begin
4 address:=findaddress(20312);
5 dbms_output.put_line(address);
6 end;
7/
Output
Result
VIVA QUESTIONS:
1. Define PL/SQL.
2. Define procedure.
3. Use of select command
4. Define function.
5. Define procedure.
Ex.No:7 DCL And TCL Commands
Aim
Step 1: Start
Stop.
DCL COMMANDS
GRANT
SAVEPOINT S1;
Savepoint created.
1 row created.
Rollback complete.
COMMIT
SQL> COMMIT;
Commit complete.
Result
VIVA QUESTIONS:
1. List out the command under DCL.
2. List out commands under TCL.
3. Explain the use grant and revoke command
4. What is the use of Rollback command.
5. Purpose of save point.
Ex.No:8 Creation of Database Triggers
Aim
Procedure
Syntax
create or replace trigger trigger name [before/after] {DML
statements} on [table name] [for each row/statement]
begin
exception
end;
PROGRAM
SQL>create table poo(rno number(5),name
varchar2(10)); Table created.
SQL>insert into poo values
(01.‟kala‟); 1 row created.
SQL>select * from poo;
RNO NAME
------ ----------
1 kala
2 priya
SQL>create or replace trigger pool before insert on poo for each row
2 declare
3 rno poo.rno%type
4 cursor c is select rno from
poo; 5 begin
6 open c;
7 loop;
8 fetch c into rno;
9 if:new.rno=rno then
10 raise_application_error(-20005,‟rno already exist‟);
11 end if;
12 exit when c%NOTFOUND
13 end loop;
14 close c;
15 end;
16 /
Trigger created.
OUTPUT
SQL>insert into poo
values(01,‟kala‟) Insert into poo
values (01,‟kala‟)
*
ERROR at line1:
ORA-20005:rno already exist
ORA-06512:”SECONDCSEA.POOL”,line 9
ORA-04088:error during execution at trigger “SECONDCSEA.POOL”
Result:
Thus the PL/SQL blocks are developed for triggers and the results are verified.
VIVA QUESTIONS:
1. Define Trigger.
2. What is the use of Begin and End statement?
3. Define Block.
4. How will you create a database?
5. Write the syntax for creating trigger.
Ex.No:9 Views And Index
Aim
To execute and verify the SQL commands for Views and Indexes.
Procedure
STEP 1: Start
STEP 5: Execute different Commands and extract information from the View.
STEP 6: Stop.
CREATION OF TABLE
Table created.
TABLE DESCRIPTION
SQL> DESC EMPLOYEE;
EMPLOYEE_NAME VARCHAR2(10)
EMPLOYEE_NO NUMBER(8)
DEPT_NAME VARCHAR2(10)
DEPT_NO NUMBER(5)
DATE_OF_JOIN DATE
CREATION OF VIEW
SQL> CREATE VIEW EMPVIEW AS SELECT
EMPLOYEE_NAME,EMPLOYEE_NO,DEPT_NAME,DEPT_NO,DATE_OF_JOIN FROM
EMPLOYEE;
view created.
DESCRIPTION OF VIEW
EMPLOYEE_NAME VARCHAR2(10)
EMPLOYEE_NO NUMBER(8)
DEPT_NAME VARCHAR2(10)
DEPT_NO NUMBER(5)
DISPLAY VIEW
1 ROW CREATED.
DELETION OF VIEW
DELETE STATEMENT
SQL> DELETE FROM EMPVIEW WHERE EMPLOYEE_NAME='SRI';
UPDATE STATEMENT:
1 ROW UPDATED.
VIEW DROPED
CREATE INDEX
MySQL> CREATE DATABASEindexes;Query OK, 1 row affected (0.01 sec)USE indexes;
Database changed
MySQL>CREATE TABLE employees (employee_id int, first_name varchar(50), last_name
varchar(50),device_serial varchar(15),salary int ); Query OK, 0 rows affected (0.00 sec)
INSERT INTO employees VALUES
(1, 'John', 'Smith', 'ABC123', 60000), (2, 'Jane', 'Doe', 'DEF456', 65000),
(3, 'Bob', 'Johnson', 'GHI789', 70000), (4, 'Sally', 'Fields', 'JKL012', 75000),
(5, 'Michael', 'Smith', 'MNO345', 80000), (6, 'Emily', 'Jones', 'PQR678', 85000),
(7, 'David', 'Williams', 'STU901', 90000), (8, 'Sarah', 'Johnson', 'VWX234', 95000),
Warnings: 0
+ + + + + + + + + + +
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered
| 1 | SIMPLE | employees | NULL | ref | salary | salary | 5 | const | 1 | 100.00 |
+ + + + + + + + + + +
Result
Thus views and indexes created successful.
VIVA QUESTIONS:
1. Define View.
2. What is the purpose of using Index?
3. What is the use of drop command?
4. How will you delete views?
EX.NO:10 XML DATABASE CREATION AND VALIDATION
Aim
Step 1: Start
prompt(version.5.5)
it.
Step 6:Stop.
CREATE TABLE
created TIMESTAMP
);
<list>
<personperson_id="1"fname="Kapek"lname="Sainnouine"/>
<personperson_id="2"fname="Sajon"lname="Rondela"/>
<personperson_id="3"><fname>Likame</fname><lname>Örrtmons</lname></person>
<personperson_id="4"><fname>Slar</fname><lname>Manlanth</lname></person>
<person><fieldname="person_id">5</field><fieldname="fname">Stoma</field>
<fieldname="lname">Milu</field></person>
<person><fieldname="person_id">6</field><fieldname="fname">Nirtam</field>
<fieldname="lname">Sklöd</field></person>
<personperson_id="7"><fname>Sungam</fname><lname>Dulbåd</lname></person>
<personperson_id="8"fname="Sraref"lname="Encmelt"/>
</list>
LOAD XML LOCAL INFILE 'c:/db/person.xml' //this is ths location of the xml
MySQL> SELECT
Result
VIVA QUESTIONS:
1. Define XML.
2. Define XML Schema.
3. What is the purpose of XML?
4. How will you create a XML Database?
5. How will you validate the XML Database?
EX.NO:11 CREATING DOCUMENT, COLUMNS & GRAPH USING NOSQL
Aim
Algorithm
Step 1:Start
Step 5:Stop
>Connection string:
mongodb://localhost:27017
output:
Create collection in mongodb
OUTPUT:
mydbnew>db.details.insertOne({"website":"mywebsite"})
Output:
Db.details.find()
Output
PROCEDURE:
To access the MongoDB Charts application, you must be logged into Atlas
If you have an Atlas Project with clusters containing data you wish to visualize,
Step 3: Select the project from the Context dropdown in the left navigation pane.
Step 4: Create an Atlas cluster. The MongoDB Charts application makes it easy to connect
Collections in your cluster asdata sources. Data sources reference specific collections and
charts views that you can access in the Chart Builder to visualize the data in those collections
or charts views.
Step 5: Launch the MongoDB Charts application. In Atlas, click Charts in the navigation bar.
Result
VIVA QUESTIONS:
Aim
Algorithm
Step 1: Start
Step 3:Design Login Screen with User Name and Password fields.
Step 5: Stop
PROGRAM
import tkinter as tk
import
MySQL.connectorfrom
tkinter import *
def submitact():
logintodb(user, passw)
try:
cursor.execute(savequery)
myresult = cursor.fetchall()
# Printing the result of the
# query
for x in myresult:
print(x)
print("Query Executed successfully")
except:
db.rollback()
print("Error occurred")
root = tk.Tk()
root.geometry("300x300")
root.title("DBMS Login Page")
root.mainloop()
Output:
Result
VIVA QUESTIONS:
Aim
To study bank management system using realtime database applications.
Bank Entity : Attributes of Bank Entity are Bank Name, Code and Address.
Code is Primary Key for Bank Entity.
Customer Entity : Attributes of Customer Entity are Customer_id, Name, Phone
Number and Address.
Customer_id is Primary Key for Customer Entity.
Branch Entity : Attributes of Branch Entity are Branch_id, Name and Address.
Branch_id is Primary Key for Branch Entity.
Account Entity : Attributes of Account Entity are Account_number, Account_Type and
Balance.
Account_number is Primary Key for Account Entity.
Loan Entity : Attributes of Loan Entity are Loan_id, Loan_Type and Amount.
Loan_id is Primary Key for Loan Entity.
This bank ER diagram illustrates key information about bank, including entities such as
branches, customers, accounts, and loans. It allows us to understand the relationships between
entities.
ER Diagram of Bank Management System :
Relationships are :
NORMALIZATION PROCESS
Database normalization is a stepwise formal process that allows us to decompose
database tables in such a way that both data dependency and update anomalies are minimized. It
makes use of functional dependency that exists in the table and primary key or candidate key in
analyzing the tables. Normal forms were initially proposed called First Normal Form
(INF), Second Normal Form (2NF), and Third Normal Form (3NF). Subsequently, R, Boyce, and
E. F. Codd introduced a stronger definition of 3NF called Boyce-Codd Normal Form. With the
exception of 1NF, all these normal forms are based on functional dependency among the
attributes of a table. Higher normal forms that go beyond BCNF were introduced later such as
Fourth Normal Form (4NF) and Fifth Normal Form (5NF). However, these later normal forms
deal with situations that are very rare.
TRIGGERS
To ensure the integrity and consistency of data during a transaction (A transaction is a unit of
program that updates various data items, read more about it here), the database system
maintains four properties. These properties are widely known as ACID properties.
Atomicity
This property ensures that either all the operations of a transaction reflect in database or
none. The logic here is simple, transaction is a single unit, it can’t execute partially. Either it
executes completely or it doesn’t, there shouldn’t be a partial execution.
Let’s say first operation passed successfully while second failed, in this case A’s balance would
be 300$ while B would be having 700$ instead of 800$. This is unacceptable in a banking
system. Either the transaction should fail without executing any of the operation or it should
process both the operations. The Atomicity property ensures that.
There are two key operations are involved in a transaction to maintain the atomicity of the
transaction.
Abort: If there is a failure in the transaction, abort the execution and rollback the changes made
by the transaction.
Consistency
Database must be in consistent state before and after the execution of the transaction. This
ensures that there are no errors in the database at any point of time. Application programmer is
responsible for maintaining the consistency of the database.
Example:
A transferring 1000 dollars to B. A’s initial balance is 2000 and B’s initial balance is 5000.
Before the transaction:
Total of A+B = 2000 + 5000 = 7000$
The data is consitendct before and after the execution of the transaction so this example
maintains the consistency property of the database.
Isolation
A transaction shouldn’t interfere with the execution of another transaction. To preserve the
consistency of database, the execution of transaction should take place in isolation (that means
no other transaction should run concurrently when there is a transaction already running).
For example account A is having a balance of 400$ and it is transferring 100$ to account B & C
both. So we have two transactions here. Let’s say these transactions run concurrently and both
the transactions read 400$ balance, in that case the final balance of A would be 300$ instead of
200$. This is wrong.
If the transaction were to run in isolation then the second transaction would have read the
correct balance 300$ (before debiting 100$) once the first transaction went successful.
Durability
Once a transaction completes successfully, the changes it has made into the database should
be permanent even if there is a system failure. The recovery-management component of
database systems ensures the durability of transaction.
STORED PROCEDURE
EXEC bank.GetTransactions
@AccountID = 100000,
@StartDate = '4/1/2007',
@EndDate = '4/30/2007'
Result:
Thus the bank management system using realtime database applications was
successfully studied.
VIVA QUESTIONS: