0% found this document useful (0 votes)
0 views

DDM lab manual (1)

The document outlines a laboratory course on Database Design and Management, detailing various experiments related to database development life cycle, conceptual modeling, SQL implementation, and querying techniques. It includes specific aims, procedures, and results for each experiment, along with viva questions to assess understanding. The course covers topics such as normalization, data definition and manipulation languages, stored procedures, functions, and triggers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

DDM lab manual (1)

The document outlines a laboratory course on Database Design and Management, detailing various experiments related to database development life cycle, conceptual modeling, SQL implementation, and querying techniques. It includes specific aims, procedures, and results for each experiment, along with viva questions to assess understanding. The course covers topics such as normalization, data definition and manipulation languages, stored procedures, functions, and triggers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

AD3381 DATABASE DESIGN AND MANAGEMENT LABORATORY

CONTENTS

Ex.No. Title of the Experiments Page No.


Database Development Life cycle:
Problem definition and Requirement analysis Scope and 3
1
Constraints
Database design using Conceptual modeling (ER-EER) – top-
down approach Mapping conceptual to relational database and 6
2
validate using Normalization language

3 Implement the database using SQL Data definition with constraints, 8


Views
4 Query the database using SQL Manipulation 10
Querying/Managing the database using SQL Programming
- Stored Procedures/Functions 12
5
- Constraints and security using Triggers
6 Database design using Normalization – bottom-up approach 18

Develop database applications using IDE/RAD tools (Eg., 26


7 NetBeans,VisualStudio)

Database design using EER-to-ODB mapping / UML class 30


8 diagrams

Object features of SQL-UDTs and sub-types, Tables using UDTs, 37


9 Inheritance, Method definition

10 Querying the Object-relational database using Objet Query 40


language

2
Page
Ex. 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.

3
Page
Class Diagram – Banking System:

Viva Questions:
1. What are the main stages of the database life cycle, and what are the key activities involved in each
stage?
2. How does the conceptual design phase differ from the physical design phase in the database life
cycle?
3. What is the importance of requirements analysis in the database life cycle, and what are the potential
consequences of inadequate requirements gathering?
4. How is the implementation phase carried out in the database life cycle, and what tools or
technologies are typically used?
5. What are the best practices for database maintenance and monitoring post-deployment, and how do
they contribute to the overall database life cycle?
4
Page
RESULT:
Hence, a Database Development Life cycle with a Problem definition and
Requirement analysis Scope and Constraints developed and understood successfully.
5
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
6
Page
BookLoan
copyNo dateOut dateDue borrowerNo

Output:

Viva Questions:
1. What is the difference between a primary key and a foreign key in a relational database?
2. How does normalization help in designing a relational database, and what are the normal forms?
3. Can you explain the concept of ACID properties in the context of relational databases?
4. What are the advantages and disadvantages of using indexes in a relational database?
5. How do JOIN operations work in SQL, and what are the different types of JOINs available?

RESULT:
Hence, the corresponding relational model is created and used for the given ER model
successfully.
7
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.

SQL> create table emp(empno number(6),ename varchar2(20)not null,job varchar2(10) not


null, deptno number(3),sal number(7,2));

2. Add a column experience to the emp table. experience numeric null allowed.
SQL> alter table emp add(experience number(2));

3: Modify the column width of the job field of emp table.


SQL> alter table emp modify(job varchar2(12));
SQL> alter table emp modify(job varchar(13));

4. Create dept table with the following structure.


Name Type
---------------------------------
DEPTNO NUMBER(2)
DNAME VARCHAR2(10)
LOC VARCHAR2(10)
Deptno as the primarykey

SQL> create table dept(deptno number(2) primary key,dname varchar2(10),loc


varchar2(10));

5. Create the emp1 table with ename and empno, add constraints to check the empno value
while entering (i.e) empno > 100.

SQL> create table emp1(ename varchar2(10),empno number(6) constraint ch


check(empno>100));
8

