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

DDM-1

The document outlines the curriculum for the Database Design and Management Laboratory course at Arunai Engineering College for the academic year 2024-2025, detailing various experiments and their objectives. It covers the Database Development Life Cycle (DDLC), including phases like requirement analysis, design, implementation, and maintenance, as well as the use of SQL for database creation and management. Additionally, it discusses constraints in PostgreSQL and provides examples of database design using conceptual modeling and SQL commands.

Uploaded by

vmohan74748
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)
4 views

DDM-1

The document outlines the curriculum for the Database Design and Management Laboratory course at Arunai Engineering College for the academic year 2024-2025, detailing various experiments and their objectives. It covers the Database Development Life Cycle (DDLC), including phases like requirement analysis, design, implementation, and maintenance, as well as the use of SQL for database creation and management. Additionally, it discusses constraints in PostgreSQL and provides examples of database design using conceptual modeling and SQL commands.

Uploaded by

vmohan74748
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/ 53

ARUNAI ENGINEERING COLLEGE

(Autonomous)
Velu Nagar, Thiruvannamalai-606603
www.arunai.org

DEPARTMENT OF CSE [AI&ML]

BACHELOR OF ENGINEERING

2024 – 2025 (EVEN SEMESTER)

SECOND YEAR

AL3381-DATABASE DESIGN AND


MANAGEMENT LABORATORY

1
ARUNAI ENGINEERING COLLEGE
(Autonomous)
TIRUVANNAMALAI – 606 603

DEPARTMENT OF CSE [AI&ML]


CERTIFICATE

Certified that this is a bonafide record of work done by

Name :

University Reg.No :

Semester :

Branch :

Year :

Staff-in-Charge Head of the Department

Submitted for the


Practical Examination held on

Internal Examiner External Examiner

2
EX.NO DATE EXPERIMENTS PAGE NO SIGN

Database Development Life


1 22/01/25 cycle:Problem definition and 04
Requirement analysis Scope and
Constraints
Database design using Conceptual
2 29/01/25 modeling (ER-EER) – top-down 12
approach Mapping conceptual to
relational database and validate using
Normalization
Implement the database using SQL
3 05/02/25 Data definition with constraints, 14
Views

4 08/02/25 Query the database using SQL 19


Manipulation
Querying/Managing the database
using SQL Programming- Stored
5 12/02/25 Procedures/Functions- Constraints 22
and security using Triggers
Database design using
6 19/02/25 Normalization – bottom-up 35
approach
Develop database applications using
7 08/03/25 IDE/RAD tools (Eg., NetBeans, 38
Visual Studio)

Database design using EER-to-ODB


8 15/03/25 mapping/ UML class diagrams 41
Object features of SQL-UDTs and
9 19/03/25 sub-types, Tables using UDTs, 46
Inheritance, Method
definition
Querying the Object-relational
10 02/04/25 database using Objet Query language 50

3
lOMoARcPSD|25110721

1. Database Development Life cycle:Problem definition and Requirement


analysis Scope and Constraints

Aim: To understand Database development Life cycle with its problem definition
and requirement analysis along with their scope and constrains for different applications

Database Development Life Cycle: Database Development Life Cycle


What are the different phases of database development Life cycle (DBMS)?
The different phases of database development life cycle (DDLC) in the Database Management
System (DBMS)
Requirement analysis.

Database design.

Evaluation and selection.

Logical database design.

Physical database design.

Implementation.

Data loading.

Testing and performance tuning.

Operation.

Maintenance.

Requirement Analysis
The most important step in implementing a database system is to find out what is needed i.e what
type of a database is required for the business organization, daily volume of data, how much data
needs to be stored in the master files etc. In order to collect all this information, a database

4
lOMoARcPSD|25110721

