Dbms Lab Manual
Dbms Lab Manual
IRUNGALUR
TIRUCHIRAPALLI-621 105
Regulation 2021
LAB MANUAL
ISSUE- B
REVISION – 02
[Link] ,
Assistant Professor
HOD/CSE PRINCIPAL
SRM TRP ENGINEERING COLLEGE
To carve the youth as dynamic, competent, valued, and knowledgeable Technocrats through
research, innovation, and entrepreneurial development for accomplishing the global
expectations.
Mission of the Institute
To be recognized as Centre of Excellence for innovation and research in computer science and
engineering through the futuristic technologies by developing technocrats with ethical values to
serve the society at global level.
M1: To develop quality and technically competent computer professionals through excellence in
academics.
M2: To encourage the faculty and students towards research and development with advanced
tools and technologies.
M3: To enhance industry institute interaction to build a strong technical expertise among the
students.
M4: To inculcate leadership skills with ethical behaviors and social consciousness within the
students.
M5: To nurture professional empowerment among students through continuous Learning.
Program Educational Objectives (PEO's)
PEO1: Ability to analyze and get solutions in the field of Computer Science and Engineering
through application of fundamental knowledge of Mathematics, Science and Electronics
(Preparation).
PEO2: Innovative ideas, methods and techniques thereby rendering expertise to the industrial and
societal needs in an effective manner and will be a competent computer/software engineer (Core
Competency).
PEO3: Good and broad knowledge with interpersonal skills so as to comprehend, analyze,
design and create novel products and solutions for real-time applications (Breadth).
PEO4: Professional with ethical values to develop leadership, effective communication skills and
teamwork to excel in career. (Professionalism)
PEO5: Strive to learn continuously and update their knowledge in the specific fields of computer
science & engineering for societal growth. (Learning environment).
Program Outcomes (PO'S)
PO1: Engineering knowledge: Apply the basic knowledge of science, mathematics, and
engineering fundamentals in the field of Computer Science and Engineering to solve complex
engineering problems.
PO2: Problem analysis: Ability to use basic principles of mathematics, natural sciences, and
engineering sciences to Identify, formulate, review research literature, and analyze Computer
Science and engineering problems.
PO6: The Engineer and Society: Ability to apply reasoning informed by the contextual
knowledge to assess the impact of Computer Science and engineering solutions in legal, health,
cultural, safety and societal context and the consequent responsibilities relevant to the
professional engineering practice.
PO8: Ethics: Ability to understand and apply ethical principles and commitment to address the
professional ethical responsibilities of an engineer.
PO11: Project management and finance: Ability to acquire and demonstrate the knowledge
of contemporary issues related to finance and managerial skills in one’s own work, as a
member and leader in a team, to manage projects and in multidisciplinary environments.
PO12: Life-long learning: Ability to recognize and adapt to the emerging field of application in
engineering and technology by developing self-confidence for lifelong learning process.
PSO1:Use Data structures, Data management, Networking, System software, Data science
with high end programming skills to design and implement automation in various domains of
emerging technologies.
PSO2: Apply engineering knowledge in project development with the end products and
services in the field of hardware and software platform to accomplish industry expectations.
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 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.
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.
● 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
COURSE OUTCOMES:
At the end of this course, the students will be able to:
CO1: Create databases with different types of key constraints.
CO2: Construct simple and complex SQL queries using DML and DCL commands.
CO3: Use advanced features such as stored procedures and triggers and incorporate in GUI based application
development.
CO4: Create an XML database and validate with meta-data (XML schema).
CO5: Create and manipulate data using NOSQL database.
CO-PO matrices
Course code PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
CCS352.1 3 3 3 3 - - - - 3 1 3 2
CCS352.2 2 2 3 2 2 - - - 1 2 3 3
CCS352.3 3 3 2 1 1 - - - 1 1 1 3
CCS352.4 1 3 3 3 1 - - - 1 1 3 2
CCS352.5 3 2 1 1 1 - - - 2 2 3 1
CCS352 2 3 2 2 1 - - - 2 1 3 2
CO-PSO matrices
Course code PSO1 PSO2 PSO3
CCS352.1 2 3 2
CCS352.2 2 1 2
CCS352.3 2 3 3
CCS352.4 3 1 3
CCS352.5 3 1 2
CCS352 2 2 2
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.
TABLE CREATION:
Table created.
DESCRIBING TABLE:
EMPID NUMBER(5)
EMPNAME VARCHAR2(10)
DEPT VARCHAR2(20)
DOB DATE
SALARY NUMBER(6)
ALTERING A TABLE
Table altered.
DESCRIBING A TABLE:
EMPID NUMBER(5)
EMPNAME VARCHAR2(10)
DEPT VARCHAR2(20)
DOB DATE
SALARY NUMBER(6)
DATEOFJOINING DATE
MODIFY:
Table altered.
EMPID NUMBER(5)
EMPNAME VARCHAR2(15)
DEPT VARCHAR2(20)
DOB DATE
SALARY NUMBER(6)
DATEOFJOINING DATE
DROPING A CLOUMN:
Table altered.
DESCRIBING A TABLE:
SQL> desc employee;
EMPID NUMBER(5)
EMPNAME VARCHAR2(15)
DEPT VARCHAR2(20)
DOB DATE
SALARY NUMBER(6)
TRUNCATE:
Table truncated.
RENAME:
Table renamed.
INSERT:
ONETIME INSERTION:
1 row created.
SELECT:
1 row created.
SELECT:
1021
RUNTIME INSERTION:
1 row created.
SELECT:
1021
UPDATE:
3 rows updated.
SELECT:
1021 50000
DELETE:
1 row deleted.
SELECT:
1 row created.
PRIMARY KEY:
Table created.
ERROR at line 1:
1 row created.
ERROR at line 1:
Table created.
1 row created.
ITEMNO PRICE
3 100
ERROR at line 1:
Table created.
1 row created.
ERROR at line 1:
DEFAULT CONSTRAIN:
r(5)default10,dept varchar2(5));
Table created.
1 row created.
RESULT:
Thus a database table with added constraints (primary key, unique, check, Not null), insert rows,
update and delete rows using SQL DDL and DML commands is created successfully.
Ex no 02 Create a set of tables, add foreign key constraints and incorporate referential
integrity
AIM:
To create a set of tables, add foreign key constraints and incorporate referential integrity.
PRIMARY KEY:
Table created.
ERROR at line 1:
1 row created.
ERROR at line 1:
FOREIGN KEY:
Table created.
1 row created.
ITEMNO PRICE
3 100
ERROR at line 1:
Table created.
1 row created.
ERROR at line 1:
DEFAULT CONSTRAIN:
r(5)default10,dept varchar2(5));
Table created.
1 row created.
1 row created.
CHECK CONSTRAIN:
SQL> create table stud4(rollno number(5) not null,studname varchar2(10),joiningyear number(5)default 10,dept
varchar2(5),age number(5)check (age>17));
Table created.
ERROR at line 1:
UNIQUE CONSTRAIN:
quantity number(5));
Table created.
1 row created.
111 pendrive 15
ERROR at line 1:
Thus a set of tables with added foreign key constraints and incorporate referential integrity is
created successfully.
[Link] 3 Query the database tables using different ‘where’ clause conditions and also
implement aggregate functions.
AIM:
To Query the database tables using different ‘where’ clause conditions and also implement aggregate functions.
SQL aggregation function is used to perform the calculations on multiple rows of a single column of a
table. It returns a single value.
It is also used to summarize the data.
1. COUNT
FUNCTION
COUNT function is used to Count the number of rows in a database table. It can work on both numeric and non-
numeric data types.
COUNT function uses the COUNT(*) that returns the count of all the rows in a specified table. COUNT(*)
considers duplicate and Null.
Syntax
COUNT(*) or
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 Com1 3 25 75
Item8 Com1 3 10 30
Item9 Com2 2 25 50
Example: COUNT()
Output:
10
Output:
Output:
Com1 5
Com2 3
Com3 2
Output:
Com1 5
Com2 3
2. SUM FUNCTION
Sum function is used to calculate the sum of all selected columns. It works on numeric fields only.
Syntax
SUM()
or
Example: SUM()
Output:
670
Output:
320
Output:
Com1 150
Com2 170
HAVING SUM(COST)>=170;
Output:
Com1 335
Com3 170
3. AVG Function
The AVG function is used to calculate the average value of the numeric type. AVG function returns the average of
all non-Null values.
Syntax
AVG() or
Example:
Output:
67.00
4. MAX FUNCTION
MAX function is used to find the maximum value of a certain column. This function determines the largest value
of all selected values of a column.
Syntax
MAX() or
Example:
30
5. MIN FUNCTION
MIN function is used to find the minimum value of a certain column. This function determines the smallest value
of all selected values of a column.
Syntax
MIN() or
Example:
Output:
10
RESULT:
Thus Query the database tables using different ‘where’ clause conditions and also
implement aggregate functions.
[Link] 4 Query the database tables and explore sub-queries and simple join operations.
AIM:
To Query the database tables and explore sub-queries and simple join operations.
SQL JOIN
A JOIN clause is used to combine rows from two or more tables, based on a related column between them.
10308 2 1996-09-18
10309 37 1996-09-19
10310 77 1996-09-20
Notice that the "CustomerID" column in the "Orders" table refers to the "CustomerID" in the "Customers" table.
The relationship between the two tables above is the "CustomerID" column.
Then, we can create the following SQL statement (that contains an INNER JOIN), that selects records that have
matching values in both tables:
Example
SELECT [Link], [Link], [Link] FROM Orders INNER JOIN Customers
ON [Link]=[Link];
CustomerName OrderDate
OrderID
10308 Ana Trujillo Emparedados 9/18/1996
10365 Antonio Moreno Taquería 11/27/1996
10383 Around the Horn 12/16/1996
10355 Around the Horn 11/15/1996
10278 Berglunds snabbköp 8/12/1996
Demo Database
In this tutorial we will use the well-known Northwind sample database.
Below is a selection from the "Orders" table:
10308 2 7 1996-09-18 3
10309 37 3 1996-09-19 1
10310 77 8 1996-09-20 2
The following SQL statement selects all orders with customer information:
Example
The following SQL statement selects all orders with customer and shipper information:
Example
Demo Database
10308 2 7 1996-09-18 3
10309 37 3 1996-09-19 1
10310 77 8 1996-09-20 2
The following SQL statement will select all customers, and any orders they might have:
Example
The RIGHT JOIN keyword returns all records from the right table (table2), and the matching records from the left
table (table1). The result is 0 records from the left side, if there is no match.
10308 2 7 1996-09-18 3
10309 37 3 1996-09-19 1
10310 77 8 1996-09-20 2
The following SQL statement will return all employees, and any orders they might have placed:
Example
The FULL OUTER JOIN keyword returns all records when there is a match in left (table1) or right (table2) table
records.
Tip: FULL OUTER JOIN and FULL JOIN are the same.
Note: FULL OUTER JOIN can potentially return very large result-sets!
Demo Database
10308 2 7 1996-09-18 3
10309 37 3 1996-09-19 1
10310 77 8 1996-09-20 2
CustomerName OrderID
Null 10309
Null 10310
RESULT:
Thus the database tables and explore sub-queries and simple join operations are queried
successfully.
[Link]:- 5 Query the database tables and explore sub-queries , natural, eqi and outer join
operations.
AIM:
To Query the database tables and explore sub-queries , natural, eqi and outer join operations.
SET OPERATORS
Table1: STUDENT
ROLLNO NAME M1 M2 M3
1 XXX 90 60 90
2 AAA 80 70 50
3 BBB 90 80 50
Table2: STUD
ROLLNO NAME M1 M2 M3
1 XXX 90 60 90
2 AAA 80 70 50
4 CCC 80 80 60
1. UNION
OUTPUT
ROLLNO
NAME
M1
M2
M3
1 XXX 90 60 90
2 AAA 80 70 50
3 BBB 90 80 50
4 CCC 80 80 60
2. UNION ALL
OUTPUT
ROLLNO NAME M1 M2 M3
1 XXX 90 60 90
2 AAA 80 70 50
3 BBB 90 80 50
1 XXX 90 60 90
2 AAA 80 70 50
4 CCC 80 80 60
3. INTERSECT
OUTPUT
ROLLNO NAMEM1 M2 M3
1 XXX 90 60 90
2 AAA 80 70 50
4. MINUS
OUTPUT
ROLLNO NAME M1 M2 M3
3 BBB 90 80 50
SYNTAX:
The IN connective test for set membership where set is a collection of values produced by a select clause.
NOT IN:
SYNTAX:
DESCRIPTION:
The NOTIN connective tests for set membership where set is a collection of values produced by a select clause.
ANY/SOME:
SYNTAX:
select * from table1 where attribute > some/any(select attribute from table name(condition));
DESCRIPTION:
The some/any keyword require that atleast one pair compiler, if denotes that the select condition TRUE if the
comparision is TRUE for atlest one of the values that is required.
ALL:
SYNTAX:
select * from table1 where attribute > ALL(select attribute from table where(condition));
DESCRIPTION:
The ALL keyword require that all values from the subselect comply with the comparison [Link] ALL
keyword specifies that the select condition TRUE if the comparision is TRUE for everyvalues that the sub query
returns.
Examples:
SQL> select * from emp where eno in(select eno from sal);
1 ram cse
2 rajan ece
4 hari cse
SQL> select * from emp where eno not in(select eno from sal where dept='cse');
2 rajan ece
3 balu ece
4 hari cse
SQL> select * from sal where salary>any(select salary from sal where dept='cse');
4 eee 8000
5 cse 10000
SQL> select * from sal where salary>some(select salary from sal where dept='cse');
4 eee 8000
5 cse 10000
SQL> select * from sal where salary>all(select salary from sal where dept='cse'); no rows selected
SQL> select * from sal where salary<all(select salary from sal where dept='cse'); ENO DEPT SALARY
2 ece 1000
EQUIJOIN:
SYNTAX:
Select attribute 1, 2, …., from table name1,table name2 where t1=t2 attribute;
DESCRIPITION:
SYNTAX:
Select attribute1, attribute2. from table 1, table2 where table1 attribute <> table2 attribute
DESCRIPTION:
A non equi join is a SQL join whose condition is established using all comparison operator except the equal (=)
operations like <=,>=,<,>
Select distinct t1 attributes _name1 t1 attributes name from table name t1 where attribute name1=t2.attribute_name
and t1.attribute_name in<> t2.attribute_name in
DESCRIPTION:
A self join is a type of SQL join which is used to join a table to itself particularly when the used table has a foreign
key the references its own primary key. It compares values with the column of a single table.
INNER JOIN:
SYNTAX:
Select attribute1, attribute 2. from table 1 left inner join table2 on condition.
DESCRIPTION:
Inner join returns the matching rows from the tables that are being joined.
OUTER JOIN:
Select attribute1, attribute 2. from table 1 left outer join table2 on condition.
DESCRIPTION:
Left outer join returns the matching rows from the tables that are being joined and also non matching rows from
the left table in the result and the place NULL values in the attribute that came from the right table.
Select attribute1, attribute 2. from table 1 right outer join table2 on condition.
DESCRIPTION:
Right outer join returns the matching rows from the tables that are being joined and also non matching rows from
the right table in the result and the place NULL values in the attribute that came from the left table.
Select attribute1, attribute 2. from table 1 full outer join table2 on condition.
DESCRIPTION:
The full outer join returns the matching rows from the tables that are being joined and also non matching rows
from the left and right table in the result and the place NULL values in the attribute that came from the right & left
table.
Example:
1 aaa cse
2 bbb it
3 ccc cse
1 aaa 30000
2 bbb 50000
1 aaa 50000
1 aaa 60000
2 bbb 30000
2 bbb 60000
3 ccc 30000
3 ccc 50000
3 ccc 60000
7 rows selected.
7 rows selected.
Inner join:
1 aaa 30000
2 bbb 50000
Outer join:
1 aaa 30000
2 bbb 50000
3 ccc
1 aaa 30000
2 bbb 50000
60000
1 aaa 30000
2 bbb 50000
3 ccc 60000
RESULT:
Thus the simple SQL queries, set operations, nested queries, sub queries, different
‘where’ clause conditions, aggregate functions and Join operations using clauses such as
GROUP BY, ORDER BY, etc. and retrieving information by joining tables has been verified
and executed successfully.
[Link]:- 6 Write user defined functions and stored procedures in SQL
AIM:
PL/SQL PROCEDURES:
An Oracle stored procedure is a program stored in an Oracle database. The following are the advantages of
using procedures. Better performance: Oracle stored procedures load once into the shared pool and remain there
unless they become paged out. Subsequent executions of the Oracle stored procedure are far faster than executions
of external code.
Coupling of data with behaviour: DBAs can use naming conventions to couple relational tables with the
behaviors associated with a table by using Oracle stored procedures as "methods". If all behaviors associated with
the employee table are prefixed with the table [Link], employee.give_raise, for example--the data
dictionary can be queries to list all behaviors associated with a table (select * from dba_objects where owner =
'EMPLOYEE'), and it's easy to identify and reuse code via stored procedures.
Isolation of code: Since all SQL is moved out of the external programs and into the Oracle stored
procedures, the application programs become nothing more than calls to Oracle stored procedures. As such, it
becomes very simple to swap out one database and swap in another one.
EXECUTION:
5/
OUTPUT:
Procedure created.
3 BEGIN
4 TOT: = N1 + N2;
5 END;
6/
OUTPUT:
Procedure created.
99
a:=&a;
INPUT:
new 8: a:=8;
new 9: b:=16;
OUTPUT:
Procedure created.
GCD is 8
<declaration_section> BEGIN
<executable_section> EXCEPTION
<exception_section> END;
PROCEDURE
1. Start.
2. Initialize the necessary variables.
6. Stop.
SQL> DECLARE
b:=&b; c:=a+b;
INPUT:
new 6: a:=23;
new 7: b:=12;
OUTPUT:
sum of23and12is35
SQL> DECLARE
IF (CONDITION) THEN
DECLARE
C:=20;
if(C>B) THEN
end;
OUTPUT:
C is maximum
SQL> DECLARE
<STATEMENTS>;
ELSE
<STATEMENTS>;
ENDIF;
END;
if n<5 then
end;
INPUT:
new 5: n:=2;
OUTPUT:
SQL> DECLARE
<STATEMENTS>;
ELSE
<STATEMENTS>;
ENDIF;
END;
b:=&b;
end;
INPUT:
new 7: a:=21;
new 8: b:=12;
new 9: c:=45;
OUTPUT:
C is maximum
PL/SQL procedure successfully completed.
SQL> DECLARE
LOOP
<EXECUTAVLE STATEMENT>;
END;
end loop;
INPUT:
new 6: endvalue:=4;
OUTPUT:
sum =4
SQL> DECLARE
<VARIABLE DECLARATION>; BEGIN
n:=n+2;
end loop;
INPUT:
new 6: endvalue:=4;
OUTPUT:
PL/SQL FUNCTION:
PROCEDURE
1. Start.
4. Frame the searching procedure for both positive and negative searching.
EXECUTION:
/ SQL>Declare
dbms_output.put_line(y); end;
Function created.
2. PROGRAM
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.
SQL> create or replace function findAddress(phone in number) return varchar2 as address varchar2(100);
begin
Function created.
SQL>declare
2 address varchar2(100);
3 begin
4 address:=findaddress(20312);
5 dbms_output.put_line(address);
6 end;
7/
OUTPUT 1:
SQL> declare
2 address varchar2(100);
3 begin
4 address:=findaddress(23556);
5 dbms_output.put_line(address);
6 end;
7/
OUTPUT2:
RESULT:
Thus PL/SQL Procedures and function were created to solve the given problem statements
[Link].:07 Execute complex transactions and realize DCL and TCL commands
AIM:
To execute complex transaction and realize DCL and TCL commands.
TCL COMMANDS:
COMMANDS OVERVIEW
SAVEPOINT
Syntax:
savepoint
username;Input:
Input:
SQL> commit;
Output:
Commit complete.
ROLLBACK
Syntax: rollback to
savepoint_text_identifier;Input
:
SQL> rollback to
emp;Output:
Rollback complete.
DCL COMMANDS:
DCL provides users with privilege commands the owner of database objects (tables), has the
soul authority ollas them. The owner (data base administrators) can allow other data base
users to access the objects as per their requirement
1. GRANT: The GRANT command allows granting various privileges to other users and
allowing them to perform operations within their privileges.
Example, if a uses is granted as ‘SELECT’ privilege then he/she can only view data but
cannot perform any other DML operations on the data base object GRANTED privileges
can also be withdrawn by the DBA at any time
Syntax:
Example:
2. REVOKE: To with draw the privileges that has been GRANTED to a uses, we use the
REVOKE
command
Syntax:
SQL>REVOKE PRIVILEGES_NAME ON object-name FROM user_name;
Example:
RESULT:
Thus the Execute complex transactions and realize DCL and TCL commands is completed and
verified successfully.
[Link]: 08 Write SQL TRIGGERS for insert,delete,and update operation in database table
AIM
To write a PL/SQL query to create a trigger.
TRIGGERS:
A trigger is a statement that the system automatically as a side effect of a modification
Type of Triggers
1. BEFORE Trigger : BEFORE trigger execute before the triggering
DML statement (INSERT, UPDATE, DELETE) execute. Triggering
SQL statement is may or may not execute, depending on the
BEFORE trigger conditions block.
2. AFTER Trigger : AFTER trigger execute after the triggering DML statement
row deleting isdefine as trigger event, when trigger file, deletes the five rows
at once from the table.
5. Combination Trigger : Combination trigger are combination of two trigger type,
1. Before Statement Trigger : Trigger fire only once for each
statement before the triggering DML statement.
2. Before Row Trigger : Trigger fire for each and every record before
the triggering DML statement.
3. After Statement Trigger : Trigger fire only once for each
statement after the triggering DML statement executing.
4. After Row Trigger : Trigger fire for each and every record after the
triggering DML statement executing.
PL/SQL
Triggers
Inserting
Trigger
SQL> CREATE or REPLACE TRIGGER trg1
2 BEFORE
3 INSERT ON customer
4 FOR EACH ROW
5 BEGIN
6 :[Link] := upper(:[Link]);
7 END;
8/
Trigger created.
Table created
TRIGGER -1:
SQL> create or replace trigger t1 after delete on student
for each row 2 begin
3 insert into bckupstu2 values(:[Link],:[Link],:[Link],:[Link]);
4 end
;
5/
Trigger created.
bckupstu2; no rows
selected
TRIGGER-3
SQL> create or replace trigger t3 before insert or update of name on student for each row
2 begin
3 :[Link]:=upper(:[Link]);
4 end
;
5/
Trigger created.
TRIGGER-4
SQL> create or replace trigger vot_trig after delete on voter_master for
each row declare
2 v_id number(5);
3 w_id number(4);
4 begin
5 v_id:=:[Link];
6 update new_list set description='shifted' where voterid=v_id;
7 end
;
8/
Trigger created.
SQL> delete from voter_master where
voterid=1000; 1 row deleted.
SQL> declare
2 address varchar2 (100);
3 begin
4 address:=find address(25301);
5 dbms_output.put_line (address);
6 end;
Priya,390,main street,SIT colony,659002
PL/SQL procedure
successfully [Link]> declare
2 address varchar2(100);
3 begin
4 address:=findaddress(25601);
5 dbms_output.put_line(address);
6 end;
Address not found
PL/SQL procedure successfully completed.
RESULT:
Thus the PL/SQL block for trigger with different controls are verified and executed.
[Link] 09 Create View and index for database tables with a large number of records.
AIM:
Create View and index for database tables with a large number of records.
OVERVIEW:
VIEW: A view is simply the representation of a SQL statement that is stored
in memory so that itcan easily be re-used. It‟s also referred as logical table.
SQL COMMANDS
Creating views:
Syntax:
Create view<view name>;
Description:
This command is used to create view by combining two tables.
Viewing single row of table:
Syntax:
Syntax:
Create view<view table name> as select * from <table name> where „condition‟;
Description:
This is used to create view which displays all the columns of a table.
Inserting into views:
Syntax:
Syntax:
Syntax:
Drop view <view name>;
SYNTAX:
CREATE OR REPLACE VIEW <view name > AS < select statement >
SYNONYM: A synonym is an alias or alternate name for a table, view,
sequence, or other schema object. They are used mainly to make it easy for
users to access database objects owned by other users.
SYNTAX:
Result:
AIM:
ALGORITHM:
1. Import the necessary libraries for XML processing in your chosen programming
language.
2. Define the data that will be stored in the XML database, including thestructure of the
data and any associated attributes.
3. Write a function that creates the XML document based on the defined datastructure.
4. Validate the XML document using an XML schema to ensure that it conforms to the
expected structure.
5. Write a function that reads and parses the XML document to retrieve and manipulate
the data as needed.
6. Implement error handling to catch and respond to any errors that may occur during
the creation or validation of the XML document.
7. Test the program by creating an XML database, validating it using the XML schema,
and reading and parsing the data to ensure that it is correctly stored and retrieved.
8. Refine the program as needed to improve functionality and efficiency, and document
the code to make it easier for others to understand and use.
PROGRAM:
Example XML Document:
<?xml version="1.0" encoding="UTF-8"?>
<employees>
<employee>
<id>1</id>
<name>John Doe</name>
<department>IT</department>
<salary>60000</salary>
</employee>
<employee>
<id>2</id>
<name>Jane Smith</name>
<department>HR</department>
<salary>50000</salary>
</employee>
</employees>
Example XML Schema:
<?xml version="1.0"?>
<xs:schema xmlns:xs="[Link]
<xs:element name="employees">
<xs:complexType>
<xs:sequence>
<xs:element name="employee" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="id" type="xs:integer"/>
<xs:element name="name" type="xs:string"/>
<xs:element name="department" type="xs:string"/>
<xs:element name="salary" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
OUTPUT:
Validation successful.
RESULT:
Thus the program to Create an XML database and validate it using XML
schema is executed and verified successfully.
EX NO :11 Create Document, column and graph based data using NOSQL database
tools.
AIM:
To Create Document, column and graph based data using NOSQL database tools.
ALGORITHM:
1. Import the necessary libraries for NoSQL database tools in your chosen programming
language.
2. Connect to the desired NoSQL database using the appropriate client library.
3. Create the desired data structure, such as a document, column family, orgraph.
4. Insert data into the NoSQL database using the appropriate method orquery.
5. Retrieve and manipulate data from the NoSQL database as needed using the appropriate
method or query.
6. Implement error handling to catch and respond to any errors that may occur during data
insertion, retrieval, or manipulation.
7. Test the program by creating and manipulating data in the NoSQL database, and ensure that
the data is correctly stored and retrieved.
PROGRAM:
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
// MongoDB example
MongoClient mongoClient =
[Link]("mongodb://localhost:27017"); MongoDatabase
database = [Link]("mydb");
MongoCollection<Document> collection =
[Link]("mycollection");
// Create a document
.append("age", 35)
.append("email", "johndoe@[Link]");
[Link](document);
[Link](createTableQuery);
String insertQuery = "INSERT INTO mycolumnfamily (id, name, age) VALUES (1,
'John Doe', 35);";
[Link](insertQuery);
// Create a graph
ArangoCollection collection =
[Link]("mydb").createCollection("mycollection", new
CollectionCreateOptions().type([Link]));
DocumentEntity documentEntity = [Link](new
BaseDocument("name", "John Doe"));
ArangoCollection edgeCollection =
[Link]("mydb").createCollection("myedges", new
CollectionCreateOptions().type([Link]));
[Link]("myedges").insertEdge(new
BaseEdgeDocument([Link](), [Link](), new BaseDocument())); }
RESULT:
Document, column and graph based data using NOSQL database tools are Created
Successfully
EX NO :12 Develop a simple GUI based database application and
incorporate all the above mentioned features
AIM:
To Develop a simple GUI based database application and incorporate allthe above
mentioned features.
ALGORITHM:
1. Import the required libraries (tkinter for GUI and sqlite3 for databaseoperations).
2. Define functions for adding records to the database and displaying records.
3. Create a new database and table (if they don't exist).
4. Create the main window for the GUI application.
5. Create input fields (labels and entry widgets) for name and age.
6. Create buttons for adding records and displaying records, and associatethem with their
respective functions.
7. Create a text area to display the records.
8. Start the application by calling [Link]().
Close the database connection when the application is closed
PROGRAM:
import tkinter as tk
import sqlite3
add_record():
name = name_entry.get()
age = age_entry.get()
[Link]("INSERT INTO records (name, age) VALUES (?, ?)", (name, age))
[Link]()
display_records()
def display_records():
record_text.delete(1.0, [Link])
conn = [Link]("[Link]")
[Link]("Database Application")
# Create input fields
name_label.pack()
name_entry = [Link](window)
name_entry.pack()
age_label = [Link](window,
text="Age:") age_label.pack()
age_entry = [Link](window)
age_entry.pack()
# Create buttons
add_button.pack()
display_button.pack()
record_text.pack()
[Link]()
RESULT:
AIM:
To implement a fire store database for real-time messaging.
PROGRAM:
Step 1: Create a fire store Collection
Navigate to Firebase Console → Firestore Database → Create Collection messages.
{
"sender": "Alice",
"receiver": "Bob",
"message": "Hey Bob! How are you?",
"timestamp": "2024-02-24T10:30:00Z"
}
Result:
Thus the Program to implement the fire store database for real-time messaging is successfully
completed.
[Link]. 14 Implementing Role-Based Access Control (RBAC) in MySQL
AIM:
To implement role based access control in MySQL
PROGRAM:
Step 1: Create Users and Roles
CREATE USER 'admin'@'localhost' IDENTIFIED BY 'admin123';
CREATE USER 'staff'@'localhost' IDENTIFIED BY 'staff123';
CREATE USER 'customer'@'localhost' IDENTIFIED BY 'customer123';
Expected Output:
+------------------------------------------------------------+
| Grants for staff@localhost |
+------------------------------------------------------------+
| GRANT SELECT, INSERT ON [Link] TO 'staff'@'localhost' |
+------------------------------------------------------------+
Result:
Thus the Program to implement role based access control in MySQL is successfully
completed.