6. Drop a column experience to the emp table.


Page

SQL> alter table emp drop column experience;


7. Truncate the emp table and drop the dept table
SQL> truncate table emp;
SQL> drop table dept;

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;

10. Display all the views generated.


SQL> select * from tab;

11. Execute the DML commands on the view created.


SQL> select * from empview;

Q12: Drop a view.


SQL> drop view empview1;

Viva Questions:
1. What is Data Definition Language (DDL) and how does it differ from DML (Data Manipulation
Language)?
2. Can you explain the purpose and syntax of the CREATE statement in DDL? Provide an example.
3. How does the ALTER statement work in DDL? What are some common operations you can perform
with it?
4. What are the differences between the DROP and TRUNCATE statements in DDL?
5. How do constraints (such as PRIMARY KEY, FOREIGN KEY, UNIQUE, and CHECK) work in
DDL, and how are they applied to database tables?

RESULT:
Hence, the data definition language commands and views were performed and
implemented successfully.
9
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

SQL> update emp set sal=15000 where job='ASP';


SQL> select * from emp;

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;

5. select employee name, job from the emp table


SQL> select ename, job from emp;

6. Delete only those who are working as lecturer


SQL> select * from emp;
SQL> delete from emp where job='lect';
SQL> select * from emp;

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;
10
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;

Viva Questions:

1. What is Data Manipulation Language (DML) and how does it differ from Data Definition Language
(DDL)?
2. What are the main operations of DML, and can you provide examples of each operation using SQL
commands?
3. How do the INSERT, UPDATE, and DELETE statements function in DML, and what are some
best practices to ensure data integrity when using these commands?
4. Can you explain the concept of transactions in DML and how the COMMIT and ROLLBACK
statements are used to manage them?
5. How does DML interact with constraints (such as foreign keys, primary keys, and unique
constraints) and what are some common issues that can arise when manipulating data with these
constraints in place?

RESULT:
Hence, the DML commands using from where clause was performed successfully and
executed.
11
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;

REG_NO MARK1 MARK2 MARK3 TOTAL AVG

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;
12
Page
REG_NO NAME BRANCH DOB BATCH

1001 Abinaya CSE 10-MAR-01 2018

3004 Manojkumar ECE 17-MAR-00 2018

1002 Aboorvan CSE 11-MAY-02 2018

2006 Naveena IT 11-MAY-02 2018

1003 Keerthana CSE 28-SEP-01 2018

Procedure Creation – To update total and average Mark


Create or replace procedure updatetotal(rno number) is
reg number;
M1 number;
M2 number;
M3 number;
null_name exception;
Begin
Select reg_no,mark1,mark2,mark3 into reg, m1,m2,m3 from student_mark
Where reg_no =rno;
if reg is null then
raise null_name;
else
update student_mark set total=m1+m2+m3, avg=(m1+m2+m3)/3
where reg = rno;
end if;
exception
when null_name then
dbms_output.put_line('Stdent no Not found');
end;

Procedure Execution
begin
updatetotal(1001);
end;
select * from student_mark;
13
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

Drop procedure updatetotal;


Procedure dropped.

Creation of Functions
1.Function Creation

create or replace function get_sname (rno number) return varchar2 is


sname student.name % type;
begin
select name into sname from student where reg_no=rno;
return(sname);
end;

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;
14
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

3.Function Creation (Factorial Calculation)


create or replace function fact(f number) return number is
a number;
fact1 number:=1;
begin
for a in 1..f
loop
fact1:=fact1*a;
end loop;
return fact1;
end;

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.
15
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.

update student_mark set mark1=99 where reg_no = 1002;


1 row(s) updated.

insert into student_mark(reg_no,mark1,mark2,mark3) values (1003,67,78,57);


1 row(s) inserted.
select * from student_mark;

REG_NO MARK1 MARK2 MARK3 TOTAL AVG

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