analyst spends a lot of time within the business organization talking to people, end users
and getting acquainted with the day-to-day process.
Database Design
In this phase the database designers will make a decision on the database model that perfectly suits
the organization’s requirement. The database designers will study the documents prepared by the
analysis in the requirement analysis stage and then start development of a system model that fulfils
the needs.
Evaluation and selection
In this phase, we evaluate the diverse database management systems and choose the one which
perfectly suits the requirements of the organization.In order to identify the best performing
database, end users should be involved.
Logical database design
Once the evaluation and selection phase is completed successfully, the next step is logical
database design.This design is translated into internal model which includes mapping of all
objects i.e design of tables, indexes, views, transaction, access privileges etc.,
Physical Database Design
This phase selects and characterizes the data storage and data access of the database.The data
storage depends on the type of devices supported by the hardware, the data
access methods.Physical design is very vital because of bad design which results in poor
performance. Implementation
Database implementation needs the formation of special storage related constructs. These
constructs consist of storage groups, table spaces, data files, tables etc.
Data Loading
Once the database has been created, the data must be loaded into the database. The data required
to be converted, if the loaded date is in a different format.
Operations
In this phase, the database is accessed by the end users and application programs.This
stage includes adding of new data, modifying existing data and deletion of absolute data. This
phase provides useful information and helps management to make a business decision.

5
lOMoARcPSD|25110721

Maintenance

It is one of the ongoing phases in DDLC.The major tasks included are database backup
and recovery, access management, hardware maintenance etc.
Database Life Cycle (DBLC)
The Database Life Cycle (DBLC) contains six phases, as shown in the following Figure:
database initial study, database design, implementation and loading, testing and evaluation,
operation, and maintenance and evolution.

6
lOMoARcPSD|25110721

1. The Database Initial Study:


In the Database initial study, the designer must examine the current system’s operation within the
company and determine how and why the current system fails. The overall purpose of the database
initial study is to: • Analyze the company situation.

• Define problems and constraints.

• Define objectives.

• Define scope and boundaries.

a. Analyze the Company Situation:


The company situation describes the general conditions in which a company operates its
organizational structure, and its mission. To analyze the company situation, the database
designer must discover what the company’s operational components are, how they function, and
how they interact.

b. Define Problems and Constraints:


The designer has both formal and informal sources of information. The process of defining
problems might initially appear to be unstructured. Company end users are often unable to
describe precisely the larger scope of company operations or to identify the real problems
encountered during company operations.

c. Define Objectives:
A proposed database system must be designed to help solve at least the major problems
identified during the problem discovery process. In any case, the database designer must begin to
address the following questions:
• What is the proposed system’s initial objective?

• Will the system interface with other existing or future systems in the company?

• Will the system share the data with other systems or users?

d. Define Scope and Boundaries:


The designer must recognize the existence of two sets of limits: scope and boundaries.
The system’s scope defines the extent of the design according to operational requirements. Will

7
lOMoARcPSD|25110721

the database design encompass the entire organization, one or more departments within
the organization, or one or more functions of a single department? Knowing the scope
helps in defining the required data structures, the type and number of entities, the physical
size of the database, and so on.
The proposed system is also subject to limits known as boundaries, which are external to
the system. Boundaries are also imposed by existing hardware and software.

2. Database Design:
The second phase focuses on the design of the database model that will support company
operations and objectives. This is arguably the most critical DBLC phase: making sure that the
final product meets user and system requirements. As you examine the procedures required to
complete the design phase in the DBLC, remember these points:
• The process of database design is loosely related to the analysis and design of a larger system.
The data component is only one element of a larger information system.
• The systems analysts or systems programmers are in charge of designing the other system
components. Their activities create the procedures that will help transform the data within the
database into useful information.

3. Implementation and Loading:


The output of the database design phase is a series of instructions detailing the creation of tables,
attributes, domains, views, indexes, security constraints, and storage and performance guidelines.
In this phase, you actually implement all these design specifications.

a. Install the DBMS:


This step is required only when a new dedicated instance of the DBMS is necessary for
the system. The DBMS may be installed on a new server or it may be installed on existing servers.
One current trend is called virtualization. Virtualization is a technique that creates logical
representations of computing resources that are independent of the underlying physical
computing resources.
b. Create the Database(s):
In most modern relational DBMSs a new database implementation requires the creation of
special storage-related constructs to house the end-user tables. The constructs usually include the
storage group (or file groups), the table spaces, and the tables
c. Load or Convert the Data:
After the database has been created, the data must be loaded into the database tables. Typically,
the data will have to be migrated from the prior version of the system. Often, data to be included

8
lOMoARcPSD|25110721

in the system must be aggregated from multiple sources. Data may have to be imported
from other relational databases, non relational databases, flat files, legacy systems, or even
manual paper-and-pencil system.
. Testing and Evaluation:
In the design phase, decisions were made to ensure integrity, security, performance, and
recoverability of the database. During implementation and loading, these plans were put
into place. In testing and evaluation, the DBA tests and fine-tunes the database to ensure
that it performs as expected. This phase occurs in conjunction with applications programming.

