DDM lab manual (1)
DDM lab manual (1)
CONTENTS
2
Page
Ex. No: 1
DATABASE DEVELOPMENT LIFE CYCLE
AIM:
Developing a Database Development Life cycle with a Problem definition and
Requirement analysis Scope and Constraints.
Database Development Life cycle:
A database system is a fundamental component of the larger organization-wide
information system, the database system development lifecycle is inherently associated with
the lifecycle of the information system. The stages of the database system development
lifecycle shown below the name of each stage is the section in this chapter that describes that
stage.
3
Page
Class Diagram – Banking System:
Viva Questions:
1. What are the main stages of the database life cycle, and what are the key activities involved in each
stage?
2. How does the conceptual design phase differ from the physical design phase in the database life
cycle?
3. What is the importance of requirements analysis in the database life cycle, and what are the potential
consequences of inadequate requirements gathering?
4. How is the implementation phase carried out in the database life cycle, and what tools or
technologies are typically used?
5. What are the best practices for database maintenance and monitoring post-deployment, and how do
they contribute to the overall database life cycle?
4
Page
RESULT:
Hence, a Database Development Life cycle with a Problem definition and
Requirement analysis Scope and Constraints developed and understood successfully.
5
Page
Ex. No.2:
MAPPING CONCEPTUAL TO RELATIONAL DATABASE
AIM:
Database design using Conceptual modeling (ER-EER) – top-down approach mapping
conceptual to relational database and validate using Normalization language.
Procedure:
For the following ER model (Conceptual Model), creating the corresponding relational
schema and map the ER model to Relational model.
Create an appropriate heading for the columns of the results table.
The following tables form part of a Library database held in an RDBMS:
Book (ISBN, title, edition, year)
BookCopy (copyNo, ISBN, available)
Borrower (borrowerNo, borrowerName, borrowerAddress)
BookLoan (copyNo, dateOut, dateDue, borrowerNo)
Where,
Book contains details of book titles in the library and the ISBN is the key.
BookCopy contains details of the individual copies of books in the library and copyNo is the
key. ISBN is a foreign key identifying the book title.
Borrower contains details of library members who can borrow books and borrowerNo is
the key.
BookLoan contains details of the book copies that are borrowed by library members and
copyNo/dateOut forms the key. borrowerNo is a foreign key identifying the Borrower.
Book
ISBN Title edition Year
BookCopy
copyNo ISBN Available
Borrower
borrowerNo borrowerName borrowerAddress
6
Page
BookLoan
copyNo dateOut dateDue borrowerNo
Output:
Viva Questions:
1. What is the difference between a primary key and a foreign key in a relational database?
2. How does normalization help in designing a relational database, and what are the normal forms?
3. Can you explain the concept of ACID properties in the context of relational databases?
4. What are the advantages and disadvantages of using indexes in a relational database?
5. How do JOIN operations work in SQL, and what are the different types of JOINs available?
RESULT:
Hence, the corresponding relational model is created and used for the given ER model
successfully.
7
Page
Ex. No: 3
THE DATABASE USING SQL DATA DEFINITION WITH
CONSTRAINTS, VIEWS
AIM:
Implementing the database using SQL Data definition with constraints, Views.
Procedure:
1. Create a table called EMP with the following structure.
Name Type
---------- ----------------------
EMPNO NUMBER(6)
ENAME VARCHAR2(20)
JOB VARCHAR2(10)
DEPTNO NUMBER(3)
SAL NUMBER(7,2)
Allow NULL for all columns except ename and job.
2. Add a column experience to the emp table. experience numeric null allowed.
SQL> alter table emp add(experience number(2));
5. Create the emp1 table with ename and empno, add constraints to check the empno value
while entering (i.e) empno > 100.
8. The organization wants to display only the details of the employees those who are
ASP.(Horizontal portioning)
SQL> create view empview as select * from emp where job='ASP';
SQL> select * from empview;
9. The organization wants to display only the details like empno, empname, deptno,
deptname of the employees. (Vertical portioning)
SQL> create view empview1 as select ename,sal from emp;
Viva Questions:
1. What is Data Definition Language (DDL) and how does it differ from DML (Data Manipulation
Language)?
2. Can you explain the purpose and syntax of the CREATE statement in DDL? Provide an example.
3. How does the ALTER statement work in DDL? What are some common operations you can perform
with it?
4. What are the differences between the DROP and TRUNCATE statements in DDL?
5. How do constraints (such as PRIMARY KEY, FOREIGN KEY, UNIQUE, and CHECK) work in
DDL, and how are they applied to database tables?
RESULT:
Hence, the data definition language commands and views were performed and
implemented successfully.
9
Page
Ex. No: 4
QUERYING THE DATABASE USING SQL MANIPULATION
AIM:
Implementing the database using SQL Data definition with constraints, Views.
Procedure for doing the experiment:
Procedure:
1. Insert a single record into dept table.
SQL> insert into dept values (1,'IT','Tholudur');
2: Insert more than a record into emp table using a single insert command.
SQL> insert into emp values(&empno,'&ename','&job',&deptno,&sal);
3. Update the emp table to set the salary of all employees to Rs15000/- who are working as
ASP
SQL> select * from emp;
EMPNO ENAME JOB DEPTNO SAL
---------- -------------------- ------------- ---------- ----------
1 Mathi AP 1 10000
2 Arjun ASP 2 12000
3 Gugan ASP 1 12000
4. Create a pseudo table employee with the same structure as the table emp and insert rows
into the table using select clauses.
SQL> create table employee as select * from emp;
SQL> desc employee;
7. List the records in the emp table orderby salary in ascending order.
SQL> select * from emp order by sal;
8. List the records in the emp table orderby salary in descending order.
SQL> select * from emp order by sal desc;
10
Page
9. Display only those employees whose deptno is 30.
SQL> select * from emp where deptno=1;
10. Display deptno from the table employee avoiding the duplicated values.
SQL> select distinct deptno from emp;
Viva Questions:
1. What is Data Manipulation Language (DML) and how does it differ from Data Definition Language
(DDL)?
2. What are the main operations of DML, and can you provide examples of each operation using SQL
commands?
3. How do the INSERT, UPDATE, and DELETE statements function in DML, and what are some
best practices to ensure data integrity when using these commands?
4. Can you explain the concept of transactions in DML and how the COMMIT and ROLLBACK
statements are used to manage them?
5. How does DML interact with constraints (such as foreign keys, primary keys, and unique
constraints) and what are some common issues that can arise when manipulating data with these
constraints in place?
RESULT:
Hence, the DML commands using from where clause was performed successfully and
executed.
11
Page
Ex.No:5
QUERYING/MANAGING THE DATABASE USING SQL PROGRAMMING
AIM:
Querying/Managing the database using SQL Programming Stored Procedures /
Functions Constraints and security using Triggers.
Procedures:
Create table student_mark (reg_no number(4) , mark1 number(3), mark2 number(3), mark3
number(3), total number(4), avg number(4));
Insert into student_mark (reg_no,mark1,mark2,mark3) values (1001,78,56,45);
Insert into student_mark (reg_no,mark1,mark2,mark3) values (1002,70,98,85);
Insert into student_mark (reg_no,mark1,mark2,mark3) values (3001,81,66,25);
Insert into student_mark (reg_no,mark1,mark2,mark3) values (4001,63,23,71);
Select * from student_mark;
1001 78 56 45 - -
1002 70 98 85 - -
3001 81 66 25 - -
4001 63 23 71 - -
Create table student (reg_no number(4), name varchar2(20), branch varchar2(10), dob date,
batch number(4));
insert into student values (1001,'Abinaya','CSE','10-Mar-2001',2018);
insert into student values (1003,'Keerthana','CSE','28-sep-2001',2018);
insert into student values (3004,'Manojkumar','ECE','17-Mar-2000',2018);
insert into student values (1002,'Aboorvan','CSE','11-May-2002',2018);
insert into student values (2006,'Naveena','IT','11-May-2002',2018);
select * from student;
12
Page
REG_NO NAME BRANCH DOB BATCH
Procedure Execution
begin
updatetotal(1001);
end;
select * from student_mark;
13
Page
REG_NO MARK1 MARK2 MARK3 TOTAL AVG
1001 78 56 45 179 60
1002 70 98 85 0 0
3001 81 66 25 0 0
2002 65 56 49 0 0
4001 63 23 71 0 0
Creation of Functions
1.Function Creation
Function created.
2.Function Execution
declare
rno number(5);
ssnm varchar2(20);
begin
rno := :Enter_reg_no;
ssnm:=get_sname (rno);
dbms_output.put_line('Student name: '||ssnm);
end;
14
Page
Input
:Enter_reg_no=1002
Output
Student name: ANBARASAN
Statement processed.
Input
:Enter_reg_no=3001
Output
Student name: ASHOK
Statement processed.
Input
:Enter_reg_no=2001
Output
ORA-01403: no data found
Function created.
4.Function Execution
declare
n number:=:Enter_n;
begin
dbms_output.put_line('Factorial of '||n||' is '||fact(n));
end;
Input
:Enter_n = 6
Output
Factorial of 6 is 720
Statement processed.
15
Page
Trigger created.
1001 78 56 45 179 60
1002 99 98 85 282 94
3001 81 66 25 0 0
2002 65 56 49 0 0
4001 63 23 71 0 0
1003 67 78 57 202 67
16
Page
Viva Questions:
1. What is a stored procedure in SQL and what are its key benefits?
2. How can you pass parameters to a stored procedure in SQL?
3. Explain the process of creating a stored procedure in SQL. Can you provide an example?
4. What are the common error handling mechanisms within SQL stored procedures?
5. How can you call a stored procedure within another stored procedure in SQL?
RESULT:
Hence, the Querying/Managing the database using SQL Programming Stored
Procedures/Functions Constraints and security using Triggers were performed successfully
and executed.
17
Page
Ex.No: 6
DATABASE DESIGN USING NORMALIZATION BOTTOM-UP APPROACH
AIM:
To design a database using Normalization-Bottom Up approach.
In the above table, we can clearly see that the Phone Number column has two values.
Thus it violated the 1st NF. Now if we apply the 1st NF to the above table we get the
below table as the result.
We have achieved atomicity and also each and every column have unique values.
2nd Normal Form (2NF)
The first condition in the 2nd NF is that the table has to be in 1st NF. The table
also should not contain partial dependency. Here partial dependency means the
proper subset of candidate key determines a non-prime attribute.
DEPARTMENT ID OFFICE LOCATION
EMPLOYEE
1EDU001 ED-T1 Pune
1EDU002 ED-S2 Bengaluru
1EDU003 ED-M1 Delhi
1EDU004 ED-T3 Mumbai
This table has a composite primary key Employee ID, Department ID. The non-
key attribute is Office Location. In this case, Office Location only depends on
Department ID, which is only part of the primary key.
18
Therefore, this table does not satisfy the second Normal Form. To bring this
table to Second Normal Form, we need to break the table into two parts.
Page
EMPLOYEE ID DEPARTMENT ID
1EDU001 ED-T1
1EDU002 ED-S2
1EDU003 ED-M1
1EDU004 ED-T3
DEPARTMENT ID OFFICE
LOCATION
ED-T1 Pune
ED-S2 Bengaluru
ED-M1 Delhi
ED-T3 Mumbai
In the table, the column Office Location is fully dependent on the primary key of that table,
which is Department ID.
3rd Normal Form (3NF)
The table has to be in 2NF before proceeding to 3NF. The other condition is
there should be no transitive dependency for non-prime attributes.
That means non-prime attributes (which doesn’t form a candidate key) should
not be dependent on other non-prime attributes in a given table.
So a transitive dependency is a functional dependency in which X → Z (X
determines Z) indirectly, by virtue of X → Y and Y → Z.
1DT15ENG01 NAME
Alex ID
15CS11 Goa
1DT15ENG02 Barry 15CS13 Bengaluru
1DT15ENG03 Clair 15CS12 Delhi
1DT15ENG04 David 15CS13 Kochi
SUBJECT ID SUBJECT
15CS11 SQL
15CS13 JAVA
19
15CS12 C++
15CS13 JAVA
Page
Viva Questions:
RESULT:
Procedure :
1 Create the DB for banking system source request the using SQL
2 Establishing ODBC connection
3 Click add button and select oracle in ORA home 90 click finished
A window will appear give the data source name as oracle and give the
4 user id as Scott
Now click the test connection a window will appear with server and user
5 name give user as scott and password tiger Click ok
VISUAL BASIC APPLICATION:-
6 Create standard exe project in to and design ms from in request
format
To add ADODC project select component and check ms ADO
data control click ok
Now the control is added in the tool book
Create standard exe project in to and design ms from in request
format
ADODC CONTEOL FOR ACCOUNT FROM:-
7 Click customs and property window and window will appear and select
ODBC data source name as oracle and click apply as the some window.
a) Program:
CREATE A TABLE IN ORACLE
SQL>create table account(cname varchar(20),accno number(10),balance number);
Table Created
SQL> insert into account values('&cname',&accno,&balance);
Enter value for cname: Mathi
Enter value for accno: 1234 Enter
value for balance: 10000
old 1: insert into account values('&cname',&accno,&balance)
new 1: insert into emp values('Mathi',1234,10000) 1 row created.
SOURCE CODE FOR FORM1
Private Sub ACCOUNT_Click()
Form2.Show
End Sub
Private Sub EXIT_Click()
Unload Me
End Sub
Private Sub TRANSACTION_Click() Form3.Show
End Sub
SOURCE CODE FOR FORM 2
21
Text2.Text = ""
Text3.Text = "" End
Sub
End Sub
Page
23
Page
Viva Questions:
1. What is Visual Basic (VB)?
2. What is an event in Visual Basic?
3. What is a form in Visual Basic?
4. What is an object in Java?
5. How do you declare a variable in Visual Basic?
RESULT:
24
Declare an extent for each class, and specify any key attributes as keys of the
extent.
included instead of the reference attribute. However, this does not allow the use
Page
of the inverse constraint. Additionally, if this choice is represented in both
directions, the attribute values will be represented twice, creating redundancy.
Step 3. Include appropriate operations for each class. These are not available
from the EER schema and must be added to the database design by referring to
the original requirements. A constructor method should include program code
that checks any constraints that must hold when a new object is created. A
destructor method should check any constraints that may be violated when an
object is deleted. Other methods should include any further constraint checks
that are relevant.
Step 4. An ODL class that corresponds to a subclass in the EER schema inherits
(via extends) the attributes, relationships, and methods of its superclass in the
ODL schema. Its specific (local) attributes, relationship references, and
operations are specified, as discussed in steps 1, 2, and 3.
Step 5. Weak entity types can be mapped in the same way as regular entity
types. An alternative mapping is possible for weak entity types that do not
participate in any relationships except their identifying relationship; these can
be mapped as though they were composite multivalued attributes of the owner
entity type, by using the set<struct<…>> or list<struct<…>> constructors. The
attributes of the weak entity are included in the struct<…> construct, which
corresponds to a tuple constructor.
Attributes are mapped as discussed in steps 1 and 2.
Step 6. Categories (union types) in an EER schema are difficult to map to ODL.
It is possible to create a mapping similar to the EER-to-relational mapping by
declaring a class to represent the category and defining 1:1 relationships
between the category and each of its superclasses.
Step 7. An n-ary relationship with degree n > 2 can be mapped into a separate
class, with appropriate references to each participating class. These references
are based on mapping a 1:N relationship from each class that represents a
participating entity type to the class that represents the n-ary relationship. An
M:N binary relationship, especially if it contains relationship attributes, may
also use this mapping option, if desired.
26
Page
EER Diagram Notation for a University database
27
Page
A UML class diagram corresponding to the EER diagram in above Figure
illustrating UML notation for specialization/generalization.
Viva Questions:
1. What is a UML class diagram?
2. What are the main components of a UML class diagram?
3. How do you represent a class and its attributes in a UML class diagram?
4. What types of relationships can be depicted in a UML class diagram?
5. How do you indicate visibility (public, private, protected) of class members in a UML
class diagram?
RESULT:
28
AIM:
Implementing Object features of SQL UDTs and sub types, Tables using UDTs,
Inheritance, Method definition.
Procdedure:
To implement a method, create the PL/SQL code and specify it within
a CREATE TYPE BODY statement.
For example, consider the following definition of an object type named rational
type:
CREATE TYPE rational_type AS OBJECT
( numerator INTEGER,
denominator INTEGER,
MAP MEMBER FUNCTION rat_to_real RETURN REAL,
MEMBER PROCEDURE normalize,
MEMBER FUNCTION plus (x rational_type)
RETURN rational_type);
RETURN ans;
Page
END;
Viva Questions:
1. What is a User-Defined Type (UDT) in programming, and how does it differ from a
built-in type?
2. How do you define a UDT in your programming language of choice, and what syntax
is used?
3. What are the primary features or components of a UDT? Can you provide an
example?
4. How can you create methods or functions to interact with a UDT, and how do these
methods differ from standard functions?
5. How does encapsulation work with UDTs, and why is it important for maintaining
object integrity?
30
RESULT:
Thus the SQL features have been understood clearly.
Page
Ex.No: 10
QUERYING THE OBJECT-RELATIONAL DATABASE USING OBJECT
QUERY LANGUAGE
AIM:
To create the querying the object-relational database using Object Query
Language
Procedure:
Create the Table.
Insert the Values.
Display the Table.
Program:
CREATE TABLE Employees (FirstName VARCHAR(32) NOT NULL,
Surname VARCHAR(64) NOT NULL,DOB DATE NOT NULL,
Salary DECIMAL(10,2) NOT NULLCHECK ( Salary > 0.0 ),
Address_1 VARCHAR(64) NOT NULL,Address_2 VARCHAR(64)
NOT NULL, City VARCHAR(48) NOT NULL,State CHAR(2) NOT
NULL,ZipCode INTEGER NOT NULL,PRIMARY KEY ( Surname,
FirstName, DOB ));
INSERT INTO Employees ( Pager_Number, Pass_Code, Message )
SELECT E.Pager_Number,E.Pass_Code,
Print(E.Name) || ': Call 1-800-TEMPS-R-US for immediate INFORMIX
DBA job' FROM Temporary_Employees E WHERE Contains
(GeoCircle('(-122.514, 37.221)', '60 miles')),E.LivesAt )
AND DocContains ( E.Resume, 'INFORMIX and Database Administrator')
AND NOT IsBooked ( Period(TODAY, TODAY + 7),E.Booked );
SELECT *FROM Employees;
31
Page
Output:
Viva Questions:
1. What is Object Query Language (OQL) and how does it differ from SQL?
2. How do you use OQL to retrieve all instances of a specific class in an object-oriented
database?
3. What syntax does OQL use for querying object attributes and relationships?
4. How can you perform a join operation in OQL to combine data from related objects?
5. Can you write a simple OQL query to find objects that meet certain criteria, such as
those with a specific attribute value?
RESULT:
Thus the querying the object-relational database using Object Query Language
has been designed successfully.
32
Page