DBMS Manual Final PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 49

Ex.

No: 1 CREATE A DATABASE TABLE, ADD CONSTRAINTS (PRIMARYKEY,


UNIQUE,CHECK, NOT NULL), INSERT ROWS, UPDATE AND DELETE
Date:
ROWS USING SQL DDL AND DML COMMANDS

AIM

To write SQL Statements to create table, add constraints, insert rows, update and delete
rows using Data Definition Language (DDL) and Data Manipulation Language(DML)

The syntax of CREATE TABLE in sql

CREATE TABLE table_name (


column1 datatype constraint,
column2 datatype constraint,
column3 datatype constraint,
...
columnN datatype constraint
);

Here's what each part of the syntax means:


 CREATE TABLE: This is the start of the SQL statement that creates a new table.
 table_name: This is the name you want to give to your new table.
 column1, column2, ..., columnN: These are the names of the columns you want to create in
your new table.
 datatype: This is the data type that each column will hold (e.g. VARCHAR, INT, DATE, etc.).
 constraint: This is an optional parameter that lets you specify additional rules for each column
(e.g. PRIMARY KEY, NOT NULL, UNIQUE, etc.).
Note that you can have as many columns as you need in your table, and you can specify
constraints for each column as needed. Once you've defined all of the columns in your table, you
can then start inserting data into it.
Note that you can add as many constraints as you need to each column in your table. Some
common constraints include NOT NULL (which ensures that a column cannot be empty),
UNIQUE (which ensures that each value in a column is unique), and FOREIGN KEY (which
links a column in one table to a primary key in another table).
The SQL INSERT Statement
It is possible to write the INSERT INTO statement in two ways:
1. Specify both the column names and the values to be inserted:
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);

1
2. If you are adding values for all the columns of the table, you do not need to specify the column
names in the SQL query. However, make sure the order of the values is in the same order as the
columns in the table. Here, the INSERT INTO syntax would be as follows:
INSERT INTO table_name
VALUES (value1, value2, value3, ...);
The SQL UPDATE Statement
The UPDATE statement is used to modify the existing records in a table.
UPDATE Syntax
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
Note: that you can update one or more fields at a time, and you can use the WHERE clause to
update only specific records that meet certain conditions. You can also update multiple records at
once by omitting the WHERE clause, but be careful with this as it will update all records in the
table.
The SQL DELETE Statement
The DELETE statement is used to delete existing records in a table.
DELETE Syntax
DELETE FROM table_name WHERE condition;
Note: Be careful when deleting records in a table! Notice the WHERE clause in the DELETE
statement. The WHERE clause specifies which record(s) should be deleted. If you omit the
WHERE clause, all records in the table will be deleted!
PROGRAM:
 student_id (integer, primary key)

 first_name (varchar(50), not null)

 last_name (varchar(50), not null)

 email (varchar(50), unique)

 age (integer, check age >= 18)

SQL code to create the table


CREATE TABLE students (
student_id integer PRIMARY KEY,
first_name varchar(50) NOT NULL,
last_name varchar(50) NOT NULL,
email varchar(50) UNIQUE,
age integer CHECK (age >= 18)
);

2
insert some data into the table
INSERT INTO students (student_id, first_name, last_name, email, age)
VALUES (1, 'John', 'Doe', '[email protected]', 25),
(2, 'Jane', 'Doe', '[email protected]', 21),
(3, 'Bob', 'Smith', '[email protected]', 30);
SELECT command
SELECT * FROM students;
OUTPUT:
student_id | first_name | last_name | email | age
+ + + +
1 | John | Doe | [email protected] | 25
2 | Jane | Doe | [email protected] | 21
3 | Bob | Smith | [email protected] | 30
UPDATE command
UPDATE students
SET age = 35
WHERE student_id = 3;
update was successful
SELECT * FROM students;
OUTPUT:
student_id | first_name | last_name | email | age
+ + + +
1 | John | Doe | [email protected] | 25
2 | Jane | Doe | [email protected] | 21
3 | Bob | Smith | [email protected] | 35
DELETE command
DELETE FROM students
WHERE student_id = 2;
delete was successful
SELECT * FROM students;

3
OUTPUT:
student_id | first_name | last_name | email | age
+ + + +
1 | John | Doe | [email protected] | 25
3 | Bob | Smith | [email protected] | 35

RESULT:
Thus the SQL Statements to create table, add constraints, insert rows, update and delete rows
using Data Definition Language (DDL) and Data Manipulation Language(DML) commands
was executed successfully

4
Ex.No: 2 CREATE A SET OF TABLES, ADD FOREIGN KEY CONSTRAINTS AND

Date: INCORPORATE REFERENTIAL INTEGRITY

AIM
To create tables and Execute Data Definition Commands, Data Manipulation Commands to
addforeign key constraints and incorporate referential integrity Statements. We want to create a set
of tables to track orders and their associated products and customers. We'll create two tables:
customers and orders

PROGRAM:
Here's the customers table:
CREATE TABLE customers (
customer_id integer PRIMARY KEY,
first_name varchar(50) NOT NULL,
last_name varchar(50) NOT NULL,
email varchar(50) UNIQUE,
phone_number varchar(20) NOT NULL
);
Here's the orders table:
CREATE TABLE orders (
order_id integer PRIMARY KEY,
order_date date NOT NULL,
customer_id integer NOT NULL,
amount numeric(10, 2) NOT NULL,
FOREIGN KEY (customer_id) REFERENCES customers (customer_id)
);

5
OUTPUT:
INSERT INTO customers (customer_id, first_name, last_name, email, phone_number)
VALUES (1, 'John', 'Doe', '[email protected]', '123-456-7890'),
(2, 'Jane', 'Doe', '[email protected]', '987-654-3210'),
(3, 'Bob', 'Smith', '[email protected]', '555-555-1212');

INSERT INTO orders (order_id, order_date, customer_id, amount)


VALUES (1, '2022-03-01', 1, 100.00),
(2, '2022-03-02', 2, 50.00),
(3, '2022-03-03', 1, 75.00),
(4, '2022-03-04', 3, 200.00),
(5, '2022-03-05', 2, 125.00);

INSERT INTO orders (order_id, order_date, customer_id, amount)