a. Test the Database:


During this step, the DBA tests the database to ensure that it maintains the integrity and security
of the data. Data integrity is enforced by the DBMS through the proper use of primary
and foreign key rules. In database testing you must check Physical security allows, Password
security, Access rights, Data encryption etc.

b. Fine-Tune the Database:


Although database performance can be difficult to evaluate because there are no standards for
database performance measures, it is typically one of the most important factors in database
implementation. Different systems will place different performance requirements on
thedataset.. Many factors can impact the database’s performance on various tasks. Environmental
factors, such as the hardware and software environment in which the database exists, can have a
significant impact on database performance.

c. Evaluate the Database and Its Application Programs:


As the database and application programs are created and tested, the system must also be
evaluated from a more holistic approach. Testing and evaluation of the individual components
should culminate in a variety of broader system tests to ensure that all of the components interact
properly to meet the needs of the users. To ensure that the data contained in the database are
protected against loss, backup and recovery plans are tested

5. Operation
Once the database has passed the evaluation stage, it is considered to be operational. At
that point, the database, its management, its users, and its application programs constitute a
complete information system. The beginning of the operational phase invariably starts the
process of system evolution.

9
lOMoARcPSD|25110721

6. Maintenance and Evolution


The database administrator must be prepared to perform routine maintenance activities within the
database. Some of the required periodic maintenance activities include:
• Preventive maintenance (backup).

• Corrective maintenance (recovery).

• Adaptive maintenance (enhancing performance, adding entities and attributes, and so on).

• Assignment of access permissions and their maintenance for new and old users.

Problem definition and Requirement analysis:


Problem Definition:
The designer has both formal and informal sources of information. The process of defining
problems might initially appear to be unstructured. Company end users are often unable to
describe precisely the larger scope of company operations or to identify the real problems
encountered during company operations.

Requirement analysis
The most important step in implementing a database system is to find out what is needed i.e what
type of a database is required for the business organization, daily volume of data, how much data
needs to be stored in the master files etc.
In order to collect all this information, a database analyst spends a lot of time within the business
organization talking to people, end users and getting acquainted with the day-to-day process.

Scope and Constrains using PostgreSQL:


The following are commonly used constraints available in PostgreSQL.
NOT NULL Constraint − Ensures that a column cannot have NULL value.

UNIQUE Constraint − Ensures that all values in a column are different.

PRIMARY Key − Uniquely identifies each row/record in a database table.

FOREIGN Key − Constrains data based on columns in other tables.

CHECK Constraint − The CHECK constraint ensures that all values in a column
satisfy certain conditions.

EXCLUSION Constraint − The EXCLUDE constraint ensures that if any two rows
are compared on the specified column(s) or expression(s) using the specified operator(s), not all
of these comparisons will return TRUE.

10
lOMoARcPSD|25110721

Result:
Thus database development life cycle is analyzed with some constrains

11
lOMoARcPSD|25110721

2. Database design using Conceptual modeling (ER-EER) – top-down


approach Mapping conceptual to relational database and validate
using Normalization

Aim:
To design using database using conceptual modeling (ER – EER) – top down approach
mapping conceptual to relational database and validate using normalization.
Procedure:
ER-to-Relational Mapping Algorithm:
The steps of an algorithm for ER-to-relational mapping. We use the COMPANY database
example to illustrate the mapping procedure. The COMPANY ER schema is shown, and
the corresponding COMPANY relational database schema is shown below.

Bdat Nam Salar

Location

Nam Numbe

Superviso Supervise
Name

Nam

ER conceptual schema diagram for the COMPANY database.

9
12
lOMoARcPSD|25110721

The relational model constraints, which include primary keys, unique keys (if any), and
referential integrity constraints on the relations, will also be specified in the mapping
results. Steps 1: Mapping of Regular Entity Types.
Step 2: Mapping of Weak Entity Types.
Step 3: Mapping of Binary 1:1 Relationship Types.
Step 4: Mapping of Binary 1: N Relationship Types.
Step 5: Mapping of Binary M: N Relationship
Types. Step 6: Mapping of Multivalued Attributes.
Step 7: Mapping of N-ary Relationship Types.
Mapping EER Model Constructs to
Relations: Mapping of Specialization or
Generalization
Step 8: Options for Mapping Specialization or Generalization.
Multiple relations—superclass and subclasses.

