DBMS
DBMS
No: 1
DATABASE DEVELOPMENT LIFE CYCLE
AIM:
Developing a Database Development Life cycle with a Problem definition and
Requirement analysis Scope and Constraints.
Database Development Life cycle:
A database system is a fundamental component of the larger organization-wide
information system, the database system development lifecycle is inherently associated with
the lifecycle of the information system. The stages of the database system development
lifecycle shown below the name of each stage is the section in this chapter that describes that
stage.
1
Page
Class Diagram – Banking System:
RESULT:
Hence, a Database Development Life cycle with a Problem definition and
Requirement analysis Scope and Constraints developed and understood successfully.
2
Page
Ex. No.2:
MAPPING CONCEPTUAL TO RELATIONAL DATABASE
AIM:
Database design using Conceptual modeling (ER-EER) – top-down approach mapping
conceptual to relational database and validate using Normalization language.
Procedure:
For the following ER model (Conceptual Model), creating the corresponding relational
schema and map the ER model to Relational model.
Create an appropriate heading for the columns of the results table.
The following tables form part of a Library database held in an RDBMS:
Book (ISBN, title, edition, year)
BookCopy (copyNo, ISBN, available)
Borrower (borrowerNo, borrowerName, borrowerAddress)
BookLoan (copyNo, dateOut, dateDue, borrowerNo)
Where,
Book contains details of book titles in the library and the ISBN is the key.
BookCopy contains details of the individual copies of books in the library and copyNo is the
key. ISBN is a foreign key identifying the book title.
Borrower contains details of library members who can borrow books and borrowerNo is
the key.
BookLoan contains details of the book copies that are borrowed by library members and
copyNo/dateOut forms the key. borrowerNo is a foreign key identifying the Borrower.
Book
ISBN Title edition Year
BookCopy
copyNo ISBN Available
Borrower
borrowerNo borrowerName borrowerAddress
3
Page
BookLoan
copyNo dateOut dateDue borrowerNo
Output:
RESULT:
Hence, the corresponding relational model is created and used for the given ER model
successfully.
4
Page
Ex. No: 3
THE DATABASE USING SQL DATA DEFINITION WITH
CONSTRAINTS, VIEWS
AIM:
Implementing the database using SQL Data definition with constraints, Views.
Procedure:
1. Create a table called EMP with the following structure.
Name Type
---------- ----------------------
EMPNO NUMBER(6)
ENAME VARCHAR2(20)
JOB VARCHAR2(10)
DEPTNO NUMBER(3)
SAL NUMBER(7,2)
Allow NULL for all columns except ename and job.
2. Add a column experience to the emp table. experience numeric null allowed.
SQL> alter table emp add(experience number(2));
5. Create the emp1 table with ename and empno, add constraints to check the empno value
while entering (i.e) empno > 100.
8. The organization wants to display only the details of the employees those who are
ASP.(Horizontal portioning)
SQL> create view empview as select * from emp where job='ASP';
SQL> select * from empview;
9. The organization wants to display only the details like empno, empname, deptno,
deptname of the employees. (Vertical portioning)
SQL> create view empview1 as select ename,sal from emp;
RESULT:
Hence, the data definition language commands and views were performed and
implemented successfully.
6
Page
Ex. No: 4
QUERYING THE DATABASE USING SQL MANIPULATION
AIM:
Implementing the database using SQL Data definition with constraints, Views.
Procedure for doing the experiment:
Procedure:
1. Insert a single record into dept table.
SQL> insert into dept values (1,'IT','Tholudur');
2: Insert more than a record into emp table using a single insert command.
SQL> insert into emp values(&empno,'&ename','&job',&deptno,&sal);
3. Update the emp table to set the salary of all employees to Rs15000/- who are working as
ASP
SQL> select * from emp;
EMPNO ENAME JOB DEPTNO SAL
---------- -------------------- ------------- ---------- ----------
1 Mathi AP 1 10000
2 Arjun ASP 2 12000
3 Gugan ASP 1 12000
4. Create a pseudo table employee with the same structure as the table emp and insert rows
into the table using select clauses.
SQL> create table employee as select * from emp;
SQL> desc employee;
7. List the records in the emp table orderby salary in ascending order.
SQL> select * from emp order by sal;
8. List the records in the emp table orderby salary in descending order.
SQL> select * from emp order by sal desc;
7
Page
9. Display only those employees whose deptno is 30.
SQL> select * from emp where deptno=1;
10. Display deptno from the table employee avoiding the duplicated values.
SQL> select distinct deptno from emp;
RESULT:
Hence, the DML commands using from where clause was performed successfully and
executed.
8
Page
Ex.No:5
QUERYING/MANAGING THE DATABASE USING SQL PROGRAMMING
AIM:
Querying/Managing the database using SQL Programming Stored Procedures /
Functions Constraints and security using Triggers.
Procedures:
Create table student_mark (reg_no number(4) , mark1 number(3), mark2 number(3), mark3
number(3), total number(4), avg number(4));
Insert into student_mark (reg_no,mark1,mark2,mark3) values (1001,78,56,45);
Insert into student_mark (reg_no,mark1,mark2,mark3) values (1002,70,98,85);
Insert into student_mark (reg_no,mark1,mark2,mark3) values (3001,81,66,25);
Insert into student_mark (reg_no,mark1,mark2,mark3) values (4001,63,23,71);
Select * from student_mark;
1001 78 56 45 - -
1002 70 98 85 - -
3001 81 66 25 - -
4001 63 23 71 - -
Create table student (reg_no number(4), name varchar2(20), branch varchar2(10), dob date,
batch number(4));
insert into student values (1001,'Abinaya','CSE','10-Mar-2001',2018);
insert into student values (1003,'Keerthana','CSE','28-sep-2001',2018);
insert into student values (3004,'Manojkumar','ECE','17-Mar-2000',2018);
insert into student values (1002,'Aboorvan','CSE','11-May-2002',2018);
insert into student values (2006,'Naveena','IT','11-May-2002',2018);
select * from student;
9
Page
REG_NO NAME BRANCH DOB BATCH
Procedure Execution
begin
updatetotal(1001);
end;
select * from student_mark;
10
Page
REG_NO MARK1 MARK2 MARK3 TOTAL AVG
1001 78 56 45 179 60
1002 70 98 85 0 0
3001 81 66 25 0 0
2002 65 56 49 0 0
4001 63 23 71 0 0
Creation of Functions
1.Function Creation
Function created.
2.Function Execution
declare
rno number(5);
ssnm varchar2(20);
begin
rno := :Enter_reg_no;
ssnm:=get_sname (rno);
dbms_output.put_line('Student name: '||ssnm);
end;
11
Page
Input
:Enter_reg_no=1002
Output
Student name: ANBARASAN
Statement processed.
Input
:Enter_reg_no=3001
Output
Student name: ASHOK
Statement processed.
Input
:Enter_reg_no=2001
Output
ORA-01403: no data found
Function created.
4.Function Execution
declare
n number:=:Enter_n;
begin
dbms_output.put_line('Factorial of '||n||' is '||fact(n));
end;
Input
:Enter_n = 6
Output
Factorial of 6 is 720
Statement processed.
12
Page
5. Creation of database triggers
a) Trigger to update total & average mark
Create or replace trigger stdmarkupd before insert or update on student_mark for each
row
declare
Srno number(20);
begin
:new.total := :new.mark1+:new.mark2+:new.mark3;
:new.avg := (:new.mark1+:new.mark2+:new.mark3)/3;
end;
Trigger created.
1001 78 56 45 179 60
1002 99 98 85 282 94
3001 81 66 25 0 0
2002 65 56 49 0 0
4001 63 23 71 0 0
1003 67 78 57 202 67
RESULT:
Hence, the Querying/Managing the database using SQL Programming Stored
Procedures/Functions Constraints and security using Triggers were performed successfully
13
and executed.
Page
Ex.No: 6
DATABASE DESIGN USING NORMALIZATION BOTTOM-UP APPROACH
AIM:
To design a database using Normalization-Bottom Up approach.
In the above table, we can clearly see that the Phone Number column has two values.
Thus it violated the 1st NF. Now if we apply the 1st NF to the above table we get the
below table as the result.
We have achieved atomicity and also each and every column have unique values.
2nd Normal Form (2NF)
The first condition in the 2nd NF is that the table has to be in 1st NF. The table
also should not contain partial dependency. Here partial dependency means the
proper subset of candidate key determines a non-prime attribute.
DEPARTMENT ID OFFICE LOCATION
EMPLOYEE
1EDU001 ED-T1 Pune
ID
1EDU002 ED-S2 Bengaluru
1EDU003 ED-M1 Delhi
1EDU004 ED-T3 Mumbai
This table has a composite primary key Employee ID, Department ID. The non-
key attribute is Office Location. In this case, Office Location only depends on
Department ID, which is only part of the primary key.
14
Therefore, this table does not satisfy the second Normal Form. To bring this
table to Second Normal Form, we need to break the table into two parts.
Page
EMPLOYEE ID DEPARTMENT ID
1EDU001 ED-T1
1EDU002 ED-S2
1EDU003 ED-M1
1EDU004 ED-T3
DEPARTMENT ID OFFICE
LOCATION
ED-T1 Pune
ED-S2 Bengaluru
ED-M1 Delhi
ED-T3 Mumbai
In the table, the column Office Location is fully dependent on the primary key of that table,
which is Department ID.
3rd Normal Form (3NF)
The table has to be in 2NF before proceeding to 3NF. The other condition is
there should be no transitive dependency for non-prime attributes.
That means non-prime attributes (which doesn’t form a candidate key) should
not be dependent on other non-prime attributes in a given table.
So a transitive dependency is a functional dependency in which X → Z (X
determines Z) indirectly, by virtue of X → Y and Y → Z.
1DT15ENG01 NAME
Alex ID
15CS11 Goa
1DT15ENG02 Barry 15CS13 Bengaluru
1DT15ENG03 Clair 15CS12 Delhi
1DT15ENG04 David 15CS13 Kochi
SUBJECT ID SUBJECT
15CS11 SQL
15CS13 JAVA
15CS12 C++
15
15CS13 JAVA
Page
RESULT:
completed.
Page
Ex. No.7
DEVELOPING A DATABASE APPLICATION
AIM:
Develop database applications using IDE/RAD tools (Eg., NetBeans,VisualStudio)
Procedure :
1 Create the DB for banking system source request the using SQL
2 Establishing ODBC connection
3 Click add button and select oracle in ORA home 90 click finished
A window will appear give the data source name as oracle and give the
4 user id as Scott
Now click the test connection a window will appear with server and user
5 name give user as scott and password tiger Click ok
VISUAL BASIC APPLICATION:-
6 • Create standard exe project in to and design ms from in request
format
• To add ADODC project select component and check ms ADO
data control click ok
• Now the control is added in the tool book
• Create standard exe project in to and design ms from in request
format
ADODC CONTEOL FOR ACCOUNT FROM:-
7 Click customs and property window and window will appear and select
ODBC data source name as oracle and click apply as the some window.
a) Program:
CREATE A TABLE IN ORACLE
SQL>create table account(cname varchar(20),accno number(10),balance number);
Table Created
SQL> insert into account values('&cname',&accno,&balance);
Enter value for cname: Mathi
Enter value for accno: 1234 Enter
value for balance: 10000
old 1: insert into account values('&cname',&accno,&balance)
new 1: insert into emp values('Mathi',1234,10000) 1 row created.
SOURCE CODE FOR FORM1
Private Sub ACCOUNT_Click()
Form2.Show
End Sub
Private Sub EXIT_Click()
Unload Me
End Sub
Private Sub TRANSACTION_Click() Form3.Show
End Sub
SOURCE CODE FOR FORM 2
Private Sub CLEAR_Click()
17
Text1.Text = ""
Page
Text2.Text = ""
Text3.Text = "" End
Sub
End Sub
Page
19
Page
RESULT:
Hence, A database application -banking system has been developed using
20
Declare an extent for each class, and specify any key attributes as keys of the
extent.
included instead of the reference attribute. However, this does not allow the use
Page
of the inverse constraint. Additionally, if this choice is represented in both
directions, the attribute values will be represented twice, creating redundancy.
Step 3. Include appropriate operations for each class. These are not available
from the EER schema and must be added to the database design by referring to
the original requirements. A constructor method should include program code
that checks any constraints that must hold when a new object is created. A
destructor method should check any constraints that may be violated when an
object is deleted. Other methods should include any further constraint checks
that are relevant.
Step 4. An ODL class that corresponds to a subclass in the EER schema inherits
(via extends) the attributes, relationships, and methods of its superclass in the
ODL schema. Its specific (local) attributes, relationship references, and
operations are specified, as discussed in steps 1, 2, and 3.
Step 5. Weak entity types can be mapped in the same way as regular entity
types. An alternative mapping is possible for weak entity types that do not
participate in any relationships except their identifying relationship; these can
be mapped as though they were composite multivalued attributes of the owner
entity type, by using the set<struct<…>> or list<struct<…>> constructors. The
attributes of the weak entity are included in the struct<…> construct, which
corresponds to a tuple constructor.
Attributes are mapped as discussed in steps 1 and 2.
Step 6. Categories (union types) in an EER schema are difficult to map to ODL.
It is possible to create a mapping similar to the EER-to-relational mapping by
declaring a class to represent the category and defining 1:1 relationships
between the category and each of its superclasses.
Step 7. An n-ary relationship with degree n > 2 can be mapped into a separate
class, with appropriate references to each participating class. These references
are based on mapping a 1:N relationship from each class that represents a
participating entity type to the class that represents the n-ary relationship. An
M:N binary relationship, especially if it contains relationship attributes, may
also use this mapping option, if desired.
22
Page
EER Diagram Notation for a University database
23
Page
A UML class diagram corresponding to the EER diagram in above Figure
illustrating UML notation for specialization/generalization.
RESULT:
AIM:
Implementing Object features of SQL UDTs and sub types, Tables using UDTs,
Inheritance, Method definition.
Procdedure:
To implement a method, create the PL/SQL code and specify it within
a CREATE TYPE BODY statement.
For example, consider the following definition of an object type named rational
type:
CREATE TYPE rational_type AS OBJECT
( numerator INTEGER,
denominator INTEGER,
MAP MEMBER FUNCTION rat_to_real RETURN REAL,
MEMBER PROCEDURE normalize,
MEMBER FUNCTION plus (x rational_type)
RETURN rational_type);
RETURN ans;
Page
END;
Viva Questions:
1. What is a User-Defined Type (UDT) in programming, and how does it differ from a
built-in type?
2. How do you define a UDT in your programming language of choice, and what syntax
is used?
3. What are the primary features or components of a UDT? Can you provide an
example?
4. How can you create methods or functions to interact with a UDT, and how do these
methods differ from standard functions?
5. How does encapsulation work with UDTs, and why is it important for maintaining
object integrity?
26
RESULT:
Thus the SQL features have been understood clearly.
Page
Ex.No: 10
QUERYING THE OBJECT-RELATIONAL DATABASE USING OBJECT
QUERY LANGUAGE
AIM:
To create the querying the object-relational database using Object Query
Language
Procedure:
➢ Create the Table.
➢ Insert the Values.
➢ Display the Table.
Program:
CREATE TABLE Employees (FirstName VARCHAR(32) NOT NULL,
Surname VARCHAR(64) NOT NULL,DOB DATE NOT NULL,
Salary DECIMAL(10,2) NOT NULLCHECK ( Salary > 0.0 ),
Address_1 VARCHAR(64) NOT NULL,Address_2 VARCHAR(64)
NOT NULL, City VARCHAR(48) NOT NULL,State CHAR(2) NOT
NULL,ZipCode INTEGER NOT NULL,PRIMARY KEY ( Surname,
FirstName, DOB ));
INSERT INTO Employees ( Pager_Number, Pass_Code, Message )
SELECT E.Pager_Number,E.Pass_Code,
Print(E.Name) || ': Call 1-800-TEMPS-R-US for immediate INFORMIX
DBA job' FROM Temporary_Employees E WHERE Contains
(GeoCircle('(-122.514, 37.221)', '60 miles')),E.LivesAt )
AND DocContains ( E.Resume, 'INFORMIX and Database Administrator')
AND NOT IsBooked ( Period(TODAY, TODAY + 7),E.Booked );
SELECT *FROM Employees;
27
Page
Output:
RESULT:
28
Thus the querying the object-relational database using Object Query Language
has been designed successfully.
Page