VALUES (6, '2022-03-06', 4, 150.00);
ERROR: insert or update on table "orders" violates foreign key constraint
"orders_customer_id_fkey"
DETAIL: Key (customer_id)=(4) is not present in table "customers".

RESULT:
Thus the Tables are created and added with foreign key constraints and incorporates
referential integrity was successfully executed.

6
Ex.No: 3 QUERY THE DATA TABLES USING DIFFERENT ‘WHERE’CLAUSE

Date: CONDITIONS AND ALSO IMPLEMENTS AGGREGATE FUNCTIONS

AIM:
Two write a sql program to query the databases using different „where‟ clause conditions
and also implements aggregate functions
LIST OF AGGREGATE FUNCTIONS:
 AVG
 COUNT
 MAX
 MIN
 STDDEV
 SUM

DISCRIPTION OF AGGREGATE FUNCTIONS:


A group function returns one result row based on a group of rows.The following options are used
in most of the group functions.
DISTINCT:
This option causes a group of function to consider only distinct values of the argument
expression.
ALL:
This option causes a group of function to consider all values including all duplicates.

1. AVG: PURPOSE: Returns average value of n.


SYNTAX: avg ([DISTINCT/ALL] n);
2. COUNT: PURPOSE: Returns the number of rows returned by the query.
SYNTAX: count ([DISTINCT/ALL] expr)
3. MAX: PURPOSE: Returns maximum value of expression.
SYNTAX: max ([DISTINCT/ALL] expr)
4. MIN: PURPOSE: Returns minimum value of the expression.
SYNTAX: min ([DISTINCT/ALL] expr)
5. STDDEV: PURPOSE: Returns standard deviation of x.
SYNTAX: stddev ([DISTINCT/ALL]x)
6. SUM: PURPOSE: Returns sum of the value n.
SYNTAX: SUM (] DISTINCT/ALL] n)

EXAMPLE:
1. AVG:
SQL>select avg(cost) from stores;
2. COUNT:
SQL> select count (client_name) “NO. Of clients:” from client_master;
3. MAX:
SQL> select max (cost) from stores;

7
4. MIN:
SQL>select min (cost) from stores;
5. STDDEV:
SQL>select stddev(cost) from stores;
6. SUM:
SQL> select sum (cost) from stores;

(i) Create Employee table containing all Records.

SQL> create table emp(eid number, ename varchar2(10),age number, salary number);
Table created.
SQL> desc emp;

(ii) Count number of employee names from employee table.


SQL> select count(ename) from emp;
COUNT(ENAME)

7
(iii) Find the Maximum age from employee table.
SQL> select max(age) from emp;
MAX(AGE)

44

8
(iv) Find the Minimum age from employee table.
SQL> select min(age) from emp;
MIN(AGE)

22
(v) Display the Sum of age employee table.
SQL> select sum(age) from emp;
SUM(AGE)
220

(vi) Display the Average of age from Employee table.


SQL> select avg (age) from emp;
AVG(AGE) ----------------
31.4285714
USING WHERE CLAUSE FOR QUERYING DATABASE:
(vii) Create a View for age in employee table.
SQL> create or replace view A as select age from emp where age<30;
View created.
(viii) Display views
SQL> select * from A;
AGE

22 29 27 29
(ix) Find grouped salaries of employees.(group by clause)
SQL> select salary from emp group by salary;
SALARY

9000 10000 8000 6000 7000

(x).Find salaries of employee in Ascending Order.(order by clause)


SQL> select ename, salary from emp order by salary;
ENAME SALARY

rohan 6000
alex 7000
shane 8000
abhi 8000
tiger 8000
anu 9000

9
scott 10000
7 rows selected.

(xi) Find salaries of employee in Descending Order.

SQL> select ename, salary from emp order by salary desc;

ENAME SALARY

scott 10000
anu 9000

RESULT:
Thus the SQL program to query the database using different „where‟ clause conditions and using
different aggregate functions was created and executed successfully.
10
Ex.No: 4 QUERY THE DATABASE TABLES AND EXPLORE SUB QUERIES
Date: AND SIMPLEJOIN OPERATIONS

AIM:
To write Sql queries to query the database tables and explore sub queries and simple join
operations
SUBQUERIES
IN:
SYNTAX:
select * from table1 where in(select attribute from table2);
DESCRIPTION:
The IN connective test for set membership where set is a collection of values produced by a
select clause.
NOT IN:
SYNTAX:
select * from table1 where notin(select attribute from table2);
DESCRIPTION:
The NOTIN connective tests for set membership where set is a collection of values produced by
aselect 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
separator.The ALL keyword specifies that the select condition TRUE if the comparision is
TRUEfor everyvalues that the sub query returns.

Examples:

SQL> select * from emp where eno in(select eno from sal);
ENO ENAME DEPT
1 ram cse

11
2 rajan Ece
4 hari Cse

SQL> select * from emp where eno not in(select eno from sal where dept='cse');

ENO ENAME DEPT


2 rajan Ece
3 balu Ece
4 hari Cse

SQL> select * from sal where salary>any(select salary from sal where dept='cse');

ENODEPT SALARY
4eee 8000
5cse 10000
SQL> select * from sal where salary>some(select salary from sal where dept='cse');

ENO DEPT SALARY


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

SIMPLE JOIN OPERATIONS:


EQUIJOIN:

SYNTAX:
Select attribute 1, 2, …., from table name1,table name2 where t1=t2 attribute;
DESCRIPITION:
A equi join is a SQL join.
NON EQUI JOIN:
SYNTAX:
Select attribute1, attribute2. ........................... from table 1, table2 where table1 attribute <>
table2 attribute

12
DESCRIPTION:
A non equi join is a SQL join whose condition is established using all comparison operatorexcept
the equal (=) operations like <=,>=,<,>
SELF JOIN:
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 columnof
a single table.
Example:
SQL> create table eem(eno number(3),ename varchar2(10),dept varchar2(5));Table created.

SQL> create table sal(eno number(3),sal number(6),dept varchar(10));Table created.

SQL> select * from eem;

ENO ENAME DEPT


1 aaa Cse
2 bbb It
3 ccc Cse
SQL> select * from sal;

ENO SAL DEPT