Multiple relations—subclass relations only Single

relation with one type attribute

Single relation with multiple type attributes

Result:
Thus database using EER is constructed.

13
lOMoARcPSD|25110721

3. Implement the database using SQL Data definition with constraints, Views

Aim:
To implement database using SQL data definition with constrains and views.
DDL Commands
To execute DDL Commands
1. Create Table
2. Alter Table
3. Drop Table
4. Truncate Table
5. Rename Table

14
lOMoARcPSD|25110721

PROGRAM:
-- Create a sample "Employees"

table CREATE TABLE

Employees ( EmployeeID INT

PRIMARY KEY, FirstName

VARCHAR(50), LastName

VARCHAR(50), Department
VARCHAR(50),
Salary

DECIMAL(10, 2)
);

-- Add a new column "Email" to the

"Employees" table ALTER TABLE

Employees

ADD Email VARCHAR(100);

-- Drop the "Employees"

table DROP TABLE

Employees; TRUNCATE

TABLE
Employees;
-- Rename the "Employees" table to

"Staff" ALTER TABLE Employees

RENAME TO Staff;

15
lOMoARcPSD|25110721

Constrains and
views: Constraints:

1. Primary Key Constraint:

CREATE TABLE Students ( StudentID INT PRIMARY KEY, FirstName VARCHAR(50),


LastName VARCHAR(50), CONSTRAINT pk_Students PRIMARY KEY (StudentID) );

2. Foreign Key Constraint:

CREATE TABLE Courses ( CourseID INT PRIMARY KEY, CourseName VARCHAR(50) );


CREATE TABLE Enrollments ( EnrollmentID INT PRIMARY KEY, StudentID INT, CourseID
INT, CONSTRAINT fk_Enrollments_Students FOREIGN KEY (StudentID)
REFERENCES Students(StudentID), CONSTRAINT fk_Enrollments_Courses FOREIGN KEY
(CourseID) REFERENCES Courses(CourseID) );

3. Unique Constraint:

CREATE TABLE Employees ( EmployeeID INT PRIMARY KEY, Email


VARCHAR(100) UNIQUE, Salary DECIMAL(10, 2) );

4. Check Constraint:

CREATE TABLE Orders ( OrderID INT PRIMARY KEY, OrderDate DATE,


TotalAmount DECIMAL(10, 2), CONSTRAINT chk_OrderAmount CHECK
(TotalAmount >= 0) );

16
lOMoARcPSD|25110721

Views:

Views Meaning Syntax Example

CREATE VIEW
CREATE VIEW
To create a view, by Comedies AS
view_name AS
CREATE VIEW statement. SELECT*
Creating Postgre query;
FROM films
SQL Views
WHERE kind =
'Comedy';

To change the defining query


CREATE CREATE comedies
Changing of a view, by using CREATE
AS SELECT * from
PostgreSQL Views VIEWstatement
OR REPLACE films where kind =
with OR REPLACE
view_name AS ‘comedy’;
addition
query
Removing To remove an existing view in
DROP VIEW [ IF DROP VIEW
PostgreSQL Views PostgreSQL, by DROP VIEW
statement EXISTS ]
Comedies;
view_name;

17
lOMoARcPSD|25110721

Result:
Thus SQL Commands executed with Constrains and views.

18
lOMoARcPSD|25110721

4. Query the database using SQL Manipulation

Aim:
Query the database using SQL Manipulation To execute different queries for database using SQL
manipulation
SQL Manipulation:
DML Query:
1. Insert
2. Update
3. Delete
4. Select

19
lOMoARcPSD|25110721

1. Insert:
Insert into a Table:
-- Insert a new student into the Students table
INSERT INTO Students (StudentID, FirstName, LastName) VALUES (1, 'John', 'Doe');

Insert from Another Table:


-- Insert all students from the StudentsBackup table into the Students table
INSERT INTO Students (StudentID, FirstName, LastName) SELECT StudentID,
FirstName, LastName FROM StudentsBackup;

2. Update:
Update a Single Record:
-- Update the salary of an employee with EmployeeID = 101
UPDATE Employees SET Salary = 60000 WHERE EmployeeID = 101;

Update Based on a Condition:


-- Increase the salary of all employees in the IT department by 10% UPDATE Employees SET
Salary = Salary * 1.1 WHERE Department = 'IT';

