dbms 2
dbms 2
Domain Constraints
Domain constraints can be violated if an attribute value is
not appearing in the corresponding domain or it is not of the
appropriate data type.
Example:
Create DOMAIN CustomerName
CHECK (value not NULL)
Example:
1 Google Active
2 Amazon Active
3 Apple Inactive
Update Operation
You can see that in the below-given relation table
CustomerName= 'Apple' is updated from Inactive to Active.
Delete Operation
To specify deletion, a condition on the attributes of the
relation selects the tuple to be deleted.
In the above-given example, CustomerName= "Apple" is
deleted from the table.
Select Operation
DBMS Keys
What are Keys in DBMS?
KEYS in DBMS is an attribute or set of attributes which
helps you to identify a
Example:
Employee FirstName LastName
ID
11 Andrew Johnson
22 Tom Wood
33 Alex Hale
In the above-given example, employee ID is a primary key
because it uniquely identifies an employee record. In this
table, no other employee can have the same employee ID.
Example:
Example:
DeptCode DeptName
001 Science
002 English
005 Computer
Integrity Constraints
o Integrity constraints are a set of rules. It is used to maintain
the quality of information.
o Integrity constraints ensure that the data insertion, updating,
and other processes have to be performed in such a way that
data integrity is not affected.
o A table can contain a null value other than the primary key
field.
Example:
3.
Referential Integrity Constraints
Example:
There are many courses having the same course fee. Here,
COURSE_FEE cannot alone decide the value of COURSE_NO or
STUD_NO.
COURSE_FEE together with STUD_NO cannot decide the value
of COURSE_NO.
COURSE_FEE together with COURSE_NO cannot decide the
value of STUD_NO.
The candidate key for this table is {STUD_NO,
COURSE_NO} because the combination of these two columns
uniquely identifies each row in the table.
COURSE_FEE is a non-prime attribute because it is not part of
the candidate key {STUD_NO, COURSE_NO}.
But, COURSE_NO -> COURSE_FEE, i.e., COURSE_FEE is
dependent on COURSE_NO, which is a proper subset of the
candidate key.
Therefore, Non-prime attribute COURSE_FEE is dependent on
a proper subset of the candidate key, which is a partial
dependency and so this relation is not in 2NF.
To convert the above relation to 2NF, we need to split the
table into two tables such as : Table 1: STUD_NO,
COURSE_NO Table 2: COURSE_NO, COURSE_FEE.
Scienc Dancin
100
e g
Student- Cours Hobb
ID e y
Singin
100 Maths
g
Dancin
101 C#
g
Singin
101 PHP
g
Scienc
100
e
100 Maths
101 C#
101 PHP
Table –
R2
Student- Hobb
ID y
Dancin
100
g
Singin
100
g
Student- Hobb
ID y
Dancin
101
g
Singin
101
g
Student- Mobile
ID Number Hobby
Dancin
123 9999900000
g
Dancin
124 9999900000
g
Student- Mobile
ID Number Hobby
Mobile
Student-ID Number
123 9999900000
123 8975622122
124 9999900000
Table –
R2
Student-ID Hobby
Dancin
123
g
123 Singing
124 Singing
Dancin
124
g
Table –
R3
Mobile
Number Hobby
Dancin
9999900000
g
9999900000 Singing
8975622122 Singing
Thus if natural join is performed on all the three relations then there
will be no extra tuples. Hence R1, R2 and R3 are in fifth normal form
(5NF).