1 30000 cse
2 50000 it
5 60000 cse
Equi join:
em, sal where eem.e o=sal.eno;
SQL> select eem.eno,ename,sal from e
ENO ENAME SAL
1 Aaa 30000
2 Bbb 50000
Non equi join:
SQL> select eem.eno,ename,sal from eem,sal where eem.eno<>sal.eno;

ENO ENAME SAL


1 Aaa 50000
1 Aaa 60000

13
2 Bbb 30000
2 Bbb 60000
3 Ccc 30000
3 Ccc 50000
3 Ccc 60000

6 rows selected.

SQL> select * from eem,sal where eem.eno<>sal.eno;

ENO ENAME DEPT ENO SAL DEPT


1 aaa cse 2 50000 It
1 aaa cse 5 60000 Cse
2 bbb it 1 30000 Cse
2 bbb it 5 60000 Cse
3 ccc cse 1 30000 Cse
3 ccc cse 2 50000 It
3 ccc cse 5 60000 Cse

7 rows selected.

RESULT:
Thus the SQL queries to query the database tables and explore sub queries and simple join
operations was written and executed successfully.

14
Ex.No: 5 QUERY THE DATABASE TABLES AND EXPLORE, NATURAL,EQUI AND

Date: OUTER JOINS

AIM:
To write Query the database tables and explore, Natural EQUI and Outer joins.

NATURAL JOIN:
SYNTAX:
Select attribute1,2……,
From table name1,table name2,
NATURAL JOIN attribute1,attribute2;
DESCRIPITION:
A natural join is a SQL join,which simply joins two table‟s attributes
EQUIJOIN:

SYNTAX:
Select attribute 1, 2, …., from table name1,table name2 where t1=t2 attribute;
DESCRIPITION:
A equi join is a SQL join.
NON EQUI JOIN:
SYNTAX:
Select attribute1, attribute2. ........................... from table 1, table2 where table1 attribute <>
table2 attribute
DESCRIPITION:
A non equi join is a SQL join whose condition is established using all comparison operatorexcept
the equal (=) operations like <=,>=,<,>
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:

LEFT OUTER JOIN:


SYNTAX:
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
15
came from the right table.
RIGHT OUTER JOIN:
SYNTAX:
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
camefrom the left table.

FULL OUTER JOIN:


SYNTAX:
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 alsonon
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:
SQL> create table eem(eno number(3),ename varchar2(10),dept varchar2(5));Table created.

SQL> create table sal(eno number(3),sal number(6),dept varchar(10));Table created.

SQL> select * from eem;

ENO ENAME DEPT

1 aaa Cse
2 bbb It
3 ccc Cse
SQL> select * from sal;
ENO SAL DEPT

1 30000 cse
2 50000 it
5 60000 cse
Equi join:
em, sal where eem.e o=sal.eno;

16
SQL> select eem.eno,ename,sal from e
ENO ENAME SAL
1 Aaa 30000
2 Bbb 50000
Non equi join:
SQL> select eem.eno,ename,sal from eem,sal where eem.eno<>sal.eno;

ENO ENAME SAL


1 Aaa 50000
1 Aaa 60000
2 Bbb 30000
2 Bbb 60000
3 Ccc 30000
3 Ccc 50000
3 Ccc 60000
8 rows selected.

SQL> select * from eem,sal where eem.eno<>sal.eno;

ENO ENAME DEPT ENO SAL DEPT


1 Aaa cse 2 50000 It
1 Aaa cse 5 60000 Cse
2 Bbb it 1 30000 Cse
2 Bbb it 5 60000 Cse
3 Ccc cse 1 30000 Cse
3 Ccc cse 2 50000 It
3 Ccc cse 5 60000 Cse

7 rows selected.
Inner join:

SQL> select eem.eno,ename,sal from eem inner join sal on eem.eno=sal.eno;

ENO ENAME SAL


1 Aaa 30000
2 Bbb 50000
Outer join:

1. Left outer join

SQL> select eem.eno,ename,sal from eem left join sal on eem.eno=sal.eno;

17
ENO ENAME SAL
1 Aaa 30000
2 Bbb 50000
3 Ccc
2. Right outer join
SQL> select eem.eno,ename,sal from eem right join sal on eem.eno=sal.eno;

ENO ENAME SAL


1 Aaa 30000
2 Bbb 50000
60000
3. Full outer join
SQL> select eem.eno,ename,sal from eem full join sal on eem.eno=sal.eno;

ENO ENAME SAL


1 Aaa 30000
2 Bbb 50000
3 Ccc 60000

RESULT:
Thus the simple queries for Natural join,Equi join and Outer join operations are used for
retrieving information by joining tables have been verified and executed successfully.

18
Ex.No: 6 WRITE USER DEFINED FUNCTIONS AND STORED PROCEDURES IN

Date: SQL

AIM:
To write User Defined functions and stored procedures in SQL.

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 name--employee.hire,
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:
SETTING SERVEROUTPUT ON:
SQL> SET SERVEROUTPUT ON
1. PROCEDURE USING POSITIONAL PARAMETERS
SQL> SET SERVEROUTPUT ON
SQL> CREATE OR REPLACE PROCEDURE PROC1 AS2 BEGIN
3 DBMS_OUTPUT.PUT_LINE ('Hello from procedure...');
4 END;
5/
Hello from procedure...
PL/SQL procedure successfully completed.

2. PROCEDURE USING NOTATIONAL PARAMETERS

SQL> CREATE OR REPLACE PROCEDURE PROC2


2 (N1 IN NUMBER,N2 IN NUMBER,TOT OUT NUMBER) IS
3 BEGIN
19
4 TOT: = N1 + N2;
5 END;
6/

OUTPUT:
Procedure created.
SQL> VARIABLE T NUMBERSQL> EXEC PROC2 (33, 66: T)
PL/SQL procedure successfully completed.SQL> PRINT T
T

99

3. PROCEDURE FOR GCD NUMBERS

SQL> create or replace procedure prois


a number(3);b number(3);c number(3);d number(3);begin
a:=&a;
b:=&b; if(a>b) then c:=mod(a,b);if(c=0) then
dbms_output.put_line('GCD is');dbms_output.put_line(b);
else dbms_output.put_line('GCD is');dbms_output.put_line(c);
end if;else
d:=mod(b,a); if(d=0) then
dbms_output.put_line('GCD is');dbms_output.put_line(a);
else dbms_output.put_line('GCD is');
dbms_output.put_line(d);end if;
end if;end;