3. Delete:
Delete a Single Record:
-- Delete a student with StudentID = 1
DELETE FROM Students WHERE StudentID = 1;

Delete Based on a Condition:


-- Delete all students who have not enrolled in any courses
DELETE FROM Students WHERE StudentID NOT IN (SELECT DISTINCT StudentID FROM
Enrollments);

4. Select:
Select All Records:
-- Retrieve all records from the Employees
table SELECT * FROM Employees;

Select Specific Columns:


20
lOMoARcPSD|25110721

-- Retrieve only the FirstName and LastName columns from the Employees
table SELECT FirstName, LastName FROM Employees;

Select with Conditions:


-- Retrieve employees with a salary greater than 50000
SELECT * FROM Employees WHERE Salary > 50000;

Result:
Thus SQLDML Commands executed Successfully.

21
lOMoARcPSD|25110721

5. Querying/Managing the database using SQL Programming


.
- Stored Procedures/Functions
- Constraints and security using Triggers

Aim:
To implement queries and manage the database using SQL Programming with procedures,
function, constraints and security using triggers.
Procedure
Stored Procedures/Functions
A SQL function or a stored procedure is a set of SQL and procedural commands such as
declarations, assignments, loops; flow-of-control etc. stored on the database server and can be
involved using the SQL interfaces.
Single Row Functions
● Single row or Scalar functions return a value for every row that is processed in a query.
● We can having single row functions for the following process
● Numeric
Functions
● String
Functions
● Date and Time
Functions
Group Functions
● These functions group the rows of data based on the values returned by the query.
● This is discussed in SQL GROUP Functions.

22
lOMoARcPSD|25110721

Programs to demonstrate the Concepts:


1) Calculate the net salary and year salary if da is 30% of basic, hra is 10% of basic and pf is
7% if basic salary is less than 8000, pf is 10% if basic sal between 8000 to160000.

Aim
To Calculate the net salary and year salary if da is 30% of basic, hra is 10% of basic and pf is 7% if
basic salary is less than 8000, pf is 10% if basic sal between 8000 to160000.

Program
CREATE OR REPLACE FUNCTION
calculate_salary( basic_salary numeric) RETURNS TABLE (net_salary numeric, yearly_salary
numeric) AS
$$ DECLARE
da_percent numeric := 0.3
hra_percent numeric := 0.1;
pf_percent_low numeric := 0.07;
pf_percent_high numeric := 0.1;
pf_threshold_low numeric := 8000;
pf_threshold_high numeric :=160000;
numeric;
hra numeric;
pf numeric; BEGIN
-- Calculate components
da := basic_salary * da_percent;
hra := basic_salary * hra_percent;

23
lOMoARcPSD|25110721

-- Determine PF based on basic salary


IF basic_salary<pf_threshold_low
THEN pf := basic_salary * pf_percent_low;
ELSIF basic_salary BETWEEN pf_threshold_low AND pf_threshold_high THEN
pf := basic_salary * pf_percent_high;
ELSE
pf := 0; -- No PF for salaries above
pf_threshold_high END IF;
-- Calculate net salary
net_salary := basic_salary + da + hra - pf;

-- Calculate yearly salary


yearly_salary := net_salary * 12;

RETURN NEXT;
END;
$$ LANGUAGE PLPGSQL;
-- Example usage
SELECT * FROM calculate_salary(7000);

24
lOMoARcPSD|25110721

Output

25
lOMoARcPSD|25110721

Result:
Program executed and output obtained successfully.

26
lOMoARcPSD|25110721

2) Create a function to find the factorial of a given number and hence find the nCr.

Aim: To write a Function to calculate the factorial of a given number and hence find the nCr.

Program
CREATE OR REPLACE FUNCTION factorial(n
INTEGER) RETURNS BIGINT AS $$ DECLARE
result BIGINT :=1;
i INTEGER
:=1; BEGIN
WHILE i <= n LOOP
result :=
result *i; i :=
i + 1;
END LOOP;
RETURN
result; END;
$$ LANGUAGE PLPGSQL;
-- Function to calculate nCr (combination)
CREATE OR REPLACE FUNCTION nCr(n INTEGER, r
INTEGER) RETURNS BIGINT AS
$$ DECLARE
numerator BIGINT := factorial(n);
denominator BIGINT := factorial(r) * factorial(n - r);
BEGIN
IF r < 0 OR r > n THEN
RAISE EXCEPTION 'Invalid values for n and
r'; END IF;

