Dbms Unit2
Dbms Unit2
RDBMS is a database management system that is based on the relational model. Data is stored
in the form of tables and relationship among the data is also stored in the form of tables.
Elementary Terminologies of RDBMS.
1) Relation :
A relation is represented in a table as rows and columns. All the rows will contain individual
data. The data in the rows are of distinct data type ,where as data in a particular column are of the
same data type.
2) Domain :Each attribute is associated with a set of values called domain of the attribute
3) Tuple :The rows of a relation are referred to as Tuples.
4) Cardinality :The number of rows or Tuples in a relation is called cardinality.
5)Attributes :The columns of a relation are called attributes.
6) Degree :The number of attributes in each row is called degree of relation.
Relational Algebra and Operations:
Eg: σ Age=15(STUDENT) ,The operation will give the following relation as output
whose age=15
RollNo Name Address Age
101 Anju Kottayam 15
103 Anil Kannur 15
II) Project Operation ( π )
This operation removes certain columns of a given relation.
Eg: π Name,Age (STUDENT) , output is
Name Age
Neenu 14
Anju 15
Raju 14
Anil 15
III) Cartesian product ( X )
This operator combines information from two tables. Consider two tables
STUDENT TEACHER
RollNo Studname Teachname Subject
100 Anju Madhu English
101 Neenu Raju Malayalam
STUDENT X TEACHER
STUDENT1 U STUDENT2
RollNo Name Address Age
100 Neenu Trivandrum 14
101 Anju Kottayam 15
102 Raju Trissur 14
103 Anil Kannur 15
V)The Set Difference operation (-)
The operation allows the user to find the rows in one table but not in the other.
R S R--S
Name Name Name
Jos Rajan Anil
Anil Usha Jos
Tuttu Tuttu
6. Composite/Compound Key
Composite Key is a combination of more than one fields/columns of a table. It can be a Candidate key,
Primary key.
Integrity Rule:
There are four types of integrity constraints in DBMS:
Domain Constraint
Entity Constraint
Referential Integrity Constraint
Key Constraint
1. Domain integrity constraint contains a certain set of rules or conditions to restrict the kind of
attributes or values a column can hold in the database table.
Roll No Name Age Class
101 Adam 14 6
102 Steve 16 8
103 Tim 6 A
In the above student's table, the value A in the last row last column violates the domain integrity
constraint because the Class attribute contains only integer values while A is a character.
2. Entity Integrity Constraint is used to ensure that the primary key cannot be null. A primary key is
used to identify individual records in a table and if the primary key has a null value, then we can't
identify those records. Consider Employees table having Id, Name, and salary of employees
ID Name Salary
1101 Jackson 40000
1102 Ash 180000
James 36000
In the above employee's table, we can see that the ID column is the primary key and contains a null value
in the last row which violates the entity integrity constraint.
3. Referential Integrity Constraint ensures that there must always exist a valid relationship between
two relational database tables. This valid relationship between the two tables confirms that a foreign
key exists in a table. It should always reference a corresponding value or attribute in the other table
or be null.
Consider an Employee and a Department table where Dept_ID acts as a foreign key between the two
tables
Employees Table Department Table
ID Name Salary Dept_ID
1101 Jackson 40000 3
Dept_ID Dept_Name
1102 Harry 60000 2
1 Sales
1103 Steve 80000 4
2 HR
1104 Ash 180000 3
3 Technical
1105 James 36000 1
In the above example, Dept_ID acts as a foreign key in the Employees table and a primary key in the
Department table. Row having DeptID=4 violates the referential integrity constraint since DeptID 4 is
not defined as a primary key column in the Departments table.
4. Key constraint
Keys are the set of entities that are used to identify an entity within its entity set uniquely. There could
be multiple keys in a single entity set, but out of these multiple keys, only one key will be the primary
key. A primary key can only contain unique and not null values in the relational database table.
Example:
Consider a student's table
Roll No Name Age Class
101 Adam 14 6
102 Steve 16 8
103 David 8 4
104 Bruce 18 12
102 Tim 6 2
The last row of the student's table violates the key integrity constraint since Roll No 102 is repeated
twice in the primary key column. A primary key must be unique and not null therefore duplicate
values are not allowed in the Roll No column of the above student's table.