Database Development Lifecycle Overview
Database Development Lifecycle Overview
:1
DATABASE DEVELOPMENT LIFE CYCLE-CASE STUDY
Date:
AIM
To learn about the phases involved in Database Development Lifecycle
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.
1
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.
4. Testing and Evaluation:
In the design phase, decisions were made to ensure integrity, security, performance,
and recoverability of the database. 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.
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.
RESULT
Thus various phases of Database Development cycle have been studied.
2
[Link].:2
DATABASE DESIGN USING ER MODELING-CASE STUDY
Date:
AIM
ER-EER MODELING
Entity Relationship Modeling (ER Modeling) is a graphical approach to database
design. It uses Entity/Relationship to represent real world objects.
Enhanced Entity Relationship (EER) Model is a high level data model which
provides extensions to original Entity Relationship (ER) model. EER Models
supports more details design. EER Modeling emerged as a solution for modeling
highly complex databases.
EER uses UML notation. UML is the acronym for Unified Modeling Language; it is
a general purpose modeling language used when designing object oriented systems.
Entities are represented as class diagrams. Relationships are represented as
associations between entities. The diagram shown below illustrates an ER diagram
using the UML notation.
It is deduced that the nature of the relationship between members and payments entities
is one-to-many. Now EER model is created using MySQL Workbench In the MySQL
workbench , Click - "+"Button
In this case study MyFlix Video Library is used to understand the concept of ER
diagrams. MyFlix is a business entity that rents out movies to its members. MyFlix has
been storing its records manually. The management now wants to move to a DBMS.
3
The steps to develop EER diagram for this database are
1. Identify the entities and determine the relationships that exist among them.
2. Each entity, attribute and relationship, should have appropriate names that
can be easilyunderstood by the non-technical people as well.
3. Relationships should not be connected directly to each other. Relationships
should connect entities.
4. Each attribute in a given entity should have a unique name.
From the above scenario, it is understood that the nature of the relationship is many-to-
many. Relational databases do not support many-to-many relationships. Hence a
junction entity is introduced. This is the role that the MovieRentals entity plays. It has
a one-to-many relationship with the members table and another one-to-many
relationship with movies table.
In the MySQL workbench, Double click on Add Diagram button to open the
workspace for ER diagrams.
4
Following window appears
The table object allows us to create entities and define the attributes
associated with the particular entity.
The relationship button allows us to define relationships between entities.
Membership number
Full names
Gender
Date of birth
Physical address
Postal address
5
Create the members table
2. Drop it in the workspace area. An entity named table 1 appears [Link] click on it.
The properties window shown below appears
Next,
1. Change table 1 to Members
2. Edit the default idtable1 to membership_number
3. Click on the next line to add the next field
4. Do the same for all the attributes identified in members' entity.
6
Repeat the above steps for all the identified entities.
The diagram workspace should now look like the one shown below.
7
Repeat above steps for other relationships. The ER diagram should now look like this -
Summary
RESULT
Thus the database design using conceptual modeling (ER-EER) and map
it to relational database is performed successfully.
8
[Link].:3 A)
IMPLEMENT THE DATABASE USING DDL AND DML
COMMANDS IN POSTGRE SQL
Date:
AIM
To implement a database using DDL and DML commands.
POSTGRESQL
PostrgeSQL is an advanced relational database system.
It supports both relational (SQL) and non-relational (JSON) queries.
PostgreSQL is free and open-source.
DDL COMMANDS
DDL is an abbreviation for Data Definition Language. It is concerned with
database schemas and descriptions of how data should be stored in the database. DDL
statements are auto-committed, meaning the changes are immediately made to the
database and cannot be rolled back.
The DDL commands in SQL are divided into following major categories:
CREATE
ALTER
TRUNCATE
DROP
CREATE
The CREATE query is used to create a database or objects such as tables, views,
stored procedures, etc.
CREATE DATABASE
The CREATE DATABASE statement is used to create a new SQL database.
Syntax
CREATE DATABASE databasename;
Example
CREATE DATABASE testDB;
CREATE TABLE
The CREATE TABLE statement is used to create a table in database.
Syntax
CREATE TABLE tablename(attributename1 datatype1,attributename2
datatype2);
Example
create table student(rollno int,name char(10),dept char(10),marks int);
ALTER
The ALTER command in SQL DDL is used to modify the structure of an already
existing table.
ADDING A NEW COLUMN
The ALTER command is used to add a new column in an existing database.
Syntax
ALTER TABLE tablename ADD attibutename datatypename;
Example
alter table student add age int;
9
MODIFYING AN EXISTING COLUMN
The ALTER command is used to modify the datatype and its allocated size of an
existing column.
Syntax
ALTER TABLE tablename ALTER COLUMN columnane datatype;
Example
alter table student alter column name type char(20);
RENAME
RENAME is a DDL command which is used to change the name of the database
table.
Syntax
ALTER TABLE OldTableName RENAME TO NewTableName;
Example
alter table student rename to stud;
TRUNCATE
The TRUNCATE command is used to remove all the records from a table.
Syntax
TRUNCATE TABLE tablename;
Example
truncate table student;
DROP
The DROP command is used to delete an existing database or an object within a
database.
DROP DATABASE
The DROP DATABASE statement is used to drop an existing SQL database.
Syntax
DROP DATABASE databasename;
Example
DROP DATABASE testDB;
DROP TABLE
The DROP TABLE statement is used to delete a table from a database.
Syntax
DROP TABLE tablename;
Example
drop table student;
DML COMMANDS
The DML commands in Structured Query Language change the data present in the SQL
database. DML commands are used to access, store, modify, update and delete the
existing records from the database.
The DML commands in SQL are divided into following major categories:
SELECT
INSERT
UPDATE
DELETE
SELECT
SELECT is the most important data manipulation command in Structured
Query Language. The SELECT command shows the records of the specified table.
10
It also shows the particular record of a particular column by using the WHERE
clause.
Syntax
SELECT * FROM tablename;
Example
SELECT * FROM Student;
SELECT EmpId, EmpSalary FROM Employee;
INSERT
The INSERT command is used to insert data in database tables.
Syntax
INSERT into TABLENAME values (attributename1,attributename2….);
Example
INSERT into STUDENT values (102,'lenin','ai',95); (or)
INSERT into STUDENT (rollno,name,dept,marks)values(107,'vinai','ece',99);
UPDATE
The UPDATE command is used to update or modify the existing data in database
tables.
Syntax
UPDATE tablename SET columnname1= value1 WHERE condition;
Example
UPDATE Product SET ProductPrice = 80 WHERE ProductId = 'P102' ;
DELETE
DELETE is a DML command which allows SQL users to remove single or
multiple existing records from the database tables.
Syntax
DELETE FROM tableName WHERE condition;
Example
DELETE FROM Product WHERE ProductId = 'P202' ;
11
alter table student alter column name type char(25);
12
select * from student;
ERROR: relation "student" does not exist LINE 1: select * from student; ^ SQL state:
42P01 Character: 15
select * from stud;
RESULT
Thus the DDL and DML commands were implemented and the data was
retrieved from the database successfully.
13
[Link].:3 B)
IMPLEMENT THE DATABASE WITH CONSTRAINTS
Date:
AIM
To implement the database with constraints using PosgreSQL.
CONSTRAINTS
Constraints in DBMS (Database Management Systems) are rules or conditions that are
applied to the data within a database to ensure data integrity, consistency, and adherence to
business rules.
There are several types of constraints available in DBMS and they are:
Domain constraints
Entity Integrity constraints
Referential Integrity constraints
Key constraints
DOMAIN CONSTRAINTS
The domain refers to the allowed values (range of values) for a function. The domain
value of an attribute must be an atomic value .
Types of Domain Constraints
Not Null
The column value cannot be empty (i.e. cannot contain a null value)
Check
The CHECK constraint checks the condition that follows it, e.g. CHECK
(Age>21) ensures that each Age column value is greater than 21.
KEY CONSTRAINTS
Keys are the set of entities that are used to identify an entity within its entity set
uniquely. A primary key can only contain unique and not null values in the relational
database table.
14
QUERIES & OUTPUT
// UNIQUE CONSTRINT
alter table employee add unique(ename);
insert into employee values(107,24,'sara',85000,'Bangalore');
ERROR: duplicate key value violates unique constraint "employee_ename_key" DETAIL: Key
(ename)=(sara ) already exists. SQL state: 23505
//CHECK CONSTRAINT
alter table employee add check (age>25);
//REFERNTIAL INTEGRITY
insert into person values(22445566,102);
insert into person values(12332145,103);
insert into person values(42536415,104);
select * from person;
15
delete from person where aadhar=12332145;
create table persn(aadhar int primary key,empid int, foreign key(empid) references
employee(empid)on delete cascade on update cascade);
insert into persn values(22445566,102);
insert into persn values(12332145,103);
insert into persn values(42536415,104);
RESULT
Thus the types of constraints were studied and the commands were implemented in
database successfully.
16
[Link].:3 C)
IMPLEMENT THE DATABASE WITH VIEWS
Date:
AIM
To implement the concept of views in PostgreSQL.
VIEWS
Views allow the user to create a virtual table based on an SQL query referring to other tables
in the database. A view stores an SQL query that is executed whenever user refer to the view.
The view has primarily two purposes:
Simplify the complex SQL queries.
Provide restriction to users from accessing sensitive data.
CREATING VIEWS
Views can be created using CREATE VIEW statement. A View can be created from a single
table or multiple tables.
Syntax:
CREATE VIEW view_name AS
SELECT column1, column2.....
FROM table_name
WHERE condition;
DROPPING VIEWS
If the view is no longer needed it can be dropped using the DROP statement.
Syntax:
DROP VIEW view_name;
UPDATING VIEWS
The CREATE OR REPLACE VIEW statement is used to add or remove fields from a
view. There could be a situation to create a view or replace it if it already exists.
17
Syntax:
CREATE OR REPLACE VIEW view_name AS
SELECT column1,column2,..
FROM table_name
WHERE condition;
OUTPUT
create table sdetails(regno int,name char(15),marks int,dept char(10));
18
create table pers(regno int,age int,address char(20));
RESULT
Thus the usage of views was implemented successfully.
19
[Link].:4 A)
IMPLEMENTATION OF SUB QUERIES
Date:
AIM
To implement various Sub queries in SQL.
SUB QUERY
In PostgreSQL, a subquery (also known as a nested query or inner query) is a query nested
inside another query. Subqueries are enclosed in parentheses and can be used in various parts
of a SQL statement, such as the SELECT, FROM, WHERE, and HAVING clauses.
The common types of subqueries in PostgreSQL are :
AS
An alias is created with the AS keyword.
SQL aliases are used to give a table, or a column in a table, a temporary name.
Syntax
SELECT column1, column2 FROM tablename AS aliasname;
Example
SELECT MAX(salary) AS maxsalary FROM employees
IN
The IN operator specify a list of possible values in the WHERE clause.
Syntax
WHERE IN (subquery)
Example
SELECT * FROM customers WHERE country IN ('Germany', 'France', 'UK');
ANY
The subquery must return exactly one column.
The ANY operator must be preceded by one of the following comparison
operator =, <=, >, <, > and <>.
The ANY operator is used to compare a value to any value in a set of values.
Syntax
expression operator ANY (subquery)
Example
SELECT * FROM products WHERE price > ANY (SELECT price FROM
discount_products);
ALL
The ALL operator is used to compare a value to all values in a set of values.
Syntax
expression operator ALL (subquery)
Example
SELECT * FROM products WHERE price > ALL (SELECT price FROM
expensive_products);
20
EXISTS
The EXISTS operator is used to check the existence of rows in a subquery result.
Syntax
pid price
1 200
2 100
3 300
4 50
pid price
1 200
3 300
SELECT * FROM product WHERE price < Any (SELECT price FROM discountprod);
pid price
2 100
4 50
21
SELECT * FROM product WHERE EXISTS (SELECT * FROM discountprod WHERE
[Link] = [Link]);
pid price
1 200
2 100
4 50
SELECT * FROM product WHERE pid IN ( SELECT pid FROM discountprod WHERE
price = 80);
pid price
2 100
pid maxprice
1 300
2 300
3 300
4 300
max
300
RESULT
Thus the SQL sub query commands were implemented and the output was verified
successfully.
22
[Link].:4 B)
SELECT COMMANDS AND AGGREGATE FUNCTIONS IN SQL
Date:
AIM
To study and execute various select commands using SQL
TYPES OF SELECT COMMAND
GROUP BY
The SQL GROUP BY clause is used to arrange identical data into groups with the
help of some aggregate functions (COUNT, MAX, MIN, SUM, AVG) .
ORDERBY
The ORDER BY clause in SQL is used to sort the result set of a query based on one or more
columns. It can be used with both numerical and textual data, and sorted in ascending (asc)
or descending (desc) order.
HAVING
The HAVING clause in SQL is used in conjunction with the GROUP BY clause to filter the
results of a query based on aggregate conditions.
BETWEEN
The BETWEEN operator in SQL is used to filter the result set based on a specified range of
values. It is often used in the WHERE clause of a query.
SET OPERATORS
UNION
The UNION operator in SQL is used to combine the result sets of two or more
SELECT statements into a single result set.
It removes duplicate rows from the combined result set.
UNION ALL
The UNION ALL operator in SQL is similar to the UNION operator but includes
all rows in the result set, including duplicate rows.
INTERSEC
The INTERSECT operator in SQL is used to combine the result sets of two
SELECT statements and retrieve only the rows that are common to both result sets.
MINUS
The MINUS operator in SQL is used to combine the result sets of two SELECT
statements.
It performs set difference operation.
23
AGGREGATE FUNCTIONS
AVG
The AVG aggregate function in SQL is used to calculate the average value of a
numeric column in a result set.
COUNT
The COUNT aggregate function in SQL is used to count the number of rows in a
result set.
MAX
The MAX function is a useful aggregate function for obtaining the maximum value in
a set of data.
MIN
The MIN function is a useful aggregate function for obtaining the minimum value in
a set of data.
SUM
The SUM aggregate function in SQL is used to calculate the total sum of values in a
specified column.
OUTPUT
create table stud(rollno int,name char(20),dbms int,maths int,algorithm int,dept
char(10),address char(15));
insert into stud values(123,'priya',78,80,80,'cse','chennai');
insert into stud values(124,'uma',63,68,70,'cse','madurai');
insert into stud values(125,'ganesh',90,95,75,'ai','ooty');
insert into stud values(126,'varun',94,87,77,'ece','chennai');
dept
cse
ai
ece
24
select dept from stud;
dept
cse
cse
ai
ece
count dept
2 cse
1 ai
1 ece
select name from stud order by (name)desc;
name
varun
uma
priya
ganesh
name
priya
varun
count dept
2 cse
25
select * from stud union select * from person;
select name from stud where name in (select name from person where dept='ai');
name
ganesh
RESULT
Thus various select command and aggregate functions are executed in SQL
successfully.
26
[Link].:5 A)
PROGRAMS USING PROCEDURES
Date:
AIM
To Querying/Managing the database using SQL Programming -Procedures and
Functions
PL/pgSQL
PL/pgSQL is a procedural programming language for the PostgreSQL dbms system.
PL/pgSQL allows you to extend the functionality of the PostgreSQL dbms server by
creating server objects with complex logic.
PL/pgSQL was designed to :
Create user-defined functions, stored procedures, and triggers.
Extend standard SQL by adding control structures such as if, case,
and loop statements.
Inherit all user-defined functions, operators, and types.
PROCEDURES
PostgreSQL 11 introduced stored procedures that support transactions.
The following illustrates the basic syntax of the create procedure statement:
Output:
NOTICE: hai
DO
Query returned successfully in 37 msec.
27
PL/PGSQL TO SWAP TWO NUMBERS
DO $$
DECLARE
num1 int;
num2 int;
temp int;
BEGIN
num1 := 1000;
num2 := 2000;
RAISE NOTICE 'Before swapping';
RAISE NOTICE 'num1=%, num2=%', num1, num2;
temp := num1;
num1 := num2;
num2 := temp;
RAISE NOTICE 'After swapping';
RAISE NOTICE 'num1=%, num2=%', num1, num2;
END $$;
Output:
NOTICE: Before swapping
NOTICE: num1=1000, num2=2000
NOTICE: After swapping
NOTICE: num1=2000, num2=1000
DO
Call proc();
OUTPUT:
NOTICE: Hello from my stored procedure! CALL Query returned
successfully in 41 msec.
28
PROGRAM USING PROCEDURES TO PERFORM TRANSACTION
create table accounts ( id int, name varchar(100) not null, balance int not null, primary
key(id));
insert into accounts values(1,'Raju', 5000);
insert into accounts values(2,'Nikhil', 10000);
id name balance
1 Raju 5000
2 Nikhil 10000
id name balance
1 Raju 4000
2 Nikhil 11000
RESULT:
Thus the concept of procedures and functions are executed successfully.
29
[Link].:5 B)
PROGRAMS USING FUNCTIONS
Date:
AIM
To execute program using functions in postgreSQL.
FUNCTIONS
PostgreSQL uses the CREATE FUNCTION statement to develop user-defined functions.
Syntax:
CREATE [OR REPLACE] FUNCTION function_name (arguments)
RETURNS return_datatype
LANGUAGE plpgsql
AS $variable_name$
DECLARE
declaration;
[...] -- variable declaration
BEGIN
< function_body >
[...] -- logic
RETURN { variable_name | value }
END;
$$
Example:
select inc(20);
OUTPUT:
inc
21
30
insert into car values(2,70000);
select * from car;
OUTPUT:
OUTPUT:
31
PL/PGSQL FUNCTION TO CALCULATE THE FACTORIAL OF A NUMBER:
OUTPUT:
OUTPUT:
32
PL/PGSQL FUNCTION TO ACCEPT A NUMBER A PRINT THE SUM OF ITS DIGIT
RETURN sum;
END;
$$ LANGUAGE plpgsql;
// call the function
SELECT sum_of_digits(12345);
OUTPUT:
RETURN rev;
END;
$$ LANGUAGE plpgsql;
SELECT reverse_number(123);
OUTPUT:
RESULT
Thus the usage of functions was studied and the programs were executed successfully.
33
[Link].:6
CONSTRAINTS AND SECURITY USING TRIGGERS
Date:
AIM
To querying the database using SQL Programming – Constraints and security using
Trigger.
TRIGGERS
A trigger is a stored procedure in a database that automatically invokes whenever a special
event in the database occurs. For example, a trigger can be invoked when a row is inserted
into a specified table or when specific table columns are updated.
Syntax:
create trigger [trigger_name]
[before | after]
{insert | update | delete}
on [table_name]
[for each row]
[trigger_body]
Explanation of Syntax
1. Create trigger [trigger_name]: Creates or replaces an existing trigger with the
trigger_name.
2. [before | after]: This specifies when the trigger will be executed.
3. {insert | update | delete}: This specifies the DML operation.
4. On [table_name]: This specifies the name of the table associated with the trigger.
5. [for each row]: This specifies a row-level trigger, i.e., the trigger will be executed for
each affected row.
6. [trigger_body]: This provides the operation to be performed as the trigger is fired
PROGRAM
34
SELECT * FROM employee_audit;
RESULT
Thus the trigger was invoked and executed successfully.
35
[Link].:7
DATABASE DESIGN USING NORMALIZATION
Date:
AIM:
To create a database with Normal forms.
NORMALZATION
Normalization is a database design technique which organizes tables in a
manner that reduces redundancy and dependency of data.
It divides larger tables to smaller tables and links them using relationships.
The inventor of the relational model Edgar Codd proposed the theory of normalization
with the introduction of First Normal Form, and he continued to extend theory with
Second and Third Normal Form. Later he joined with Raymond F. Boyce to develop
the theory of Boyce-Codd Normal Form.
Theory of Data Normalization in SQL is still being developed further. For example,
there are discussions even on 6thNormal Form. However, in most practical
applications, normalization achieves its best in 3rd Normal Form. The evolution of
Normalization theories is illustrated below-
Assume a video library maintains a database of movies rented out. Without any
normalization, all information is stored in one table as shown below.
Table 1
36
1NF Example
What is a KEY?
A KEY is a value used to identify a record in a table uniquely. A KEY could be a
single column orcombination of multiple columns
Note: Columns in a table that are NOT used to identify a record uniquely are called
37
Let's move into second normal form 2NF
It is clear that we can't move forward to make our simple database in 2nd
Normalization form unlesswe partition the table above.
Table 1
Table 2
We have divided our 1NF table into two tables viz. Table 1 and Table2. Table 1
contains member information. Table 2 contains information on movies rented.
38
Why do we need a foreign key?
Suppose an idiot inserts a record in Table B such as
We will only be able to insert values into your foreign key that exist in the unique
key in the
parenttable. This helps in referential integrity.
Now, if somebody tries to insert a value in the membership id field that does not
exist in the parenttable, an error will be shown!
39
Let's move into 3NF
3NF (Third Normal Form) Rules
Rule 1- Be in 2NF
Rule 2- Has no transitive functional dependencies
To move our 2NF table into 3NF, we again need to again divide our table.
3NF Example
Table 1
Table 2
Table 3
We have again divided our tables and created a new table which stores Salutations.
There are no transitive functional dependencies, and hence our table is in 3NF
Now our little example is at a level that cannot further be decomposed to attain higher
forms of normalization. In fact, it is already in higher normalization forms. Separate
efforts for moving into next levels of normalizing data are normally needed in
40
complex databases. However, we will be discussing next levels of normalizations in
brief in the following.
If no database table instance contains two or more, independent and multivalued data
describing therelevant entity, then it is in 4th Normal Form.
RESULT
Thus the normalization concept was studied and the database was created using
normalization.
41
[Link].:8 DEVELOPING A DATABASE APPLICATIONS USING
Date: VISUALSTUDIO
AIM
To develop a database application for students using VisualStudio
PROCEDURE
1. In the start menu go to all apps and select Microsoft office->Ms Access
2. Select new document .create a table with name mydata . Choose design view and
create three fields name, address and age.
3. Enter the data for the created fields by double clicking the table mydata. Save the
document as mydata and close the document.
4. In the start menu go to Microsoft Visual studio [Link] create a new project->WPF
framework(.Netframework)->next->create a new project.
5. Select and pin toolbox and datasource at the leftside of the [Link] the toolbox
select 3 labels and 3 textboxes, place it in the form and change the label name from
its properties.
42
9. Choose the database objects and click finish.
10. Place the datagridview in the form and from choose data source->mydata
11. Select each textbox and from its properties choose data bindings->tag->select
appropriate field.
12. Write the code for each buttons.
13. Run the project by pressing CTRL+F5.
43
OUTPUT
RESULT
Thus the application to develop student Management System using VisualStudio is
successfully implemented.
44
[Link].:9 DATABASE DESIGN USING EER-TO-ODB MAPPING / UML CLASS
Date: DIAGRAMS
AIM
To design a database using EER-to-ODB mapping and create UML class diagrams for
the object-oriented database model.
ALGORITHM
1. Develop EER or UML diagrams representing system entities, attributes, and
relationships.
2. Extract entities and attributes for tables, considering each entity as a table and
attributes as columns.
3. Translate relationships into foreign keys in corresponding tables, considering
cardinalities and participation constraints.
4. Decide on a mapping strategy for inheritance (table-per-class or table-per-hierarchy)
for generalization/specialization.
5. Map aggregations to foreign keys or separate tables.
6. Assign appropriate data types to attributes based on requirements and the DBMS.
7. Apply normalization to eliminate redundancy and anomalies.
8. Establish primary keys, foreign keys, unique constraints, and other integrity
constraints.
9. Create a SQL script to implement the database schema, relationships, and constraints.
10. Execute the SQL script to create the database, test and optimize the schema for
performance and functionality, and document the structure
45
4. Student Attributes:
Class
5. AccountAttributes:
no_borrowed_books no_reserved_books no_returned_books
no_lost_books fine_amountOperations: Calculate_fine()
6. Book Attributes:
Title
Author
ISBN
publication Operations: Show_duedt()
Reservation_status()
Feedback()
Book_request()
Renew_info()
7. librarianAttributes:
Name
Id
Password
SearchString Operations: Verify_librarian()
Search()
8. Library database
Attributes:
List_of_books Operations:
Add()
Delete()
Update()
Display()
Search()
46
UML DIAGRAM
RESULT
Thus the implementation on database design using eer-to-odb mapping / uml class
diagrams is performed successfully.
47
[Link].:10 A)
PROGRAM USING UDTs AND INHERITANCE
Date:
AIM:
To implement the object features of SQL using UDTs and Inheritance.
ALGORITHM:
1. Create a type called as addresstype to hold street and city.
2. Create a table employ consisting of emp_id,name,salary and address.
3. Create a table manager which inherits employ table and insert values into this table.
4. Create a table developer which inherits employ and insert values into this table.
5. Display the above three tables, now the base table is inherited by the child tables and the
result will be shown.
PROGRAM
48
select * from developer;
RESULT
Thus the object features of SQL like UDT and inheritance was implemented
successfully.
49
[Link].:10 B)
PROGRAM USING UDTs AND SUBTYPES
Date:
AIM
To implement the object features of SQL like UDTs and Subtypes.
SUBTYPE IN POSTGRESQL
In PostgreSQL, subtypes are implemented using the CREATE TYPE statement. Subtypes
allow to create a new data type that is based on an existing data type and inherits its
properties.
ALGORITHM
RESULT
Thus the subtype concept under object features of SQL was implemented
successfully.
50
[Link].:10 C)
OBJECT FEATURES OF SQL-METHOD DEFINITION
Date:
AIM
To calculate the length of books title using method definition.
ALGORITHM
1. Create a table named books with columns book_id, title, author, and publication_year.
2. Define a method named calculate_title_length that takes a book title as an argument
and returns the length of the title using the LENGTH function.
3. Insert some sample data into the books table.
4. Use the calculate_title_length method in a query to find the title length for each book.
PROGRAM
-- Create a table
CREATE TABLE books (book_id SERIAL PRIMARY KEY, title VARCHAR, author
VARCHAR, publication_year INT);
-- Create a method to calculate the number of characters in the title of a book
CREATE OR REPLACE FUNCTION calculate_title_length(book_title VARCHAR)
RETURNS INT AS $$
BEGIN
RETURN LENGTH(book_title);
END;
$$ LANGUAGE plpgsql;
-- Use the method to calculate the title length for a specific book
RESULT
Thus the length of given books title was calculated using method definition and
displayed successfully.
51
[Link].:11 QUERYING THE OBJECT-RELATIONAL DATABASE USING
Date: OBJET QUERY LANGUAGE
AIM
To query the object relational database using object query language.
OBJECT-RELATIONAL DATABASE
Object-relational databases aim to bridge the gap between relational databases and
object-oriented databases, incorporating concepts from both paradigms.
They allow the users to define custom data types, store complex data structures, and
use functions to manipulate the data, providing more flexibility than traditional
relational databases.
Oracle Database: Oracle supports object-relational features and has a long history of
providing support for complex data types.
IBM Db2: Db2 is known for its support for complex data types and object-relational
features.
ALGORITHM & QUERIES
1. Table Creation:
The Authors table is created with columns AuthorID (primary key),
AuthorName (name of the author), and Books (an array of book titles).
CREATE TABLE Authors ( AuthorID SERIAL PRIMARY KEY, AuthorName
VARCHAR(100), Books VARCHAR(200)[ ]);
2. Data Insertion:
Sample data is inserted into the Authors table. Authors are associated with an
array of books they have written.
INSERT INTO Authors (AuthorName, Books) VALUES
('Jenith joel', ARRAY['Book1', 'Book2']),
('Reena dev', ARRAY['Book3', 'Book4', 'Book5']),
('Alice mary', ARRAY['Book6']);
52
SELECT [Link], [Link], CARDINALITY(Books) AS NumberofBooks
FROM Authors a;
RESULT
Thus the usage of arrays, creation of user-defined types and the inclusion of functions
which are features of object-relational databases are implemented and executed.
53