RETURN numerator /
denominator; END;
$$ LANGUAGE PLPGSQL;

27
lOMoARcPSD|25110721

-- Example: Calculate
factorial of 5
SELECT factorial(5);
-- Example: Calculate combination

choose
2) SELECT nCr(5, 2);

Output:

28
lOMoARcPSD|25110721

Result:
Program executed and output obtained successfully.

29
lOMoARcPSD|25110721

3) Create a function to find the Prime Numbers

Aim:

To write a function to find prime numbers.

Program
CREATE OR REPLACE FUNCTION find_primes(n INTEGER) RETURNS SETOF INTEGER
AS
$BODY$ DECLARE
divisor INTEGER;
is_prime BOOLEAN;
num INTEGER;
BEGIN
FOR num IN 2..n
LOOP
is_prime := TRUE;
FOR divisor IN 2..sqrt(num)::INTEGER LOOP
IF num % divisor = 0 THEN
is_prime :FALSE;
EXIT;
END IF;
END LOOP;
IF is_prime THEN RETURN
NEXT num;
END IF;
END LOOP;
RETURN;
END;

$BODY$
LANGUAGE
plpgsql;

SELECT * FROM find_primes(100);


30
lOMoARcPSD|25110721

Output

Result:
Program executed and output obtained successfully.

31
lOMoARcPSD|25110721

4) Create a function to generate Fibonacci

series. Aim:

To write a function to generate Fibonacci series

Program
CREATE OR REPLACE FUNCTION generate_fibonacci(n
INT) RETURNS SET OF INT
LANGUAGE plpgsql
AS $$ DECLARE a INT := 0; b INT := 1;
i INT := 1;
BEGIN
WHILE i <= n LOOP
RETURN NEXT a;
a := a + b;
b := a - b;
i := i + 1;
END LOOP;
RETURN; END;
$$;
SELECT * FROM generate_fibonacci(10);

32
lOMoARcPSD|25110721

Output

33
lOMoARcPSD|25110721

Result:
Program executed and output obtained successfully.

34
lOMoARcPSD|25110721

6. Database design using Normalization – bottom-up approach

Aim: To implement database design using Normalization with bottom up approach.

Procedure:
Normalization is a process of converting a relation to be standard form by decomposition a larger
relation into smaller efficient relation that depicts a good database design.
• 1NF: A Relation scheme is said to be in 1NF if the attribute values in the relation are
atomic.i.e., Mutli –valued attributes are not permitted.

• 2NF: A Relation scheme is said to be in 2NF,iff and every Non-key attribute is fully
functionally dependent on primary Key.

• 3NF: A Relation scheme is said to be in 3NF,iff and does not have transitivity dependencies.
A Relation is said to be 3NF if every determinant is a key for each & every functional
dependency.

• BCNF: A Relation scheme is said to be BCNF if the following statements are true for each FD
P->Q in set F of FDs that holds for each FD. P->Q in set F of FD’s that holds over R. Here P is the
subset of attributes of R & Q is a single attribute of R.

35
lOMoARcPSD|25110721

PROGRAM:
The given FD is a trivial P is a super key.

Normalized tables are:-


CREATE TABLE BUS2 (BUSNO VARCHAR (20) PRIMARY KEY, SOURCE VARCHAR (20),
DESTINATION VARCHAR (20));

CREATE TABLE PASSENGER4 (PPN VARCHAR (15) PRIMARY KEY, NAME


VARCHAR (20), AGE INTEGER, SEX CHAR, ADDRESS VARCHAR (20));
CREATE TABLE PASSENGERTICKET (PPN VARCHAR (15) PRIMARY KEY, TICKETNO
INTEGER);

CREATE TABLE RESERVATION2 (PNRNO INTEGER PRIMARY KEY, JOURNEYDATE


DATETIME, NOOFSEATS INT, ADDRESS VARCHAR (20),CONTACTNOINTEGER);

CREATE TABLE CANCELLATION2 (PNRNO INTEGER PRIMARY KEY, JOURNEYDATE


DATETIME, NOOFSEATS INTEGER, ADDRESS VARCHAR (20), CONTACTNO INTEGER,
FOREIGN KEY (PNRNO) REFERENCES RESERVATION2 (PNRNO));

