Database Design and Management System Manual-1
Database Design and Management System Manual-1
AIM
To study about the various concepts such as Problem definition, Requirement analysis, Scope and Constraints
involved in Database Development Life Cycle.
DESCRIPTION
DATABASE ENVIRONMENT
A database environment is a collective system of components that comprise and regulates the group of data, management,
and use of data, which consist of software, hardware, people, techniques of handling database, and the data also. One of the
primary aims of a database is to supply users with an abstract view of data, hiding a certain element of how data is stored and
manipulated.
● Hardware in a database environment means the computers and computer peripherals that are
being used to manage a database,
● Software includes operating system (OS) to the application programs that include database
management software like M.S. Access or SQL Server.
● People in a database environment include administrators and data users in system
● Database life cycle (DBLC) defines the stages involved for implementing a database,
starting with requirements analysis and ending with monitoring and modification.
● DBLC never ends because database monitoring, modification, and maintenance are part of
the life cycle, and these activities continue long after a database has been implemented.
● DBLC encompasses the lifetime of database.
1. Requirements analysis
2. Logical design
3. Physical design
4. Implementation
Requirements analysis
Planning – This stages of database design concepts are concerned with planning of entire Database
Development Life Cycle.
System definition – This stage defines the scope and boundaries of the proposed database system.
Requirement Analysis - Example
Below are the two methodologies used for requirement analysis phase,
1. Structured Data Analysis (SDA)is a method for analysing the flow of information within
an organization using data flow diagrams.
Specification documents created in requirement analysis phase are used as input to conceptual
schema design phase. Structured data analysis (systems analysis) consists of
● Validation –
● Sorting –
● Summarization(statistical) or (automatic) –
● Aggregation –Analysis –
● Reporting –
● Classification
SSADM techniques Three most important techniques that are used in SSADM are as follows:
▪ Logical design
▪ Physical Design
▪ Implementation
Physical Design stage has only one purpose: to maximize database efficiency.
This means finding ways to speed up the performance of the RDBMS. Manipulating certain
database design elements can speed up the two slowest operations in an RDBMS: retrieving
data from and writing data to a database.
The final two stages in the DBLC,
1. Implementation
2. Monitoring, Modification, and Maintenance occur after database design is complete.
IV. Implementation
During the implementation stage of the DBLC, the tables developed in the ER diagram (and
subsequently normalized) are converted into SQL statements. These SQL statements are then
executed in the RDBMS to create a database. By this stage in the database life cycle, the System
Administrator has installed and configured an RDBMS.
V. Monitoring, modification, and maintenance
A successfully implemented database must be carefully monitored to ensure that it is
functioning properly and that it is secure from unauthorized access.
RDBMS usually provides utilities to help monitor database functionality and security.
Database modification involves adding and deleting records, importing data from other systems
(as needed), and creating additional tables, user views, and other objects and tools.
DATABASE DESIGN:
Database Design
● Logical model – This stage is concerned with developing a database model based
on requirements. The entire design is on paper without any physical
implementations or specific DBMS considerations.
● Physical model – This stage implements the logical model of the database taking
into account the DBMS and physical implementation factors.
Implementation
RESULT:
AIM:
DESCRIPTION:
ER model
● ER model stands for an Entity-Relationship model. It is a high-level data model. This model
is used to define the data elements and relationship for a specified system.
● It develops a conceptual design for the database. It also develops a very simple and easy
to design view of data.
● In ER modeling, database structure is portrayed as a diagram called entity-relationship
diagram.
In this database, the student will be an entity with attributes like address, name, id, age, etc. The
address can be another entity with attributes like city, street name, pin code, etc and there will be a
relationship between them.
Component of ER Diagram
The database can be represented using the notations, and these notations can be reduced to a collection
of tables.
In the database, every entity set or relationship set can be represented in tabular form.
TABLE CREATION
CREATE TABLE
SALESMAN (SALESMAN_ID
NUMBER (4),
NAME VARCHAR2 (20),
CITY VARCHAR2 (20),
COMMISSION VARCHAR2 (20),
PRIMARYKEY
(SALESMAN_ID));
CREATE TABLE
CUSTOMER1
(CUSTOMER_ID NUMBER
(4),
CUST_NAME VARCHAR2 (20),
CITY VARCHAR2 (20),
GRADE NUMBER (3),
PRIMARY KEY (CUSTOMER_ID),
SALESMAN_ID REFERENCES SALESMAN (SALESMAN_ID) ON DELETE SET NULL);
CREATE TABLE
ORDERS (ORD_NO
NUMBER (5),
PURCHASE_AMT NUMBER (10,
2), ORD_DATE DATE,
PRIMARY KEY (ORD_NO),
RESULT:
Thus the mapping from a ER-EER Model to Relational Database in a Database Design Using
Conceptual Modeling was done successfully.
EX.NO : 3 IMPLEMENT THE DATABASE USING SQL DATA DEFINITION
DATE: WITH CONSTRAINTS, VIEWS
AIM
To execute and verify the Data Definition SQL with constraints and views .
COMMANDS:
DDL (DATA DEFINITION LANGUAGE)
The major tasks included are database backup and recovery, access management, hardware maintenance etc
NOT NULL
UNIQUE
PRIMARY KEY
FOREIGN KEY
CHECK
DEFAULT
CREATE INDEX
Now let us try to understand the different constraints available in SQL in more detail with the help of examples. We will use
MySQL database for writing all the queries.
1. NOT NULL
Whenever a table's column is declared as NOT NULL, then the value for that column cannot be empty for any of the table's
records.
There must exist a value in the column to which the NOT NULL constraint is applied.
NOTE: NULL does not mean zero. NULL means empty column, not even zero.
CREATE TABLE TableName (ColumnName1 datatype NOT NULL, ColumnName2 datatype,…., ColumnNameN
datatype);
Example:
Create a student table and apply a NOT NULL constraint on one of the table's column while creating a table.
CREATE TABLE student(StudentID INT NOT NULL, Student_FirstName VARCHAR(20), Student_LastName
VARCHAR(20), Student_PhoneNumber VARCHAR(20), Student_Email_ID VARCHAR(40));
Example:
Consider we have an existing table student, without any constraints applied to it. Later, we decided to apply a NOT NULL
constraint to one of the table's column. Then we will execute the following query:
mysql> ALTER TABLE student CHANGE StudentID StudentID INT NOT NULL;
To verify that the not null constraint is applied to the student table's column, we will execute the following query:
2. UNIQUE
o Duplicate values are not allowed in the columns to which the UNIQUE constraint is applied.
o The column with the unique constraint will always contain a unique value.
o This constraint can be applied to one or more than one column of a table, which means more than one unique constraint
can exist on a single table.
o Using the UNIQUE constraint, you can also modify the already created tables.
CREATE TABLE TableName (ColumnName1 datatype UNIQUE, ColumnName2 datatype,…., ColumnNameN datatype);
Example:
Create a student table and apply a UNIQUE constraint on one of the table's column while creating a table.
To verify that the unique constraint is applied to the table's column and the student table is created successfully, we will execute
the following query:
CREATE TABLE TableName (ColumnName1 datatype, ColumnName2 datatype,…., ColumnNameN datatype, UNIQUE (
ColumnName1, ColumnName 2));
Example:
Create a student table and apply a UNIQUE constraint on more than one table's column while creating a table.
Example:
Consider we have an existing table student, without any constraints applied to it. Later, we decided to apply a UNIQUE
constraint to one of the table's column. Then we will execute the following query:
To verify that the unique constraint is applied to the table's column and the student table is created successfully, we will execute
the following query:
3. PRIMARY KEY
Example:
Create a student table and apply the PRIMARY KEY constraint while creating a table.
mysql> CREATE TABLE student(StudentID INT PRIMARY KEY, Student_FirstName VARCHAR(20), Student_LastN
ame VARCHAR(20), Student_PhoneNumber VARCHAR(20), Student_Email_ID VARCHAR(40));
To verify that the primary key constraint is applied to the table's column and the student table is created successfully, we will
execute the following query:
Example:
Consider we have an existing table student, without any constraints applied to it. Later, we decided to apply the PRIMARY
KEY constraint to the table's column. Then we will execute the following query:
To verify that the primary key constraint is applied to the student table's column, we will execute the following query:
Example:
Create an employee table and apply the FOREIGN KEY constraint while creating a table.
To create a foreign key on any table, first, we need to create a primary key on a table.
mysql> CREATE TABLE employee (Emp_ID INT NOT NULL PRIMARY KEY, Emp_Name VARCHAR (40), Emp_S
alary VARCHAR (40));
To verify that the primary key constraint is applied to the employee table's column, we will execute the following query:
Now, we will write a query to apply a foreign key on the department table referring to the primary key of the employee table,
i.e., Emp_ID.
mysql> CREATE TABLE department(Dept_ID INT NOT NULL PRIMARY KEY, Dept_Name VARCHAR(40), Emp_I
D INT NOT NULL, FOREIGN KEY(Emp_ID) REFERENCES employee(Emp_ID));
To verify that the foreign key constraint is applied to the department table's column, we will execute the following query:
Example:
Create an employee table and apply the FOREIGN KEY constraint with a constraint name while creating a table.
To create a foreign key on any table, first, we need to create a primary key on a table.
mysql> CREATE TABLE employee (Emp_ID INT NOT NULL PRIMARY KEY, Emp_Name VARCHAR (40), Emp_S
alary VARCHAR (40));
To verify that the primary key constraint is applied to the student table's column, we will execute the following query:
Now, we will write a query to apply a foreign key with a constraint name on the department table referring to the primary key
of the employee table, i.e., Emp_ID.
mysql> CREATE TABLE department(Dept_ID INT NOT NULL PRIMARY KEY, Dept_Name VARCHAR(40), Emp_I
D INT NOT NULL, CONSTRAINT emp_id_fk FOREIGN KEY(Emp_ID) REFERENCES employee(Emp_ID));
To verify that the foreign key constraint is applied to the department table's column, we will execute the following query:
ALTER TABLE Parent_TableName ADD FOREIGN KEY (ColumnName) REFERENCES Child_TableName (Column
Name);
Example:
Consider we have an existing table employee and department. Later, we decided to apply a FOREIGN KEY constraint to the
department table's column. Then we will execute the following query:
mysql> ALTER TABLE department ADD FOREIGN KEY (Emp_ID) REFERENCES employee (Emp_ID);
To verify that the foreign key constraint is applied to the department table's column, we will execute the following query:
o Whenever a check constraint is applied to the table's column, and the user wants to insert the value in it, then the value
will first be checked for certain conditions before inserting the value into that column.
o For example: if we have an age column in a table, then the user will insert any value of his choice. The user will also
enter even a negative value or any other invalid value. But, if the user has applied check constraint on the age column
with the condition age greater than 18. Then in such cases, even if a user tries to insert an invalid value such as zero or
any other value less than 18, then the age column will not accept that value and will not allow the user to insert it due
to the application of check constraint on the age column.
CREATE TABLE TableName (ColumnName1 datatype CHECK (ColumnName1 Condition), ColumnName2 datatype,….,
ColumnNameN datatype);
Example:
Create a student table and apply CHECK constraint to check for the age less than or equal to 15 while creating a table.
To verify that the check constraint is applied to the student table's column, we will execute the following query:
CREATE TABLE TableName (ColumnName1 datatype, ColumnName2 datatype CHECK (ColumnName1 Condition AN
D ColumnName2 Condition),…., ColumnNameN datatype);
Example:
Create a student table and apply CHECK constraint to check for the age less than or equal to 15 and a percentage greater than
85 while creating a table.
To verify that the check constraint is applied to the age and percentage column, we will execute the following query:
Example:
Consider we have an existing table student. Later, we decided to apply the CHECK constraint on the student table's column.
Then we will execute the following query:
To verify that the check constraint is applied to the student table's column, we will execute the following query:
Whenever a default constraint is applied to the table's column, and the user has not specified the value to be inserted in it, then
the default value which was specified while applying the default constraint will be inserted into that particular column.
CREATE TABLE TableName (ColumnName1 datatype DEFAULT Value, ColumnName2 datatype,…., ColumnNameN d
atatype);
Example:
Create a student table and apply the default constraint while creating a table.
To verify that the default constraint is applied to the student table's column, we will execute the following query:
Example:
Consider we have an existing table student. Later, we decided to apply the DEFAULT constraint on the student table's column.
Then we will execute the following query:
To verify that the default constraint is applied to the student table's column, we will execute the following query:
7. CREATE INDEX
CREATE INDEX constraint is used to create an index on the table. Indexes are not visible to the user, but they help the user
to speed up the searching speed or retrieval of data from the database.
Example:
Create an index on the student table and apply the default constraint while creating a table.
To verify that the create index constraint is applied to the student table's column, we will execute the following query:
Example:
To verify that the create index constraint is applied to the student table's column, we will execute the following query:
Consider we have an existing table student. Later, we decided to apply the DEFAULT constraint on the student table's column.
Then we will execute the following query:
RESULT:
Thus the Data Definition Language with constraints and view commands are executed and verified.
EX.NO : QUERY THE DATABASE USING SQL MANIPULATION
DATE:
AIM:
To Query the database using SQL Manipulation i.e. Data Manipulation Language (DML) Commands.
DESCRIPTION:
▪ DML commands are SQL commands, used to manipulation of data i.e., modify
the data present in the database
▪ It is responsible for all form of changes in the database.
▪ The command of DML is not auto-committed that means it can't permanently save
all the changes in the database. They can be rollback.
a. SQL INSERT: SQL INSERT statement is used to insert a single or multiple data into row of a
table.
Syntax:
For example:
Query: INSERT INTO EMPLOYEE VALUES (6, 'Marry', 'Canada', 600000, 48);
Output:
To insert partial column values, you must have to specify the column names.
Syntax
INSERT INTO EMPLOYEE (EMP_ID, EMP_NAME, AGE) VALUES (7, 'Jack', 40);
Output: After executing this query, the table will look like:
b. SQL UPDATE:
● This command is used to update or modify the value of a column in the table.
● SQL UPDATE statement is used to modify the data that is already in the database.
● The condition in the WHERE clause decides that which row is to be updated.
Syntax:
UPDATE table_name
Sample Table:
EMPLOYEE
EMP_ID EMP_NAME CITY SALARY AGE
1 Angelina Chicago 200000 30
2 Robert Austin 300000 26
3 Christian Denver 100000 42
4 Kristen Washington 500000 29
5 Russell Los angels 200000 36
6 Marry Canada 600000 48
Updating single record
Update column EMP_NAME and set the value to 'Emma' in the row where SALARY is 500000.
UPDATE EMPLOYEE
If you want to update multiple columns, you should separate each field assigned with a comma.Syntax
UPDATE table_name
SET column_name = value1, column_name2 = value2 WHERE
condition;
Query
UPDATE EMPLOYEE
Syntax:
If you don't specify the WHERE condition, it will remove all the rows from the table.
Delete the row from the table EMPLOYEE where EMP_NAME = 'Kristen'. This will delete only the fourth
row.
Query
Delete the row from the EMPLOYEE table where AGE is 30.
Query
Output: After executing this query, the EMPLOYEE table will look like:
Delete all the row from the EMPLOYEE table. After this, no records left to display. The EMPLOYEE table
will become empty.
Syntax
or
Query
Output: After executing this query, the EMPLOYEE table will look like:
SELECT:
SELECT statement is used to query or retrieve data from a table in the database. The
returns data is stored in a table, and the result table is known as result-set.
Syntax:
SELECT expressions FROM
TABLES
WHERE conditions;
Or
SELECT column1, column2, ... FROM
table_name;
For example:
Use the following syntax to select all the fields available in the table:
SELECT * FROM table_name;
Example: EMPLOYEE
EMP_ID
1
2
3
4
5
To fetch all the fields from the EMPLOYEE table, use the following query:
SELECT * FROM EMPLOYEE
Output
RESULT:
Thus, SQL Data Manipulation Language (DML) Commands for Querying the database has been
executed.
EX.NO : QUERYING/MANAGING THE DATABASE USING SQL
DATE: MANIPULATION – FUNCTIONS, PROCEDURES AND
TRIGGERS
AIM:
To Query/Manage the Database Using SQL Programming Functions, procedures and triggers.
FUNCTIONS IN SQL
DESCRIPTION: To create a function for deposit and withdrawal of money from an account in a
bank management system this uses bank table.
TABE CREATION:
Table created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created
PROGRAM:
declare
n number;
begin
n:=withdraw(100,20000);
end
/
Statement processed.
select * from bank_acc;
begin
n:=withdraw(101,20000);
end
/
DEPOSIT FUNCTION:
Create a function for depositing money to an account in a bank
/
Function
created
declare
n number;
begin
n:=deposit(104,5000);
end
/
Statement processed.
PROCEDURES IN SQL
DESCRIPTION:
To create a procedure for deposit and withdrawal of money in an account in a bank table
Table Creation:
Table created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
select * from bank;
CREATING A PROCEDURE
Create a procedure for deposit & withdrawal of money in account in a Bank table.
Procedure created.
PROCEDURE CALL - DEPOSIT
begin
bank_pro(1,40000,100);
end;
/
Balance after deposition is 90000
Statement processed.
select * from bank;
begin
bank_pro(2,1500,102);
end;
/
OUTPUT:
Balance after withdrawal is1000
Statement processed.
Select * from bank;
OUTPUT:
Cannot withdraw… Balance lower than-500
Statement processed.
TRIGGERS IN SQL
TRIGGER DESCRIPTION:
SYNTAX:
Create trigger trigger name
BEFORE | AFTER
DELETE, INSERT, UPDATE
ON table name
FOR EACH
ROW BEGIN
Executable-statements
END;
Example:
Create a trigger so that the total and average of specified marks is automatically calculated whenever a
record is inserted.
Database creation:
create table student(sid number(4), name varchar(30), sub1 number(2), sub2 number(2),
sub3 number(2), total number(3), per number(3));
Table Description:
Desc student;
Before Trigger Execution: Inserting Values in table:
insert into student values(1, 'Nivetha', 50, 60, 70, 0, 0);
1 row(s) inserted.
CREATING TRIGGER
create trigger
strigger before insert
on
Student
for each row
Begin
update student set Student.total = Student.sub1 + Student.sub2 + Student.sub3,
Student.per = Student.total/3;
end;
/
OUTPUT: Trigger Created.
After Trigger Execution Inserting Values in table:
Insert into student values(2, 'Rithani', 90, 80, 90, 0, 0);
1 row(s) inserted.
RESULT:
Thus the function, procedure trigger while insert or update or delete operations are performed on
the table student was successfully executed and output was verified
EX.NO : DATABASE DESIGN USING NORMALIZATION BOTTOM-UP
DATE: APPROACH
AIM:
DESCRIPTION:
NORAMALIZATION OF TABLE
▪ Database normalization is the process of removing redundant data from tables in order to improve
storage efficiency, data integrity, and scalability
4NF A relation will be in 4NF if it is in Boyce Codd's normal form and has no
multi-valued dependency.
A relation is in 5NF. If it is in 4NF and does not contain any join dependency,
5NF joining should be lossless.
1. FIRST NORMAL FORM
14 John 7272826385, UP
9064738238
The decomposition of the EMPLOYEE table into 1NF has been shown below:
14 John 7272826385 UP
14 John 9064738238 UP
Example 1:
In Second normal form, every non-prime attribute should be fully functionally dependent on prime key
attribute. That is, if X → A holds, then there should not be any proper subset Y of X, for which Y → A also
holds true.
In Student_Project relation that the prime key attributes are Stu_ID and Proj_ID.
According to the rule, non-key attributes, i.e. Stu_Name and Proj_Name must be dependent upon both and
not on any of the prime key attribute individually.
But Stu_Name can be identified by Stu_ID and Proj_Name can be identified by Proj_ID independently.
This is called partial dependency, which is not allowed in Second Normal Form.
Example: 2 TEACHER
table
TEACHER_ID SUBJECT TEACHER_AGE
25 Chemistry 30
25 Biology 30
47 English 35
83 Math 38
83 Computer 38
In the given table, non-prime attribute TEACHER_AGE is dependent on TEACHER_ID which is a proper
subset of a candidate key. That's why it violates the rule for 2NF.
To convert the given table into 2NF, we decompose it into two tables:
TEACHER_DETAIL table:
TEACHER_ID TEACHER_AGE
25 30
47 35
83 38
TEACHER_SUBJECT table:
TEACHER_ID SUBJECT
25 Chemistry
25 Biology
47 English
83 Math
83 Computer
● A relation will be in 3NF if it is in 2NF and not contain any transitive partial dependency.
● If there is no transitive dependency for non-prime attributes, then the relation must be in third
normal form.
For a relation to be in Third Normal Form, it must be in Second Normal form and must satisfy −
Example:1
In the above Student_detail relation, Stu_ID is the key and only prime key attribute.
City can be identified by Stu_ID as well as Zip itself. Neither Zip is a superkey nor is City a prime
attribute. Additionally, Stu_ID → Zip → City, so there exists transitive dependency.
To bring this relation into third normal form, we break the relation into two relations as follows −
Non-prime attributes: In the given table, all attributes except EMP_ID are non-prime.
Here, EMP_STATE & EMP_CITY dependent on EMP_ZIP and EMP_ZIP dependent on EMP_ID. The non-
prime attributes (EMP_STATE, EMP_CITY) transitively dependent on super key(EMP_ID).
It violates the rule of third normal form. That's why we need to move the EMP_CITY and EMP_STATE
to the new <EMPLOYEE_ZIP> table, with EMP_ZIP as a Primary key.
After 3rd Normalization
EMPLOYEE table:
EMP_ID EMP_NAME EMP_ZIP
222 Harry 201010
333 Stephan 02228
444 Lan 60007
555 Katharine 06389
666 John 462007
EMPLOYEE_ZIP table:
BCNF states that For any non-trivial functional dependency, X → A, X must be a super-key.
In the above Example, Stu_ID is the super-key in the relation Student_Detail and Zip is
the super-key in the relation ZipCodes.
RESULT:
AIM:
To Develop Database Applications Using IDE (Netbeans) To Connect Java Program With
MS-Access Using JDBC Connectivity
JDBC DESCRIPTION
Java has defined its own API (JDBC API) that uses JDBC drivers (written in Java language).
JDBC API is used to handle database using Java program and can perform the following
activities:
1. Connect to the database
2. Execute queries and update statements to the database
3. Retrieve the result received from the database.
Step 1: Open Microsoft Access and select Blank database option and give the database name as File
name option
Step 2: Create a table and insert your data into the table
Step 3: Save the table with the desired name;, we save the following records with the
table name student.
Now Creating DSN of your database
Step 6: Now click on add option for making a new DSN.select Microsoft Access Driver
(*.mdb.
*.accdb) and then click on Finish
Step 7: Make your desired Data Source Name and then click on the Select option, for example in this
article we use the name mydsn
Step 8: Now you select your data source file for storing it and then click ok and then click on
Create
and Finish
Step 9: Java
program code
Test.java
import
java.
sql.*
;
class
Test
DB
{
public static void main(String ar[])
{
Try
{
String url="jdbc:odbc:mydsn";
Class.forName("sun.jdbc.odbc.JdbcOdb
cDriver"); Connection
c=DriverManager.getConnection(url);
Statement st=c.createStatement();
ResultSet rs=st.executeQuery("select * from
login"); while(rs.next())
{
System.out.println(rs.getString(1) + " " + rs.getString(2)+ " " rs.getString(2));
}
}
catch(Exception ee){System.out.println(ee);
}}}
RESULT:
Thus the Database Applications Using IDE (Netbeans) To Connect Java Program
With MS- Access Using JDBC Connectivity is executed.
EX.NO : OBJECT DATABASE DESIGN USING EER-ODB MAPPING /UML
DATE: CLASS DIAGRAMS
AIM:
To develop a database design using EER-to-ODB mapping / UML class diagrams
DESCRIPTION
MAPPING EER TO ODB SCHEMA
An EER conceptual schema for a UNIVERSITY database.
a,ga
...
...
I I
r PI..O¥r[ 1\1..Ut.lNUS DrGREr Sll.lOrNT
Salary
hire_emp new_ar.-.is
,...,_·1 . Year
Dc11rec
Mapr_dept
_Jll&jor
V Mlljor
... ... ...
...
I
t I
i
STAFF FACULTY SJ1U!)ENT ASSISTANT
P'oeiti0e Riu1i Flerc,...,t_time
hi _mff promote hi _studcnl
... ... . ..
I
,,\
I
A I
RESEARCH_ TEACH G_ GRADUATE UNDERGRADUATE_
ASSISTANT ASSISTANT SflUDENT STUDENT
Project Cou""" De9ree- pro!J11ffl c1a..
ch _prnject 1tssign_lo_oo changc_dcgm:_progrill11 cliangic_d1tssif1Calioo
... ... ... ...
FlgureU,9
(a) lntelfa;c.e !fxampl.:: at il d:liab= chtlm!!.
( r::: ,......... , not..J.oon for rBcrn,seolm□ ODL
smem:as. (b) A graph (}bjeci daitabase
crass, STUOe,J
scne.ma fur part of ihe llNIVEFi!SITY
da13ba.ss [GRADE and DEGREE chs.ses
are not s.hown
Relalionsl!ll,s
"'Iii!! al!!
t
CinM inhe!"illln
I herttance u ing eJCtend:i
"F1DE "™ 7
(b)
PEJ SON
STU.ENT
! Mef:-;::lct iicn:i Offarecl_b,;
_IC_O_U_RS--,
1-!a,i;_ flOn
CURR_SECTI N
Reg· ered_swdenw
ODL schema for the UNIVERSITY database
RESULT:
Thus the Database design using EER-to-ODB mapping / UML class diagrams is executed.
EX.NO : OBJECT FEATURES OF SQL-UDTS AND SUB-TYPES, TABLES
DATE: USING UDT’S , INHERITANCE, METHOD DEFINITION
AIM:
To Study about the various Object Features such as SQL-UDTS And Sub-Types, Tables
Using UDTS, Inheritance, Method Definition etc.,
DESCRIPTION
TYPE INHERITANCE
create type Student under Person (degree varchar(20), department varchar (20));
create type Teacher under Person (salary integer, department varchar (20));
Both Student and Teacher inherit the attributes of Person—namely, name and address. Student and
Teacher are said to be subtypes of Person, and Person is a supertype of Student, as well as of Teacher
Multiple inheritance:
Example Creation of a simple UDT hierarchy for a business. The hierarchy implements a Person
UDT and two subtypes:
● Agent and
● Customer.
Objects can also be attributes of other objects. The Person type has been created to include an address
UDT. After the types are created a typed table of Agent objects is created and a new row is inserted into
the table.
insert into Agents values ('001', 'John Smith', Address('123 Main', 'Lal street)
OBJECT FEATURES OF SQL
(b) Using UDTs as types for attributes such as Address and Phon
CREATE TYPE STREET_ADDR_TYPE
AS ( NUMBER
V
, STREET_NAME
A
), APT_NO
R
,
C
C
A 5
R )
SUITE_NO VARCHAR(5)
);
CREATE TYPE USA_ADDR_TYPE AS
( STREET_ADDR
STREET_ADDR_TYP
E, CITY VARCHAR(25),
ZIP VARCHAR(10)
);
CREATE TYPE USA_PHONE_TYPE AS
( PHONE_TYPE
VARCHAR(5
),
AREA_CODE CHAR(3),
PHONE_NUM CHAR(7)
);
USA_ADDR_TYPE
INSTANTIABLE NOT FINAL
INSTANCE METHOD AGE() RETURNS INTEGER;
CREATE INSTANCE METHOD AGE() RETURNS
INTEGER
FOR
PERSON_TYPE
BEGIN
RETURN /* CODE TO CALCULATE A PERSON’S AGE FROM TODAY’S
DATE AND BIRTH_DATE */
END;
);
RESULT:
Thus various Object Features such as SQL-UDTS And Sub-Types, Tables Using UDTS,
Inheritance, Method Definition have been studied.
EX.NO : QUERYING THE OBJECT-RELATIONAL DATABASE USING
DATE: OBJECT QUERY LANGUAGE
AIM:
DESCRIPTION:
● Object Query Language (OQL) is a version of the Structured Query Language. Like SQL,
OQL is a declarative (not procedural) language
● Object Query Language is a query language standard for object-oriented databases modeled
after SQL and developed by the Object Data Management Group.
● OQL is the way to access data in an O2 database. OQL is a powerful and easy-to-use SQL-
like query language with special features dealing with complex objects, values and methods.
● OQL is an attempt by the OO community to extend languages like C++ with SQL-
like, relation-at-a-time dictions.
CREATING DATABASE AND TABLE
Example 2
from database_name.table_name
[ where conditional_test ]
The * symbol can be used in a select statement to return all the columns of the table.
EmployeeID=1;
Name='Matt';
( 1 record(s) : Transaction complete )
Syntax
The following syntax shows how to use the update
keyword. update database_name.table_name
set column = value [ , column = value ... ]
[ where conditional_test ] ;
If the update statement is used without a where condition, all records are updated.
Example: Updates Age column of staff.managers table for any records where Name="John"
Update staff.managers
set Age=30
where Name="John";
▪ Use the show keyword to list the databases, columns, or tables or the current service.
Syntax
show databases ;
show databases;
databases = [ 'staff' ]
( 1 Record(s) : Transaction complete )
Example 2 shows all the tables from the staff database.
delete from
staff.contractors where
Name="Jane";
Deletion of a database or table
▪ Delete a database or table using the drop command.
drop table
staff.managers; drop
database staff;
RESULT:
Thus the Querying of Object-Relational database using Objet Query language was
executed.