INPUT:
Enter value for a: 8old 8: a:=&a;
new 8: a:=8;
Enter value for b: 16old 9: b:=&b;
new 9: b:=16;
OUTPUT:
Procedure created.
SQL> set serveroutput on;
SQL> execute pro;
GCD is8
PL/SQL procedure successfully completed.

SYNTAX:

CREATE [OR REPLACE] PROCEDURE procedure_name (parameters list) IS

<declaration_section>BEGIN
<executable_section>EXCEPTION
<exception_section>END;
20
Addition of Two Numbers
1.Write a PL/SQL Program for Addition of Two Numbers

PROCEDURE
1. Start.
2. Initialize the necessary variables.
3. Develop the set of statements with the essential operational parameters.
4.Specify the Individual operation to be carried out.
5.Execute the statements.
6.Stop.

PL/ SQL General Syntax

SQL> DECLARE
<VARIABLE DECLARATION>;BEGIN
<EXECUTABLE STATEMENT >;END;

PL/SQL CODING FOR ADDITION OF TWO NUMBERS

SQL> declarea number;


b number;c number;begin a:=&a;
b:=&b;c:=a+b;
dbms_output.put_line('sum of'||a||'and'||b||'is'||c);end;
/
INPUT:
Enter value for a: 23old 6: a:=&a;
new 6: a:=23;
Enter value for b: 12old 7: b:=&b;
new 7: b:=12;
OUTPUT:
sum of23and12is35
PL/SQL procedure successfully completed.

2. Write a PL/SQL Program using if conditionPROCEDURE


STEP 1: Start
STEP 2: Initialize the necessary variables.STEP 3: invoke the if condition.
STEP 4: Execute the statements.STEP 5: Stop.

PL/ SQL GENERAL SYNTAX FOR IF CONDITION


SQL> DECLARE
<VARIABLE DECLARATION>;BEGIN
IF (CONDITION) THEN
<EXECUTABLE STATEMENT >;END;

Coding for If Statement:


DECLARE
21
b number;c number;BEGIN B:=10;
C:=20;
OUTPUT:
Procedure created.
SQL> EXECUTE PROC1
if(C>B) THEN
dbms_output.put_line('C is maximum');end if;
end;

OUTPUT:
C is maximum
PL/SQL procedure successfully completed.

3. PL/ SQL GENERAL SYNTAX FOR IF AND ELSECONDITION


SQL> DECLARE
<VARIABLE DECLARATION>;BEGIN
IF (TEST CONDITION) THEN
<STATEMENTS>;
ELSE
<STATEMENTS>;
ENDIF;
END;

Less then or Greater Using IF ELSE


SQL> declaren number; begin
dbms_output.put_line('enter a number');n:=&number;
if n<5 then
dbms_output.put_line('entered number is less than 5');else
dbms_output.put_line('entered number is greater than 5');end if;
end;
/

INPUT:
Enter value for number: 2old 5: n:=&number;
new 5: n:=2;

OUTPUT:
entered number is less than 5
PL/SQL procedure successfully completed.

4. PL/ SQL GENERAL SYNTAX FOR NESTED IF


SQL> DECLARE
<VARIABLE DECLARATION>;BEGIN
IF (TEST CONDITION) THEN
<STATEMENTS>;

22
ELSEIF (TEST CONDITION) THEN
<STATEMENTS>;
ELSE
<STATEMENTS>;
ENDIF;
END;

GREATEST OF THREE NUMBERS USING IF ELSEIF