CREATE TABLE TICKET2(TICKETNO INTEGER PRIMARY KEY,JOURNEYDATE


DATETIME, AGE INT(4),SEX CHAR(2),SOURCE VARCHAR(20),DESTINATION
VARCHAR(20),DEPTTIME VARCHAR(2));

36
lOMoARcPSD|25110721

Result:
Thus we implemented database design using Normalization with bottom up approach.

37
lOMoARcPSD|25110721

7. Develop database applications using IDE/RAD tools (Eg., NetBeans, Visual Studio)

Aim: To develop database applications using IDE tools with NetBeans.

Procedure:
Creating the Database Tables in NetBeans IDE:
To create the database tables in Java DB, the database server included with
Application Server, need to create the database connection and execute the SQL
commands in tut- install/examples/common/sql/javadb/tutorial.sql.

Creating the Database Connection


To create the database connections do the following:
1. Click the Services tab.
2. Right-click the Databases node and select New Connection to open the New
Connection dialog.
3. Under Name, select Java DB (Network).
4. Set Database URL to the following: jdbc:derby://localhost:1527/sun-appserv-samples
5. Set User Name to APP.
6. Set Password to APP.
7. Select the Remember Password during this Session box.
8. Click OK.

38
lOMoARcPSD|25110721

Creating the Tables


To create the tutorial tables, do the following:
1. Select File->Open File.
2. Navigate to tut-install/examples/common/sql/javadb/ and open tutorial.sql.
3. In the editor pane, select the connection URL to Java DB:
jdbc:derby://localhost:1527/sun- appserv-samples
4. Click the Run SQL button at the top of the editor pane.

Deleting theTables
To delete the tutorial tables,do the following:
SelectFile->OpenFile.
Navigatetotut-install/examples/common/sql/javadb/andopendelete.sql. In
the editorpane, select the connection URL to JavaDB:
jdbc:derby://localhost:1527/sun- appserv-samples
Click the Run SQL button at the top of the editor pane.

39
lOMoARcPSD|25110721

Result:
Thus a database application is created using IDE – Netbean Tools.

40
lOMoARcPSD|25110721

8. Database design using EER-to-ODB mapping / UML class diagrams

Aim: To develop database design using EER to ODB mapping / UML Class Diagrams.

Procedure:
Mapping an EER Schema to an ODB Schema
It is relatively straightforward to design the type declarations of object classes for an ODBMS from
an EER schema that contains neither categories nor n-ary relationships with n- ary. However,
the operations of classes are not specified in the EER diagram and must be added to the class
declarations after the structural mapping is completed. 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. 38 Multivalued attributes are typically declared
by using the set, bag, or list constructors. 39 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. (This is possible only if
an extent facility and key constraint declarations are avail- able in the ODBMS.)

Step 2. Add relationship properties or reference attributes for each binary relation- ship 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. 40 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 are collection types (set-valued or list-valued 41 ) for relationships in
the 1:N or M:N direction. An alternative way to map binary M:N relationships is discussed in
step 7.

41
lOMoARcPSD|25110721

If relationship attributes exist, a tuple constructor (struct )can be used to create a structure of the form
< reference , relationship attributes >, which may be included instead of the reference attribute.
However, this does not allow the use of the inverse constraint. Additionally, if this choice is
represented in both directions, the attribute values will be represented twice, creating redundancy.
This implicitly uses a tuple constructor at the top level of the type declaration, but in general, the tuple
constructor is not explicitly shown in the ODL class declarations. 39 Further analysis of the application
domain is needed to decide which constructor to use because this information is not available from the
EER schema. 40 The ODL standard provides for the explicit definition of inverse relationships. Some
ODBMS products may not provide this support; in such cases, programmers must maintain every
relationship explicitly by coding the methods that update the objects appropriately. The decision
whether to use set or list is not available from the EER schema and must be determined

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 type
and methods of its super class in the ODL schema. It’s specific (non inherited) 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 theywere 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

Step6.Categories(uniontypes)inanEERschemaaredifficulttomaptoODL.Itispossible to create a
mapping similar to the EER-to-relational mapping(see SectioN 9.2) by declaring a class to
represent the category and defining 1:1 relationships between the category and each of its
super classes. Another option is to use a union type, if it is available

42
lOMoARcPSD|25110721

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.

Enhanced Entity-Relationship (EER) Model:


Consider the following entities: Book, Author, Publisher, and Library. Each book can have
multiple authors, each author can write multiple books, and each book belongs to a specific
library. A library can have multiple books.

