Documente Academic
Documente Profesional
Documente Cultură
System
Homework-2
Submitted By:
Section: E - 3004
Roll_No: RE3004B77
Group: 2
Course_code: 1604
Subject_code: CAP301
Date_Of_Submission: 20/09/2010
Submitted To:
Insurance database
Person ( driverid, name, address)
Car (license, model, year)
Accident (reportnumber , date, location)
Owns(driverid, license)
Participated(driverid, car, reportno, damageamount)
Ans:- (
a) select count(*) from owns where
participated.driverid=owns.driverid and
participated.reportno=accident.reportno and accident.date
between 1-jan-1989 and 31-dec-1989;
Q2:-> Explain the various formats for inserting the records into
the database table?
Ans:
There are three formats for inserting the records into the database.
The first form doesn't specify the column names where the data will
be inserted, only their values:
Syntax:
Example:
The second form specifies both the column names and the values to
be inserted:
Syntax:
Example:
Ans:
We will have to use the IS NULL and IS NOT NULL operators to check
the NULL values.
Example:
(b) GROUP BY
(c) JOIN
Customers:
Sales:
Example:
Types of JOIN
Inner join
Outer join
Cross join
1. Inner join:
Inner join is the default type of join, it will produces the result
set, which contains matched rows only.
2. Outer join:
Outer join produces the results, which contains matched rows
and unmatched rows.
3. Cross join:
A join without having any condition is known as cross join, in cross join
every row in first table is joins with every row in second table. Cross
join is nothing but Cartesian product.
(d) VIEW
A view is defined using the create view statement which has the
form
Once a view is defined, the view name can be used to refer to the
virtual relation that the view generates.
syntax:-
Select……
From (select…..
From…..
Where……
)
Where……
(f) Where Clause
(f) ORDER BY
SELECT column_name(s)
FROM table_name
ORDER BY column_name(s) ASC|DESC
Example:
Ascending order
Descending order
Ans:
A trigger is a statement that is executed automatically by the
system as a side effect of a modification to the database.
To design a trigger mechanism, we must:
Specify the conditions under which the trigger is to be
executed.
Specify the actions to be taken when the trigger
executes.
Before Triggers
The BEFORE triggers execute the trigger action before the triggering
statement (INSERT/DELTE/UPDATE) is executed. The BEFORE triggers
are commonly used in the following situations :
For example,
a) BEFORE UPDATE trigger on Items table can be allowed to be
completed if only there exists a corresponding record for the Delivery
table for a particular item. That is, if only an item has been delivered
then its stock quality can be updated otherwise this update operation
would not be allowed to complete at all.
b) When specific column values need to be delivered before
completing a triggering INSERT or UPDATE statement. For example, a
BEFORE INSERT trigger on the student table may be used to assign a
value for the primary key column BEFORE a new record is inserted into
this table. This trigger is activated upon the INSERT operation into the
student table and the trigger actions are executed BEFORE the INSERT
itself is performed.
After Triggers
Ans:
Insert Anomalies
Modification Anomalies
Ans:
Functional Dependency (F.D) – Functional dependency represents
semantic association between attributes. If a value of an attribute A
determines the value of another attribute B, we say B is functionally
dependent on A. This is denoted by
A => B and read as “A determines B” and A is called the determinant
Ans:
Multi-valued Dependency—Multi-valued dependency refers to m:n
(many-to-many) relationships. We say multi-valued dependency exists
between two data items when one value of the first data item gives a
collection of values of the second data item i.e., it multi-determines
the second data items.
Ans:
Join Dependency—If we decompose a relation into smaller relations
and the join of the smaller relations does not give us tuples as in the
parent relation, we say the relation has join dependency.
Fifth normal form (5NF and also PJ/NF) requires that there
are no non-trivial join dependencies that do not follow from
the key constraints. A table is said to be in the 5NF if and only
if it is in 4NF and every join dependency in it is implied by the
candidate keys.
Ans:
Boyce-Codd normal form (or BCNF) is a normal form used in
database normalization. It
is a slightly stronger version of the third normal form (3NF). A table is
in Boyce-Codd
normal form if and only if, for every one of its non-trivial functional
dependencies X →
Y, X is a superkey—that is, X is either a candidate key or a superset
thereof.
Only in rare cases does a 3NF table not meet the requirements of
BCNF. A 3NF table
which does not have multiple overlapping candidate keys is
guaranteed to be in BCNF.
Boyce-codd Normal Form (BCNF)A Table is in BCNF if and only if every
determinant
is a candidate key. BCNF is a stronger form of 3NF.