DBMS Lab Record
DBMS Lab Record
Ex.no: 01
Database Development Life cycle: Problem definition and
Date: Requirement analysis Scope and Constraints
Aim:
To Database Development Life cycle: Problem definition and Requirement analysis
Scope and Constraints
Query :
desc student1;
CREATE TABLEcontact(
student_id number(10),
phone_no number(12) NOT
NULL, dob date,
department varchar(10),
FOREIGN KEY(student_id) references student1(student_id));
desc contact;
Output :
Table created
Table created
Table created
310123243072
Aim :
To develop a Database design using Conceptual modeling (ER-EER) – top-down approach Mapping
conceptual to relational database and validate using Normalization.
WHAT IS NORMALIZATION?
Normalization is the process of organizing the data in the database.Normalization is used to minimize the
redundancy from a relation or set of relations. It is also used to eliminate undesirable characteristics like
Insertion, Update, and Deletion Anomalies.
2NF A relation will be in 2NF if it is in 1NF and all non-key attributes are fully functional
dependent on the primary key.
ER MODEL
The ER model defines the conceptual view of a database. It works around real-world entities and the
associations among them. At view level, the ER model is considered a good option for designing
databases.
310123243072
310123243072
310123243072
Query :
Output :
Table created.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
Table created.
1 row(s) inserted
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
Table created.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
Table created.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
DEPT_ID DEPT_TITLE
14 President
20 Manager
12 Manager
Table created.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
DEPT_ID DEPT_DESC
14 Accounting
20 Sales
12 Research
310123243072
Table created.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
Table created.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
Table created.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
Table created.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
Table created.
1 row(s) inserted.
1 row(s) inserted.
EMP_ID EMP_COUNTRY
264 India
364 UK
310123243072
Table created.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
Table created.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
EMP_ID EMP_DEPT
264 Designing
264 Testing
364 Stores
364 Developing
310123243072
Ex.no:03
Implement the database using SQL Data definition with
Date: constraints, Views
Aim:
To implement the database using SQL Data definition with constraints, Views
Query :
#STAFF TABLE
#BRANCH TABLE
VIEW
#STUDENT TABLE
Output :
#STAFF TABLE
Table created.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
#BRANCH TABLE
Table created.
1 row(s) inserted.
# WORKING OF DEFAULT
1 row(s) inserted.
310123243072
1 row(s) inserted.
VIEWS
#STUDENT TABLE
Table created.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
#VIEW CREATED
View created.
View created.
#DISPLAY VIEW S1
#DROP VIEW S1
View dropped.
#DISPLAY VIEW S1
#DISPLAY VIEW S2
AGE DEPT
20 AI
19 IT
21 CS
310123243072
Ex.no:04
Query the database using SQL
Date: Manipulation
Aim:
To implement the Query the database using SQL Manipulation
Query :
#DATE FUNCTION
# NUMERIC FUNCTIONS
#CHARACTER FUNCTIONS
#CONVERSION FUNCTION
#MISCELLANEOUS FUNCTIONS
# GROUP FUNCTIONS
#COUNT FUNCTION
#SQL ORDER BY
# SQL ALIAS
SELECT firstname,lastname, age FROM stud WHERE age between 20 AND 30;
# SQL IN OPERATOR
# NESTED SUBQUERIES
#IN
#NOT IN
#EXISTS
SELECT title FROM book WHERE exists (SELECT * FROM author WHERE
author.bookid=book.bookid);
#NOT EXISTS
SELECT title FROM book WHERE NOT EXISTS (SELECT * FROM author WHERE
author.bookid=book.bookid);
310123243072
#SOME
SELECT title FROM book WHERE price>some (SELECT price FROM book WHERE pub_year=2005);
# ALL
SELECT title FROM book WHERE price>all (SELECT price FROM book WHERE pub_year<2003);
#DELETE
Output :
Table created.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) updated.
1 row(s) deleted.
#DATE FUNCTION
# NUMERIC FUNCTIONS
310123243072
#CHARACTER FUNCTIONS
310123243072
#CONVERSION FUNCTION
#MISCELLANEOUS FUNCTIONS
310123243072
# GROUP FUNCTIONS
#COUNT FUNCTION
#SQL ORDER BY
310123243072
FIRSTNAME SUM(AGE)
Ram 24
Shyam 29
FIRSTNAME SUM(AGE)
Ram 24
Shyam 29
310123243072
# SQL ALIAS
# SQL IN OPERATOR
no data found
AGE
28
24
# NESTED SUBQUERIES
Table created.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
#IN
#NOT IN
Table created.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
310123243072
#EXISTS
#NOT EXISTS
no data found
#SOME
# ALL
#DELETE
1 row(s) deleted.
310123243072
Ex.no:05
Querying/Managing the database using SQL Programming -
Date: Stored Procedures/Functions - Constraints and security using
Triggers.
Aim:
To Querying/Managing the database using SQL Programming – Stored Procedure /
Functions – Constraints and security using Triggers
Query :
declare
a number(10);
b number(10);
begin
a:=10;
b:=8;
dbms_output.put_line('THE PREV VALUES OF A AND B WERE');
dbms_output.put_line(a);
dbms_output.put_line(b);
a:=a+b;
b:=a-b;
a:=a-b;
dbms_output.put_line('THE VALUES OF A AND B WERE');
dbms_output.put_line(a);
dbms_output.put_line(b);
end;
# THE LARGEST OF TWO NUMBERS
declare
a number;
b number;
begin
a:=10;
b:=8;
if a=b
then dbms_output.put_line('BOTH ARE EQUAL');
elsif
a>b
then
dbms_output.put_line('A IS GREATER');
else
dbms_output.put_line('B IS GREATER');
end if;
end;
310123243072
declare
pi constant number(4,2):=3.14;
radius number(5):=3;
area number(6,2);
begin
while radius<7 loop
area:=pi*power(radius,2);
radius:=radius+1;
end loop;
end;
declare
mano number(5,2);
mcb number(6,2);
minibal constant number(7,2):=1000.00;
fine number(6,2):=100.00;
begin mano:=234.00;
if mcb<minibal then
end if;
end;
SELECT * FROM acct50;
310123243072
PROCEDURE
# CREATE A PROCEDURE TO DISPLAY A MESSAGE
# CREATE A PROCEDURE WHICH ACCEPTS TWO NUMBERS AND DISPLAY ITS SUM.
FUNCTIONS
# TO FIND THE GRADE OF THE STUDENT.
declare
a number(3);
begin
a:=datas51(a);
end;
310123243072
TRIGGER
create or replace trigger tri52 after insert on snt52 for each row
begin
dbms_output.put_line('record inserted');
end;
Output :
Statement processed.
A IS GREATER
Statement processed.
Table created.
Statement processed.
Table created.
1 row(s) inserted.
Statement processed.
310123243072
PROCEDURE
Hello World
Statement processed.
# CREATE A PROCEDURE WHICH ACCEPTS TWO NUMBERS AND DISPLAY ITS SUM.
Procedure created.
The sum is 5
Statement processed.
Table created.
1 row(s) inserted.
Procedure created.
Statement processed.
ENOSALARY
12 3045
FUNCTIONS
Function created.
grade is d
Statement processed.
310123243072
TRIGGER
Table created.
Trigger created.
record inserted
1 row(s) inserted.
STUNAMEROLLNO
A 1
Table created.
Trigger created.
Thank You
1 row(s) inserted.
Thank You
1 row(s) inserted.
Thank You
1 row(s) updated.
Thank You
1 row(s) deleted.
LOCDEPTNO
DELHI10
Table created.
Trigger created.
1 row(s) inserted.
2 row(s) deleted.
310123243072
Ex.no:06
Database design using Normalization – bottom-up approach
Date:
Aim:
To implement database design using Normalization – bottom-up approach
Query :
Output :
Aim:
To Develop database applications using IDE/RAD tools
Query :
#MYSQL QUERY
Mysql> create database student;
Mysql> use student;
Mysql> select * from details;
#JAVA PROGRAM 7
Package mini project;
import java.sql.connection;
Public class insert{
Public static void main(String[]args) throws ClassNotFoundException, SQLException {
Class.forName(“com.mysql.cj.jdbc.Driver”);
Connection con=DriverManager.getConnection(“jdbc:mysql//localhost:
3306/student”,”root”,”skm03102001”);
PreparedStatement ps=con.prepareStatement(“insert into detailsvalues(?,?,?,?,?,?,?”);
Scanner sc=new Scanner(System.in);
System.out.println(“enter register number:”);
int a=sc.nextInt();
System.out.println(“enter student name:”);
Stringb=sc.next();
System.out.println(“enter student branch:”);
String c=sc.next();
System.out.println(“enter student department:”);
String d=sc.next();
System.out.println(“enter joining year:”);
int e=sc.next();
System.out.println(“enter passout year:”);
int f=sc.next();
ps.setInt(1,a);
ps.setString(2,b);
ps.setString(3,c);
ps.setString(4,d);
ps.setInt(5,e);
ps.setInt(6,f);
int z=ps.executeUpdate();
System.out.println(z+”record inserted”);
con.close();
}
}
310123243072
Output :
310123243072
Ex.no:08
Database design using EER-to-ODB mapping / UML class
Date: diagrams
Aim:
To implement the database design using EER-to-ODB mapping / UML class
diagrams
UML Class Diagram for Online Shopping System
310123243072
Query :
OBJECT NAMES:
i. ADMIN
ii. CUSTOMER
iii. PRODUCTS
iv. CART
v. PAYMENT
vi. ORDER STATUS
vii. GUEST USER
Output :
310123243072
Ex.no:09
Object features of SQL-UDTs and sub-types, Tables
Date: using UDTs, Inheritance, Method definition
Aim:
To implement the Object features of SQL-UDTs and sub-types, Tables using
UDTs, Inheritance, Method definition
Query :
Output :
Type created.
310123243072
Ex.no:10
Querying the Object-relational database using Objet Query
Date: language
Aim:
To implement the Querying the Object-relational database using Objet Query language
Query :
declare
residence address;
begin
residence := address('01','anna nagar','chennai','tamilnadu','600001');
dbms_output.put_line('House No: '|| residence.house_no);
dbms_output.put_line('Street: '|| residence.street);
dbms_output.put_line('City: '|| residence.city);
dbms_output.put_line('State: '|| residence.state);
dbms_output.put_line('Pincode: '|| residence.pincode);
end;
310123243072
Output :