OODB Mapping:
In object-oriented database design, entities are often mapped to classes, and relationships
are mapped to associations between classes. Here's a simplified mapping:

43
lOMoARcPSD|25110721

44
lOMoARcPSD|25110721

Result:
Thus database design using EER-to-ODB mapping / UML class diagrams was constructed.

45
lOMoARcPSD|25110721

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


UDTs, Inheritance, Method definition

Aim:
To create an object features of SQL – UDTs and sub-types, Tables using UDTs, Inheritance,
Method Definition.
Procedure:
User-Defined Types (UDTs):
To create complex-structured objects, and to separate the declaration of a type from the creation of a
table, SQL. The user will create the UDTs for a particular application as part of the database
schema. Syntax:

46
lOMoARcPSD|25110721

CREATE TYPE TYPE_NAME AS (<component declarations>);


Example:

(a) CREATE TYPE STREET _ ADDR TYPE AS ( NuMBER VARCHAR (5),


STREET-NAME VAR CHAR (25), APT_NO VAR CHAR (5), SUITE_NO VAR CHAR (5));

(b) CREATE TYPE PERSON _TYPE AS ( NAME VARCHAR


(35), DOB DATE,
PHONE USA_PHONE_TYPE ARRAY[4],
ADDR USA_ADDR_TYPE INSTANTIBLE
NOT FINAL
REF IS SYSTEM GENERATED
INSTANT METHOD AGE() RETURN INTEGER;
CREATE INSTANCE METHOD AGE () RETURNS
INTEGER FOR PERSON _TYPE
BEGIN
RETURN END);

(c) CREATE TYPE GRADE_TYPE AS


( COURSENO CHAR(8),
SEMESTER VARCHAR(8),

YEAR CHAR(4),
GRADE CHAR
);
CREATE TYPE STUDENT_TYPE UNDER PERSON _TYPE AS ( MAJOR-CODE CHAR(4),
STUDENT_ID CHAR(12),
DEGREE VARCHAR(5),
TRANSCRIPT GRADE_TYPE ARRAY[100]
INSTANTIBLE
NOT FINAL
INSTANCE METHOD GPA() RETURNS FLOAT;
CREATE INSTANCE METHOD GPA() RETURNS
FLOAT FOR STUDENT _TYPE

47
lOMoARcPSD|25110721

BEGIN
RETURN
END,);

(d) CREATE TABLE PERSON OF PERSON _TYPE REF IS PERSON _ ID


SYSTEM GENERATED,
CREATE TABLE EMPOLOYEE OF EMPOLOYEE _TYPE UNDER PERSON;
CREATE TABLE MANAGER OF MANAGER_ TYPE UNDER
EMPOLOYEE;
CREATE TABLE STUDENT OF STUDENT_TYPE UNDER PERSON;

48
lOMoARcPSD|25110721

Result: Thus we created Object features of SQL-UDTs and sub-types, Tables


using UDTs, Inheritance, and Method definition.

49
lOMoARcPSD|25110721

10. Querying the Object-relational database using Objet Query language

Aim: To query the Object-relational database using Objet Query language

Procedure:
Object Query Language (OQL)
A version of the Structured Query Language (SQL) that has been designed for use in Network
Manager. The components create and interact with their databases using OQL. Use OQL
to create new databases or
insert data into existing databases (to configure the operation of Network Manager Components)
by amending the component schema files. OQL statements using the OQL Service Provider,
for example, to create or modify databases, insert data into databases and retrieve data.

50
lOMoARcPSD|25110721

Create command to create a database.


Syntax:
Create database database_nam;
Example:
Create table database_name.table_name (
column_name [ constraints ] [ default default ],
[ column_name [ constraints ] [ default default ] , ] [ additional_columns ]
[ unique ( column_name ) , ] [ counter ( column_name ) , ]
[ timestamp ( column_name ) ] );

Data Types:
Data Types Description
TEXT Holds plaintext.
INT Holds integer values.
UINT Holds a 32-bit unsigned integer value
FLOAT Holds decimal values.
LONG64 Holdsa64-bitnumericalvalue.

51
lOMoARcPSD|25110721

External datatypes:

Syntax:
Data type datatype is external datatype;

Example

Data type boolean is external boolean;


Data type entityTypes is external entityTypes;

52
lOMoARcPSD|25110721

Result:
Thus we created object relational database using object query language.

53

You might also like