16
Page
Viva Questions:
1. What is a stored procedure in SQL and what are its key benefits?
2. How can you pass parameters to a stored procedure in SQL?
3. Explain the process of creating a stored procedure in SQL. Can you provide an example?
4. What are the common error handling mechanisms within SQL stored procedures?
5. How can you call a stored procedure within another stored procedure in SQL?

RESULT:
Hence, the Querying/Managing the database using SQL Programming Stored
Procedures/Functions Constraints and security using Triggers were performed successfully
and executed.
17
Page
Ex.No: 6
DATABASE DESIGN USING NORMALIZATION BOTTOM-UP APPROACH

AIM:
To design a database using Normalization-Bottom Up approach.

1st Normal Form (1NF)


In this Normal Form, we tackle the problem of atomicity. Here atomicity means
values in the table should not be further divided. In simple terms, a single cell cannot hold
multiple values. If a table contains a composite or multi-valued attribute, it violates the
First Normal Form

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
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.
18

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.

STUDENT ID STUDENT SUBJECT ID SUBJECT ADDRESS


NAME
1DT15ENG01 Alex 15CS11 SQL Goa
1DT15ENG02 Barry 15CS13 JAVA Bengaluru
1DT15ENG03 Clair 15CS12 C++ Delhi
1DT15ENG04 David 15CS13 JAVA Kochi

In the above table, Student ID determines Subject ID, and Subject


ID determines Subject.
Therefore, Student ID determines Subject via Subject ID. This implies that we
have a transitive functional dependency, and this structure does not satisfy the third
normal form.
STUDENT STUDENT SUBJECT ADDRESS

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
19

15CS12 C++
15CS13 JAVA
Page
Viva Questions:

1. What is the purpose of normalization in database design?


2. how does it help in reducing data redundancy?
3. Describe the different normal forms (1NF, 2NF, 3NF, BCNF).
4. How does the process of normalization impact the performance of a database in terms of read and
write operations?
5. What are some common pitfalls or challenges faced during the normalization process?

RESULT:

Hence, the database design using normalization bottom-up approach is successfully


completed.
20
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
21

Private Sub CLEAR_Click()


Text1.Text = ""
Page

Text2.Text = ""
Text3.Text = "" End
Sub

Private Sub DELETE_Click()


Adodc1.Recordset.DELETE
MsgBox "record deleted"
Adodc1.Recordset.MoveNext
If Adodc1.Recordset.EOF = True Then
Adodc1.Recordset.MovePrevious
End If End Sub
Private Sub EXIT_Click()
Unload Me
End Sub
Private Sub HOME_Click()
Form1.Show
End Sub
Private Sub INSERT_Click()
Adodc1.Recordset.AddNew End
Sub
Private Sub TRANSACTION_Click()
Form3.Show
End Sub
Private Sub UPDATE_Click()
Adodc1.Recordset.UPDATE
MsgBox "record updated successfully" End
Sub

SOURCE CODE FOR FORM 3

Private Sub ACCOUNT_Click()


Form2.Show
End Sub

Private Sub CLEAR_Click()


Text1.Text = ""
Text2.Text = "" End
Sub

Private Sub DEPOSIT_Click()


Dim s As String
s = InputBox("enter the amount to be deposited")
Text2.Text = Val(Text2.Text) + Val(s)
A = Text2.Text
MsgBox "CURRENT BALANCE IS Rs" + Str(A)
Adodc1.Recordset.Save
Adodc1.Recordset.UPDATE
22

End Sub
Page

Private Sub EXIT_Click()


Unload Me
End Sub

Private Sub HOME_Click()


Form1.Show
End Sub

Private Sub WITHDRAW_Click()


Dim s As String
s = InputBox("enter the amount to be deleted")
Text2.Text = Val(Text2.Text) - Val(s)
A = Text2.Text
MsgBox "current balance is Rs" + Str(A)
Adodc1.Recordset.Save
Adodc1.Recordset.UPDATE
End Sub
Output:

23
Page
Viva Questions:
1. What is Visual Basic (VB)?
2. What is an event in Visual Basic?
3. What is a form in Visual Basic?
4. What is an object in Java?
5. How do you declare a variable in Visual Basic?

RESULT:
24

Hence, A database application -banking system has been developed using


Visual Basic and Oracle.
Page
Exp. No.: 8
DATABASE DESIGN USING EER-TO-ODB MAPPING / UML CLASS
DIAGRAMS
AIM:
Design the database using EER-to-ODB mapping/UML class diagrams.
Procedure:
The outline of the mapping from EER to ODL is as follows:
Step 1. Create an ODL class for each EER entity type or subclass. The type of
the ODL class should include all the attributes of the EER class. Multivalued
attributes are typically declared by using the set, bag, or list constructors. If the
values of the multivalued attribute for an object should be ordered, the list
constructor is chosen; if duplicates are allowed, the bag constructor should be
chosen; otherwise, the set constructor is chosen. Composite attributes are
mapped into a tuple constructor (by using a struct declaration in ODL).

Declare an extent for each class, and specify any key attributes as keys of the
extent.

Step 2. Add relationship properties or reference attributes for each binary


relationship into the ODL classes that participate in the relationship. These may
be created in one or both directions. If a binary relationship is represented by
references in both directions, declare the references to be relationship properties
that are inverses of one another, if such a facility exists.36 If a binary
relationship is represented by a reference in only one direction, declare the
reference to be an attribute in the referencing class whose type is the referenced
class name.

Depending on the cardinality ratio of the binary relationship, the


relationship properties or reference attributes may be single-valued or collection
types. They will be single-valued for binary relationships in the 1:1 or N:1
directions; they will be collection types (set-valued or list-valued37) for
relationships in the 1:N or M:N direction. An alternative way to map binary
M:N relationships is discussed in step 7.

If relationship attributes exist, a tuple constructor (struct) can be used to


create a structure of the form <reference, relationship attributes>, which may be
25

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.
26
Page
EER Diagram Notation for a University database

27
Page
A UML class diagram corresponding to the EER diagram in above Figure
illustrating UML notation for specialization/generalization.

Viva Questions:
1. What is a UML class diagram?
2. What are the main components of a UML class diagram?
3. How do you represent a class and its attributes in a UML class diagram?
4. What types of relationships can be depicted in a UML class diagram?
5. How do you indicate visibility (public, private, protected) of class members in a UML
class diagram?

RESULT:
28

The given EER diagram notation is mapped to corresponding UML as well as


Page

corresponding ODB schema successfully.


Ex.No:9
OBJECT FEATURES OF SQL-UDTs

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);

Example: The following definition is shown merely because it defines the


function gcd, which is used in the definition of the normalize method in
the CREATE TYPE BODY statement later in this section.

CREATE FUNCTION gcd (x INTEGER, y INTEGER) RETURN INTEGER


AS
-- Find greatest common divisor of x and y. For example, if
-- (8,12) is input, the greatest common divisor is 4.
-- This will be used in normalizing (simplifying) fractions.
-- (You need not try to understand how this code works, unless
-- you are a math wizard. It does.)
--
ans INTEGER;
BEGIN
IF (y <= x) AND (x MOD y = 0) THEN
ans := y;
ELSIF x < y THEN
ans := gcd(y, x); -- Recursive call
ELSE
ans := gcd(y, x MOD y); -- Recursive call
END IF;
29

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?

30

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;
31
Page
Output:

Viva Questions:

1. What is Object Query Language (OQL) and how does it differ from SQL?
2. How do you use OQL to retrieve all instances of a specific class in an object-oriented
database?
3. What syntax does OQL use for querying object attributes and relationships?
4. How can you perform a join operation in OQL to combine data from related objects?
5. Can you write a simple OQL query to find objects that meet certain criteria, such as
those with a specific attribute value?

RESULT:
Thus the querying the object-relational database using Object Query Language
has been designed successfully.
32
Page

You might also like