SQL> declarea number;
b number;c number;d number;begin a:=&a;
b:=&b;
c:=&b; if(a>b)and(a>c) then
dbms_output.put_line('A is maximum');elsif(b>a)and(b>c)then dbms_output.put_line('B is
maximum');else
dbms_output.put_line('C is maximum');end if;
end;
/

INPUT:
Enter value for a: 21old 7: a:=&a;
new 7: a:=21;
Enter value for b: 12old 8: b:=&b;
new 8: b:=12;
Enter value for b: 45old 9: c:=&b;
new 9: c:=45;

OUTPUT:
C is maximum
PL/SQL procedure successfully completed.

5. PL/ SQL GENERAL SYNTAX FOR LOOPING STATEMENT


SQL> DECLARE
<VARIABLE DECLARATION>;BEGIN
LOOP
<STATEMENT>;END LOOP;
<EXECUTAVLE STATEMENT>;
END;
SUMMATION OF ODD NUMBERS USING FOR LOOP
SQL> declaren number;
sum1 number default 0;endvalue number;

begin endvalue:=&endvalue;n:=1;
for n in 1..endvalueloop
if mod(n,2)=1 then sum1:=sum1+n;end if;
end loop;

23
dbms_output.put_line('sum ='||sum1);end;
/
INPUT:
Enter value for endvalue: 4 old 6: endvalue:=&endvalue;
new 6: endvalue:=4;
OUTPUT:
sum =4
PL/SQL procedure successfully completed.

6. PL/ SQL GENERAL SYNTAX FOR WHILE LOOPING STATEMENT


SQL> DECLARE
<VARIABLE DECLARATION>;BEGIN
WHILE <condition>LOOP
<STATEMENT>;END LOOP;
<EXECUTAVLE STATEMENT>;END;

SUMMATION OF ODD NUMBERS USING WHILE LOOP


SQL> declaren number;
sum1 number default 0;endvalue number; begin endvalue:=&endvalue; n:=1;
while(n<endvalue)loop sum1:=sum1+n;
n:=n+2;
end loop;
dbms_output.put_line('sum of odd no. bt 1 and' ||endvalue||'is'||sum1);end;
/
INPUT:
Enter value for endvalue: 4 old 6: endvalue:=&endvalue;
new 6: endvalue:=4;

OUTPUT:
sum of odd no. bt 1 and4is4
PL/SQL procedure successfully completed.

PL/SQL FUNCTION:

PROCEDURE
1. Start.
2. Create the table with essential attributes.
3. Initialize the Function to carry out the searching procedure.
4. Frame the searching procedure for both positive and negative searching.
5.Execute the Function for both positive and negative result.
6.Stop.

EXECUTION:
SETTING SERVEROUTPUT ON:
SQL> SET SERVEROUTPUT ON

24
1. IMPLEMENTATION OF FACTORIAL USING FUNCTION
SQL>create function fnfact (n number)return number is
b number;begin b:=1;
for i in 1..nloop b:=b*i; end loop; return b; end;
/ SQL>Declare
n number:=&n;y number; begin y:=fnfact(n);
dbms_output.put_line(y);end;
/
Function created.
Enter value for n: 5
old 2: n number:=&n;new 2: n number:=5; 120
PL/SQL procedure successfully completed.

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> insert into phonebook values(20312,'vijay','120/5D','bharathi


street','NGOcolony','629002');1 row created.

SQL> insert into phonebook values(29467,'vasanth','39D4','RK bhavan','sarakkal vilai','629002');


1 row created.

SQL> select * from phonebook;

PHONE_NO USERNAME DOORNO STREET PLACE


PINCODE

20312 vijay 120/5D bharathi street


NGO colony629002
29467 vasanth 39D4 RK
bhavansarakkalvilai629002

SQL> create or replace function findAddress(phone in number) return varchar2 asaddress


varchar2(100);
begin
select username||','||doorno ||','||street ||','||place||','||pincode into address from phonebook
wherephone_no=phone;
return address;exception
whenno_data_found then return 'address not found';end;
/

25
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:
Vijay,120/5D,bharathi street,NGO colony,629002PL/SQL procedure successfully
completed.SQL> declare
2 address varchar2(100);
3 begin
4 address:=findaddress(23556);
5 dbms_output.put_line(address);
6 end;
7/

OUTPUT2:
Address not found
PL/SQL procedure successfully completed.

RESULT:

Thus SQL Procedures and user defined functions were written and executed successfully.

26
Ex.No: 7 EXECUTE COMPLEX TRANSACTIONS AND REALIZE DCL AND TCL

Date: COMMAND

AIM:
To write Execute complex transactions and realize DCL and TCL Command.

TCL COMMANDS:

COMMANDS OVERVIEW

 COMMIT - save work done & it is visible to other users.

 SAVEPOINT - identify a point in a transaction to which you can later roll back

 ROLLBACK - restore database to original since the last COMMIT

 SET TRANSACTION - Change transaction options like what rollback segment to


use

SAVEPOINT
Syntax: savepoint username;Input:
SQL> savepoint emp;
Output:
savepoint created;
COMMIT
Syntax: commit;
Input:
SQL> commit;
Output:
Commit complete.
ROLLBACK
Syntax:
rollback to savepoint_text_identifier;
Input:
SQL> rollback to emp;
Output:
Rollback complete.
DCL (Data Control Language)

27
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:
SQL>GRANT PRIVILEGES_NAME on object_name To user_name;
Example:
SQL>GRANT SELECT, UPDATE on emp To hemanth;
OUTPUT:
Query OK, 0 rows affected

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:
SQL>REVOKE SELECT, UPDATE ON emp FROM ravi;

OUTPUT:
Query OK, 0 rows affected

RESULT:
Thus the complex transactions using DCL and TCL commands are executed successfully.
28
Ex.No: 8 WRITE SQL TRIGGERS FOR INSERT, DELETE, AND UPDATE

Date: OPERATIONS IN A 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

SYNTAX FOR CREATING A TRIGGER:


Create or replace trigger<trigger_name>
{Before/After}
{Delete Insert Update} On<Table name>
[Referencing {OLD[AS] OLD new [AS] new}][For each row]
When (condition)Declare
<declaration section>Begin
<executable statement>
End;
Component of Trigger
Triggering SQL statement : SQL DML (INSERT, UPDATE and DELETE) statement that
executeand implicitly called trigger to execute.
Trigger Action : When the triggering SQL statement is execute, trigger automatically call and
PL/SQL trigger block execute.
Trigger Restriction : We can specify the condition inside trigger to when trigger is fire.
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 notexecute, depending
on the BEFORE trigger conditions block.
2. AFTER Trigger : AFTER trigger execute after the triggering DML statement (INSERT,

UPDATE, DELETE) executed. Triggering SQL statement is execute as soon as followed bythe
code of trigger before performing Database operation.
3. ROW Trigger : ROW trigger fire for each and every record which are performing INSERT,

UPDATE, DELETE from the database table. If row deleting is define as trigger event, when
trigger file, deletes the five rows each times from the table.
4. Statement Trigger : Statement trigger fire only once for each statement. If row deleting is

define as trigger event, when trigger file, deletes the five rows at once from the table.

29
5. Combination Trigger : Combination trigger are combination of two trigger type.

1. Before Statement Trigger : Trigger fire only once for each statement before thetriggering
DML statement.
2. Before Row Trigger : Trigger fire for each and every record before the triggeringDML
statement.
3. After Statement Trigger : Trigger fire only once for each statement after thetriggering DML
statement executing.
4. After Row Trigger : Trigger fire for each and every record after the triggering DMLstatement
executing.
PL/SQL TriggersInserting Trigger
SQL> CREATE or REPLACE TRIGGER trg1
2 BEFORE
3 INSERT ON customer
4 FOR EACH ROW
5 BEGIN
6 :new.name := upper(:new.name);
7 END;
8/

Trigger created.

SQL> select * from customer;

NAME CID ADDRESS SALARY


---------- --------- ---------- ---------
mani 200 Erode 30000
abi 201 namakkal 40000
rani 301 Salem 40000

SQL> insert into customer values('&name',&cid,'&address',&salary);Enter value for name: logu


Enter value for cid: 306
Enter value for address: salemEnter value for salary: 40000
old 1: insert into customer values('&name',&cid,'&address',&salary)new 1: insert into customer
values('logu',306,'salem',40000)

1 row created.SQL> select * from customer;

NAME CID ADDRESS SALARY

LOGU 306 salem 40000


mani 200 erode 30000
abi 201 namakkal 40000
rani 301 Salem 40000

This trigger execute BEFORE to convert name field lowercase to uppercase.

30
CREATION OF FIRST TABLE

SQL> create table student(regno number(10),name varchar2(10),dept varchar2(10),percentage


number(10));
Table created

SQL> select * from student;


REGNO NAME DEPT PERCENTAGE
1001 kani cse 70
1002 madhi cse 80
1003 sharan it 85
1004 sathya it 90
CREATION OF SECOND TABLE
SQL> create table bckupstu2(regno number(10),name varchar2(10),dept
varchar2(10),percentagenumber(10));
Table created.
TRIGGER -1:
SQL> create or replace trigger t1 after delete on student for each row
2 begin
3 insert into bckupstu2 values(:old.regno,:old.name,:old.dept,:old.percentage);
4 end;
5/
Trigger created.

SQL> select * from bckupstu2;no rows selected

SQL> delete from student where regno=1001;1 row deleted.

SQL> select * from bckupstu2;

REGNO NAME DEPT PERCENTAGE

1001 kani cse 70

SQL> select * from student;


REGNO NAME DEPT PERCENTAGE
1002 madhi cse 80
1003 sharan it 85
1004 sathya it 90
TRIGGER-2
SQL> create or replace trigger t2 after update of regno on student for each row
2 begin
3 insert into bckupstu2 values(:old.regno,:old.name,:old.dept,:old.percentage);

31
4 end;
5/

Trigger created.

SQL> update student set name='mozhi' where regno=1002;1 row updated.

SQL> select * from student;


REGNO NAME DEPT PERCENTAGE

1002 mozhi cse 80


1003 sharan it 85
1004 sathya it 90
S Q
L> select * from bckupstu2;
REGNO NAME DEPT PERCENTAGE

S Q1L
00>1upda t ksatundient set regcnsoe=1 5 where7r0egno=1002;1 ro updated.

SQL> select * from student;


REGNO NAME DEPT PERCENTAGE

1005 mozhi cse 80


1003 sharan it 85
1004 sathya it 90

SQL> select * from bckupstu2;


REGNO NAME DEPT PERCENTAGE

1001 kani cse 70


1002 mozhi cse 80
TRIGGER-3
SQL> create or replace trigger t3 before insert or update of name on student for each row
2 begin
3 :new.name:=upper(:new.name);
4 end;
5/

Trigger created.

SQL> insert into student values(1006,'anu','ece',91);1 row created.

32
SQL> select * from student;
REGNO NAME DEPT PERCENTAGE

1005 mozhi cse 80


1003 sharan it 85
1004 sathya it 90
1006 anu ece 91

SQL> select * from bckupstu2;


REGNO NAME DEPT PERCENTAGE
1001 kani cse 70
1002 mozhi cse 80

CREATION OF THIRD TABLE:


SQL> create table voter_master(voterid number(5),name varchar2(10),wardno number(4),dob
date,address varchar2(15),primary key(voterid,wardno));
Table created.

SQL> select * from voter_master;


VOTERID NAME WARDNO DOB ADDRESS

1000 Saran 5 03-JAN-91 Neru street erode


1001 Madhi 12 15-MAY-89 Gandhi nagar erode
2000 Priya 6 05-FEB-84 Yal street erode
CREATION OF FOURTH TABLE:

SQL> create table new_list(voterid number(5),wardno number(4),name char(20),description


char(20);
Table created.

SQL> select * from new_list;

VOTERID WARDNO NAME DESCRIPTION

1000 5 Saran Neru street erode


1001 12 Madhi Gandhi nagar erode
5000 21 Roja Ashok street erode
TRIGGER-4
SQL> create or replace trigger vot_trig after delete on voter_master for each rowdeclare
2 v_id number(5);
3 w_id number(4);
4 begin
5 v_id:=:old.voterid;
6 update new_list set description='shifted' where voterid=v_id;

33
7 end;
8/
Trigger created.
SQL> delete from voter_master where voterid=1000;1 row deleted.

SQL> select * from voter_master;


VOTERID NAME WARDNO DOB ADDRESS

1001 Madhi 12 15-MAY-89 Gandhi nagar erode


2000 Priya 6 05-FEB-84 Yal street erode

SQL> select * from new_list;


VOTERID WARDNO NAME DESCRIPTION

1000 5 Saran shifted


1001 12 Madhi Gandhi nagar erode
5000 21 Roja Ashok street erode

SQL> desc phonebook;

Name Null? Type


PHONE_NO NOT NULL NUMBER (6)
USERNAME VARCHAR2 (13)
DOORNO VARCHAR2 (5)
STREET VARCHAR2 (13)
PLACE VARCHAR2 (13)
PINCODE CHAR (6)

SQL> select * from phonebook;


PHONE_NO USERNAME DOORN STREET PLACE PINCOD

25301 priya 390 main street SIT colony 659002


25401 murthy 39D9 MS bhavan sai nagar 689002
25701 karthi 7 jay nagar chennai 600002

SQL> create or replace function findAddress(phone in number) return varchar2 as address


varchar2(100);
2 begin
3 select username||','||door no ||','||street ||','||place||','||Pincode into address from phonebook
4 where phone_no=phone;
5 return address;
6 exceptions
7 when no_data_found then return 'address not found';
8 end;

34
9/
Function created.
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 completed.SQL> 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.

35
Ex.No: 9 CREATE VIEW AND INDEX FOR DATABASE TABLES WITH A LARGE

Date: NUMBER OF RECORDS

AIM:
To create a view and index for database tables with a large number of records

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:
Create view<view name> as select from <table name>;
Description:
This command is used to view a single row from a particular table.
Viewing all columns from a single table:
Syntax:
Create view<view name> as select * from <table name>;
Description :
This is used to create view which displays all columns from a single table.
View specified column from a single table:
Syntax:
Create view<view table name> as select column1,column2 from <tablename>;
Description:
This command is used to create view which displays on a specified from a single table.
View specified column from a muliple table:
Syntax:
Create view<view table name> as select column1,column2,….columnn where „condition‟;

Description:
This is used to create view to display specified columns from multiple tables.
View all column from a muliple table:
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.

36
SYNTAX:

CREATE OR REPLACE VIEW <view name > AS < select statement >
INDEXES:
Database system uses indexes to avoid the need for large-table, full-table scans and disk sorts,
which are required when the SQL optimizer cannot find an efficient way to service the SQL
query.

RESULT:
Thus the view and index for database tables with a large number of records was created
successfully.

37
Ex.No: 10 CREATE AN XML DATABASE AND VALIDATE USING XML SCHEMA

Date:

AIM:
To create an XML database and validate it using XML schema.

XML(Extensible Markup Language)-used to describe data and supports information exchange


between computer systems such as websites,databases and third party applications
XML FILE CRAEATION:
CREATE AN XML FILE CALLED "EMPLOYEES.XML
<?xml version="1.0" encoding="UTF-8"?>
<employees>
<employee>
<id>001</id>
<name>John Doe</name>
<email>[email protected]</email>
<department>Marketing</department>
</employee>
<employee>
<id>002</id>
<name>Jane Smith</name>
<email>[email protected]</email>
<department>Finance</department>
</employee>
<employee>
<id>003</id>
<name>Bob Johnson</name>
<email>[email protected]</email>
<department>IT</department>
</employee>
</employees>

38
CREATE AN XML SCHEMA CALLED "EMPLOYEES.XSD
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="employees">
<xs:complexType>
<xs:sequence>
<xs:element name="employee" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="id" type="xs:string"/>
<xs:element name="name" type="xs:string"/>
<xs:element name="email" type="xs:string"/>
<xs:element name="department" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
XML FILE VALIDATION USING XML SCHEMA
XML SCHEMA-describes the structure of the XML document.It is also known as XML
Schema Definition(XSD)
LET'S VALIDATE OUR XML FILE USING THE XML SCHEMA:
<?php
$xml = new DOMDocument();
$xml->load('employees.xml');
if ($xml->schemaValidate('employees.xsd')) {
echo "Validation successful!";
} else {
echo "Validation failed!";
}?>
39
Output:
Validation successful!

RESULT:
Thus the XML database was created and it is validated by XML schema successfully.

40
Ex.No: 11 CREATE DOCUMENT, COLUMN AND GRAPH BASED DATA USING

Date: NOSQL DATABSE TOOLS

AIM:
To create a document,column and graph based data using NOSQL Database tools

Document-Based Data
// Insert a blog post into the blogposts collection
db.blogposts.insertOne({
title: "My First Blog Post",
content: "This is my very first blog post!",
author: "John Doe",
publishDate: ISODate("2023-04-07T00:00:00Z")
});
Column based data
// Create the userprofiles column family
db.createCollection("userprofiles", {
capped: false,
autoIndexId: true,
max: 10000
});

// Insert a user profile into the userprofiles column family


db.userprofiles.insertOne({
username: "johndoe",
email: "[email protected]",
firstName: "John",
lastName: "Doe",
phoneNumber: "+1-555-555-5555"
});

41
Graph based data
// Create the socialnetwork graph
db.createCollection("socialnetwork", {
capped: false,
autoIndexId: true,
max: 10000
});

// Insert a user into the socialnetwork graph


db.socialnetwork.insertOne({
name: "John Doe",
friends: []
});

// Create a connection between two users in the socialnetwork graph


db.socialnetwork.updateOne(
{ name: "John Doe" },
{ $push: { friends: "Jane Smith" } }
);
Output:
// Retrieve all blog posts from the blogposts collection
db.blogposts.find();
// Retrieve all user profiles from the userprofiles column family
db.userprofiles.find();
// Retrieve all users and their connections from the socialnetwork graph
db.socialnetwork.find();

Result:
Thus ,the document,column and graph based database application was successfully created.
42
Ex.No: 12 CASE STUDY USING ANY OF THE REAL LIFE DATABASE

Date: APPLICATIONS FROM THE FOLLOWING LIST

AIM:
To case study using the real life database applications –Inventory Management for a EMart
Grocery shop.

I. Inventory Management for a EMart Grocery Shop


Case Study:
eMart is a grocery shop that sells various products such as vegetables, fruits, meat, dairy, and
bakery products. The shop wants to track its inventory levels to ensure that it has enough stock to
meet customer demand while minimizing waste.
To accomplish this, eMart decides to implement an inventory management system using a
relational database. The database will have the following tables
 Products: contains information about each product, including its name, price, and quantity in

stock.
 Orders: contains information about each order, including the order date, the products ordered,

and the quantity of each product.


 Customers: contains information about each customer, including their name and contact

information.
Output:
Products Table
+ + + + +
| ID | Name | Price | Stock |
+ + + + +
| 1 | Apples | 2.50 | 100 |
| 2 | Bananas | 1.50 | 50 |
| 3 | Oranges | 2.00 | 75 |
| 4 | Carrots | 1.00 | 200 |
| 5 | Broccoli | 1.50 | 100 |
| 6 | Milk | 3.50 | 50 |

43
| 7 | Eggs | 2.00 | 100 |
| 8 | Chicken | 6.00 | 25 |
| 9 | Ground Beef | 5.00 | 30 |
| 10 | Sliced Bread | 2.50 | 50 |
+ + + + +
Orders Table
+ + + + +
| ID | CustomerID | ProductID | Quantity |
+ + + + +
|1 |1 |1 |5 |
|2 |1 |2 | 10 |
|3 |2 | 3, 4, 5 | 5, 10, 3 |
|4 |3 | 6, 7, 8, 9 | 2, 5, 1, 3 |
|5 |2 | 1, 2, 3, 4, 5, 6, 7, 8, 9 | 1, 1, 1, 1, 1, 1, 1, 1, 1 |
+ + + + +

Customers Table
+ + + + +
| ID | FirstName | LastName | ContactNumber |
+ + + + +
| 1 | John | Smith | 555-1234 |
| 2 | Jane | Doe | 555-5678 |
| 3 | Bob | Johnson | 555-9999 |
+ + + + +
II. Society Financial Management
XYZ Society is a housing society that manages the financial transactions of its members. The
society wants to implement a database system to manage its financial data efficiently. The
database will have the following tables
 Members: contains information about each member, including their name, address, and contact

information.
 Transactions: contains information about each financial transaction, including the transaction

date, amount, and type of transaction (e.g., maintenance fee, electricity bill, water bill, etc.).

44
 Invoices: contains information about each invoice generated, including the invoice date,

amount, and due date.


Members Table
+ + + + + +
| ID | FirstName | LastName | Address | ContactNumber|
+ + + + + +
| 1 | John | Smith | 123 Main St. | 555-1234 |
| 2 | Jane | Doe | 456 Elm St. | 555-5678 |
| 3 | Bob | Johnson | 789 Oak St. | 555-9999 |
+ + + + + +
Transactions Table
+ + + + + +
| ID | MemberID | Date | Type | Amount|
+ + + + + +
|1 |1 | 2022-01-01| Maintenance Fee | 100 |
|2 |1 | 2022-01-15| Electricity Bill| 50 |
|3 |2 | 2022-01-01| Maintenance Fee | 100 |
|4 |3 | 2022-01-01| Maintenance Fee | 100 |
|5 |1 | 2022-02-01| Maintenance Fee | 100 |
|6 |1 | 2022-02-15| Electricity Bill| 50 |
|7 |2 | 2022-02-01| Maintenance Fee | 100 |
|8 |3 | 2022-02-01| Maintenance Fee | 100 |
+ + + + + +
Invoices Table
+ + + + + +
| ID | MemberID | Date | DueDate | Amount|
+ + + + + +
|1 |1 | 2022-01-01| 2022-01-31| 150 |
|2 |2 | 2022-01-01| 2022-01-31| 100 |
|3 |3 | 2022-01-01| 2022-01-31| 100 |
|4 |1 | 2022-02-01| 2022-02-28| 150 |

45
|5 |2 | 2022-02-01| 2022-02-28| 100 |
|6 |3 | 2022-02-01| 2022-02-28| 100 |
+ + + +
III. Cop Friendly App – Eseva
Eseva is a cop-friendly app that is designed to help police officers access information and data
related to cases and suspects quickly. The app has a database system that stores all the necessary
information related to cases and suspects. The database will have the following tables
 Cases: contains information about each case, including the case ID, case description, case

status, and case category (e.g., homicide, theft, cybercrime, etc.).


 Suspects: contains information about each suspect, including their name, address, contact

information, and other personal details.


 Evidence: contains information about each piece of evidence collected in a case, including the

evidence ID, description, and the case ID it belongs to.


Cases Table
+ + + + +
| ID | Description | Status | Category |
+ + + + +
| 1 | Murder of John | Open | Homicide |
| 2 | Theft of Car | Closed | Theft |
| 3 | Cybercrime | Open | Cybercrime|
+ + + + +
Suspects Table
+ + + + + +
| ID | FirstName | LastName | Address | ContactNumber|
+ + + + + +
| 1 | Mark | Johnson | 123 Main St. | 555-1234 |
| 2 | Sarah | Smith | 456 Elm St. | 555-5678 |
| 3 | Bob | Williams | 789 Oak St. | 555-9999 |
+ + + + + +

46
Evidence Table
+ + + +
| ID | Description | CaseID |
+ + + +
| 1 | Bloodstains | 1 |
| 2 | Fingerprints | 1 |
| 3 | Video Footage| 1 |
| 4 | Car Parts |2 |
| 5 | Credit Card | 2 |
| 6 | Email Logs | 3 |
+ + + +
IV. Property Management – eMall
eMall is a property management system designed to manage properties like malls, shopping
centers, etc. The system has a database that stores all the necessary information related to
properties, tenants, and rental agreements. The database will have the following tables
 Properties: contains information about each property, including the property ID, property

name, location, and other details.


 Tenants: contains information about each tenant, including their name, contact information,

and other details.


 RentalAgreements: contains information about each rental agreement, including the rental

agreement ID, the property ID it belongs to, the tenant ID, rental start and end dates, and rental
amount.
Properties Table
+----+---------------+---------------+---------------------+-------------------+
| ID | PropertyName | Location | PropertyType | PropertyStatus |
+----+---------------+---------------+---------------------+-------------------+
| 1 | Phoenix Mall | Mumbai | Shopping Mall | Open |
| 2 | Westend Mall | Pune | Shopping Complex | Closed |
| 3 | Grand Central | Delhi | Shopping Center | Under Renovation |
+----+---------------+---------------+---------------------+-------------------+

47
Tenants Table
+ + + + + +
| ID | TenantName | ContactNumber | ContactEmail | TenantType |
+ + + + + +
| 1 | Brand Factory | 9123456789 | [email protected] | Retail Clothing |
| 2 | McDonald's | 9987654321 | [email protected] | Food & Beverages |
| 3 | PVR Cinemas | 9123456780 | [email protected] | Entertainment |
+ + + + + +
RentalAgreements Table
+ + + + + + +
| ID | PropertyID | TenantID| Rent | StartDate | EndDate |
+ + + + + + +
|1 |1 |1 | 100000 | 2022-01-01 | 2023-01-01 |
|2 |1 |2 | 50000 | 2022-06-01 | 2023-06-01 |
|3 |2 |3 | 75000 | 2022-04-01 | 2023-04-01 |
+ + + + + + +
V. Star Small and Medium Banking and Finance
Star Small and Medium Banking and Finance is a banking and finance system designed to
manage the banking transactions of small and medium-sized businesses. The system has a
database that stores all the necessary information related to customers, accounts, and
transactions. The database will have the following tables
 Customers: contains information about each customer, including their name, contact

information, and other details.


 Accounts: contains information about each account, including the account number, customer

ID, account type, and balance.


 Transactions: contains information about each transaction, including the transaction ID,

account number it belongs to, transaction type, amount, and transaction date.
Customers Table
+ + + + +
| ID | CustomerName | ContactNumber | ContactEmail |
+ + + + +

48
| 1 | ABC Corporation| 9123456789 | [email protected] |
| 2 | XYZ Company | 9987654321 | [email protected] |
| 3 | PQR Limited | 9123456780 | [email protected] |
+ + + + +
Accounts Table
+ + + + + +
| ID | AccountNumber | CustID | AccountType | Balance |
+ + + + + +
| 1 | 100001 |1 | Current | 500000 |

| 2 | 100002 |2 | Savings | 1000000


| 3 | 100003 |3 | Fixed |
+ + + + | 2500000
+ +
Transactions Table
+ + + + + + +
| ID | AccountNumber | TransactionType| Amount | TransDate | Description|
+ + + + + + +
| 1 | 100001 | Debit | 25000 | 2022-01-01 | Office Rent|
| 2 | 100002 | Credit | 50000 | 2022-02-01 | Customer Payment|
| 3 | 100003 | Debit | 100000 | 2022-03-01 | Fixed Deposit|
+ + + + + + +

RESULT:
Thus the case study using real life database application –Inventory Management for aEMart
Groery Shop was completed successfully.
49

You might also like