DDM-1
DDM-1
(Autonomous)
Velu Nagar, Thiruvannamalai-606603
www.arunai.org
BACHELOR OF ENGINEERING
SECOND YEAR
1
ARUNAI ENGINEERING COLLEGE
(Autonomous)
TIRUVANNAMALAI – 606 603
Name :
University Reg.No :
Semester :
Branch :
Year :
2
EX.NO DATE EXPERIMENTS PAGE NO SIGN
3
lOMoARcPSD|25110721
Aim: To understand Database development Life cycle with its problem definition
and requirement analysis along with their scope and constrains for different applications
Database design.
Implementation.
Data loading.
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
• Define objectives.
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?
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.
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.
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
• Adaptive maintenance (enhancing performance, adding entities and attributes, and so on).
• Assignment of access permissions and their maintenance for new and old users.
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.
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
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.
Location
Nam Numbe
Superviso Supervise
Name
Nam
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.
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"
VARCHAR(50), LastName
VARCHAR(50), Department
VARCHAR(50),
Salary
DECIMAL(10, 2)
);
Employees
Employees; TRUNCATE
TABLE
Employees;
-- Rename the "Employees" table to
RENAME TO Staff;
15
lOMoARcPSD|25110721
Constrains and
views: Constraints:
3. Unique Constraint:
4. Check Constraint:
16
lOMoARcPSD|25110721
Views:
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';
17
lOMoARcPSD|25110721
Result:
Thus SQL Commands executed with Constrains and views.
18
lOMoARcPSD|25110721
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');
2. Update:
Update a Single Record:
-- Update the salary of an employee with EmployeeID = 101
UPDATE Employees SET Salary = 60000 WHERE EmployeeID = 101;
3. Delete:
Delete a Single Record:
-- Delete a student with StudentID = 1
DELETE FROM Students WHERE StudentID = 1;
4. Select:
Select All Records:
-- Retrieve all records from the Employees
table SELECT * FROM Employees;
-- Retrieve only the FirstName and LastName columns from the Employees
table SELECT FirstName, LastName FROM Employees;
Result:
Thus SQLDML Commands executed Successfully.
21
lOMoARcPSD|25110721
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
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
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
Aim:
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;
Output
Result:
Program executed and output obtained successfully.
31
lOMoARcPSD|25110721
series. Aim:
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
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.
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)
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.
38
lOMoARcPSD|25110721
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
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.
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
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
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,);
48
lOMoARcPSD|25110721
49
lOMoARcPSD|25110721
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
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
52
lOMoARcPSD|25110721
Result:
Thus we created object relational database using object query language.
53