DBMS_Unit3_Notes
DBMS_Unit3_Notes
Domains: A domain is a set of values permitted for an attribute in a table. Domain is atomic. For
example, age can only be a positive integer. A data type or format is also specified for each
domain. It is possible for several attributes to have the same domain. The data type for
Employee_ages is an integer number. Some examples of domains follow:
■ Mobile numbers, . The set of ten-digit phone numbers is valid
■Local_phone_number, The set of seven-digit phone numbers valid within a particular area code
■Social_security_numbers, . The set of valid nine-digit Social Security numbers.
Attribute: Each column in a Table. Attributes are the properties which define a relation. e.g.,
Student_Rollno, NAME,etc.
Tuple – It is nothing but a single row of a table, which contains a single record.
Relations- are in the table format. It is stored along with its entities. A table has two properties
rows and columns. Rows represent records and columns represent attributes.
Relation schema- A relational schema is the design for the table. It includes none of the actual
data, but is like a blueprint or design for the table, so describes what columns are on the table and
the data types. It may show basic table constraints ( e.g. if a column can be null) but not how it
relates to other tables.
A relation schema R, denoted by R (A1,A2, ..., An), is made up of a relation name R and a
list of attributes, A1,A2, ...,An. Each attribute Ai is the name of a role played by some domain D in
the relation schema R. D is called the domain of Ai and is denoted by dom(Ai). The relation
schema R(A1,A2, ...,An), also denoted by r(R), is a set of n -tuples r= {t1,t2, ...,tm}.
Degree- (or arity) of a relation is the number of attributes n of its relation schema. A relation of
degree seven, which stores information about university students, would contain seven attributes
describing each student. as follows:
STUDENT(Name,Ssn,Home_phone,Address,Office_phone,Age,Gpa)
Cardinality: Total number of rows present in the Table.
Relation instance – Relation instance is a finite set of tuples at a given time. The current relation
state reflects only the valid tuples that represent a particular state of the real world.
Null value: A field with a NULL value is a field with no value. Primary key can’t be a null value.
Characteristics of Relations
● Values in a tuple: All values are considered atomic. A special null value is used to
represent values that are unknown or inapplicable to certain tuples. In general, NULL
values, means value unknown or value exists but is not available.
1. Constraints that are inherent in the data model. We call these inherent model-based constraints
or implicit constraints.
2. Constraints that can be directly expressed in schemas of the data model, typically by specifying
them in the DDL.
3. Constraints that cannot be directly expressed in the schemas of the data model, and hence
must be expressed and enforced by the application programs. This is known as application-based
or semantic constraints or business rules.
The schema-based constraints include domain constraints, key constraints, constraints on NULL s,
entity integrity constraints, and referential integrity constraints.
Domain constraints:
Each table has certain set of columns and each column allows a same type of data, based on its
data type. The column does not accept values of any other data type.
Domain constraints are user defined data type and we can define them like this:
Domain Constraint = data type + Constraints (NOT NULL / UNIQUE / PRIMARY KEY / FOREIGN
KEY / CHECK / DEFAULT)
Here, value ‘A’ is not allowed since only integer values can be taken by the age attribute.
Key constraints
An attribute that can uniquely identify a tuple in a relation is called the key of the table. All the
values of primary key must be unique.
This relation does not satisfy the key constraint as here all the values of primary key are not
unique.
This relation does not satisfy the entity integrity constraint as here the primary key contains a NULL value.
● The relation ‘Student’ does not satisfy the referential integrity constraint.
● This is because in relation ‘Department’, no value of primary key specifies department no.
14.
● Thus, referential integrity constraint is violated.
A trigger is a statement or a block of statement which are executed automatically by the system
when an event like insert, update or delete takes place on a table.Triggers are more powerful
because the can check conditions and also modify the data.
Assertions - An assertion is a piece of SQL which makes sure a condition is satisfied or it stops
action being taken on a database object. It could mean locking out the whole table or even the
whole database. Assertions do not modify the data, they only check certain conditions.
● Delete Operation: is used to delete tuples from the table. The Delete operation can violate
only referential integrity. This occurs if the tuple being deleted is referenced by foreign
keys from other tuples in the database. Here are some examples.
-Operation: Delete the Department tuple with Dept NO = 1.
Result: This deletion is acceptable and deletes exactly one tuple.
-Operation:Delete the Student tuple with Dept No = 1.
Result: This deletion is not acceptable, because there are tuples in Department that
refer to this tuple.
Several options are available if a deletion operation causes a violation. The first option,
called restrict, is to reject the deletion. The second option, called cascade. A third option, called set
null or set default, is to modify the referencing attribute values that cause the violation.And also
combinations of these three options are also possible.
● Update Operation:Modify allows you to change the values of some attributes in existing
tuples. Consider two table EMPLOYEE(Ssn, name, salary, Dno) and DEPARTMENT(Dno,
Dname)
-Operation:Update the salary of the EMPLOYEE tuple with Ssn = ‘123’ to 2800.
Result: Acceptable.
-Operation:Update the Dno of the EMPLOYEE tuple with Ssn = ‘123’ to 7.
Result: Unacceptable, because it violates referential integrity.
-Operation:Update the Ssn of the EMPLOYEE tuple with Ssn = ‘123‘ to ‘321’.
Result: Unacceptable, because it violates primary key constraint
Updating an attribute that is neither part of a primary key nor of a foreign key usually causes no
problems.
The initial relational schema is expressed in the following format writing the table names
with the attributes list inside a parentheses as shown below for
Student( Roll_No , Name, Class, Subject )
● Create table for each entity.
● Entity's attributes should becomes column of tables with their respective data types.
● Declare primary key.
A multi-valued attribute is usually represented with a double-line oval.
If you have a multi-valued attribute, take the attribute and turn it into a new entity or table of
its own.
Person( personid , name)
Phones ( personid, phone )
Phones Person
A composite attribute,
Mapping Relationship
A relationship is an association among entities.
-One to many
-many to many
-many to one
Many to Many
● SELECT (symbol: σ)
● PROJECT (symbol: π)
● RENAME (symbol:ρ )
● UNION (υ)
● INTERSECTION ( ),
● DIFFERENCE (-)
● JOIN
● DIVISION
● CARTESIAN PRODUCT ( x )
SELECT (σ):The SELECT operation is used for selecting a subset of the tuples according to a
given selection condition. Sigma(σ)Symbol denotes it.
σ condition (Relation)
STUDENT
ID NAME MARK
1 Jisy 70
2 vishnu 75
3 Dwayne 80
Projection(π): The project operation is used for selecting attributes according to a given selection
condition.
Π Attribute (Relation)
Combination of Select and Project: Retrieve ID and Name from STUDENT where mark>=75
Π ID, NAME ( σ Mark>=75 (STUDENT))
Rename Operation (ρ):
. The rename operation allows us to rename the oldt relation to new. ‘Rename’ operation is
denoted with small Greek letter rho ρ.
ρN ew (Old Relation Name)
Union operation (υ):UNION is symbolized by ∪ symbol. It includes all tuples that are in tables A
or in B. It also eliminates duplicate tuples. A ∪ B
For a union operation to be valid, the following conditions must hold -
ARTS SPORTS
ID NAME ID NAME
1 A 3 C
2 B 2 B
3 C 4 D
ID NAME
1 A
2 B
3 C
4 D
Intersection : A ∩ B of two sets A and B is the set that contains all elements of A that also belong
to B (or equivalently, all elements of B that also belong to A) , but no other elements.
Retrieve students name those who participant in both arts and sports:
ID NAME
2 B
3 C
Set Difference (−):The result of set difference operation is tuples, which are present in one
relation but are not in the second relation.
Retrieve students name those who participant only in arts and not in sports:
Π NAME (ARTS) - Π NAME (SPORTS)
ARTS - SPORTS
ID NAME
1 A
Retrieve students name those who participant only in sports and not in arts:
Π NAME (SPORTS) - Π NAME (ARTS)
4 D
A B
K Y K Y
1 A 1 C
2 B 3 D
A Χ B
K Y K Y
1 A 1 C
1 A 3 D
2 B 1 C
2 B 3 D
Join operation (⋈):Used to combine two tables having same attributes.Two type,
● Inner join
● Outer Join
Inner join ⋈:If the join criterion is based on equality of column values, the result is called an
equijoin. A natural join is an equijoin with redundant columns removed
STUD DEPT
ID NAME DNO. DNO DNAME
1 A 1 1 CS
2 B 2 2 EC
3 C 3 4 EE
1 A 1 CS
2 B 2 EC
Outer joins: Includes all the tuples from the participating relations in the resulting relation. There
are three kinds of outer joins:
● Left outer join
● Right outer join
● Full outer join.
Left Outer Join(R S):All the tuples from the Left relation, R, are included in the resulting
relation. If there are tuples in R without any matching tuple in the Right relation S, then the
S-attributes of the resulting relation are made NULL.
STUD DEPT
ID NAME DNO. DNAME
1 A 1 CS
2 B 2 EC
3 C 3 Null
Right Outer Join: ( R S ):All the tuples from the Right relation, S, are included in the
resulting relation. If there are tuples in S without any matching tuple in R, then the R-attributes of
resulting relation are made NULL.
STUD DEPT
ID NAME DNO. DNAME
1 A 1 CS
2 B 2 EC
Null Null 4 EE
Full Outer Join: ( R S):All the tuples from both participating relations are included in the
resulting relation. If there are no matching tuples for both relations, their respective unmatched
attributes are made NULL.
STUD DEPT
ID NAME DNO. DNAME
1 A 1 CS
2 B 2 EC
3 C 3 Null
Null Null 4 EE
Division operation ( ÷ ):The Division operator results in columns values in one table for which
there are other matching column values corresponding to every row in another table.