Unit II_K scheme_DMS
Unit II_K scheme_DMS
SYSTEM
DMS(313302)
Unit II
2c. Design SQL queries to create Relational database and apply in the given data
constraint
What is field?
• A field is a column in a table that is designed to maintain specific information about
every record in the table.
• Every table is broken up into columns called fields. The fields in the EMPLOYEE table
consist of Emp_no, Emp_nm, Dept, salary.
What is a Record?
• A record is also called as a row of data is each individual entry that exists in
a table.
• For ex. there are 3 records in the above EMPLOYEE table. Following is a
single row of data or record in the CUSTOMERS table −
101 AAA Account 30000
• Entity
• An entity is a “thing” or “object” in the real world.
• An entity contains attributes, which describe that entity. So anything
about which we store information is called an entity.
• Entities are recorded in the database and must be distinguishable,
i.e., easily recognized from the group.
• For example: A student, An employee, or bank a/c, etc. all are
entities.
Entity
• Attribute: It refers to every column present in a table. The attributes
refer to the properties that help us define a relation.
Degree
Domain
Emp_no= {101, 102, 103}
Emp_nm= {James, Jenny, Smith}
States= {California, New York, Texas}
Key concept
• Keys are very important part of Relational database model. They are used to
establish and identify relationships between tables and also to uniquely
identify any record or row of data inside a table.
Branch Table
Integrity Constraint
• Integrity means correctness and completeness of data. Constraints means
restriction.
• Integrity constraints means the mechanism used to prevent invalid data
entry into table.
• Integrity constraint are rules defined in a database to maintain data
accuracy, Consistency and reliability
Domain Integrity constraints
• A domain constraint defines the valid range of values that a
column can hold.
•These rules apply to the data before data is inserted into table
and column.
1) Default constraint
• By default all columns allow null values, but when not null constraint is enforced for the column,
then that column does not allow null values.
• The NOT NULL constraint specifies that a column in a table must not contain any null values.
• It ensures that a particular attribute or field cannot be left empty or undefined for any record in
the table.
Syntax:
Create table <tableName> (column_name datatype(size) not null);
EX:
Create table Student(Rollno number(5) , Stud_name varchar2(20) not null);
3) Check constraint
• These constraints defines the condition that each row must satisfied.
• The CHECK constraint explains a condition that must be satisfied for the values in a
columns. It allows you to limit the range of acceptable values based on a specific
condition or expression.
Syntax
Ex.
Syntax:
Syntax:
Create table table_name(ColumnName datatype(size) unique);
EX:
Create table Student(Rollno number(5) unique, Stud_name varchar2(20));
Data modeling using E-R model
• ER model stands for an Entity-Relationship model. It define relationship among
different entities
• It is a graphical Graphical representation of database.
• Relational Model Defines one entity and its objects
Entity-Relationship model Connects different entities as per their
relationship
Features:
It is used to give structure to the data.
It simple and easy for understanding.
It can be easily converted into table.
Good database design can be prepared using E-R model.
Symbols used to draw E-R model
Symbol Meaning
Entity(strong entity)
Weak entity
Attribute
Multivalued attribute
Derived attribute
Symbols used to draw E-R model
Symbol Meaning
Primary key attribute
_______
Relationship
Weak relationship
Components of E-R modeling
1. Entity:
An entity is any object in the system that we want to store in the database.(any thing
about which data are to be collected and stored)
• Group of same type of entities are called entity sets.
Two types:
a) Strong Entity set:
The entity which is not depend on any other entity for its existence or entity which has
sufficient attribute to form a primary key.
3. Simple attribute:
An attribute that cannot be further subdivided into components is a simple
attribute.
Example: The roll number of a student, the ID number of an employee
4. Composite attribute:
• An attribute that can be split into subparts is a composite attribute.
(It can be divided into sub parts)
• Example: The address can be further split into house number, street
number, city, state, country, and pin code, the name can also be split
into first name middle name, and last name.
5. Derived attribute:
• An attribute that can be derived from other attributes is derived attributes. And it is
represented by dotted oval shape.
• Example: Total and average marks of a student, age of an employee that is derived
from date of birth.
6. Key attribute
• Key attributes are those attributes that can uniquely identify the entity in
the entity set.
Example: Roll-No is the key attribute because it can uniquely identify the
student.
7. Null Attribute
• This attribute can take NULL value when entity does not have value for it.
Example –The ‘Net Banking Active ’ attribute gives weather particular customer
having net banking facility activated or not activated.
• For bank which does not offer facility of net banking in customer table ‘Net
Banking Active’ attribute is always null till Net banking facility is not activated as
this attribute indicates Bank offers net banking facility or does not offers.
8. Complex Attribute
• Those attributes, which can be formed by the nesting of composite and
multi-valued attributes, are called “Complex Attributes“. These
attributes are rarely used in DBMS
• Example: Address because address contain composite value like street,
city, state, PIN code and also multi valued because one people has more
that one house address.
Relationship
• A relationship is used to describe the relation between entities. Diamond is used
to represent the relationship
3. Many-to-one relationship
• When more than one instance of the entity on the left, and only one instance of
an entity on the right associates with the relationship then it is known as a many-
to-one relationship.
• For example, Student enrolls for only one course, but a course can have many
students.
4. Many-to-many relationship
• When more than one instance of the entity on the left, and more than one instance of an entity
on the right associates with the relationship then it is known as a many-to-many relationship.
• For example, Employee can assign by many projects and project can have many employees.
Teacher_name
Roll_no Student_name
Contact_no
Teacher_ID
1 Ashish
2 Anurag
3 Varun
4 Rucha
Functional dependencies
• F(a) b • Definition :
•A B , it is called as A A Functional Dependency is a
determines B constraint that specifies the
• In Functional dependency An relationship of one attribute to
Attribute which determines another attribute in a Relation or
other Attribute is called a Table
Determinant Attribute.
• Attribute which determined by That is
Determinant is called A Determines B is represented by
Dependent Attribute.
A B
Functional Dependency Example
Rollno Student_Name Dept_Name Dept_Build • Functional Dependency :
ing
Rollno {Student_Name, Dept_Name,
2 Amit CS A4 Dept_Building}
3 Geeta IT A3
Case 1:
4 Ashish CS A4
Ex. : 3 {Geeta, IT, A3}
5 Ashish IT A3
Detarminant Dependant
6 Yusuf EC B2 1 A
2 B
7 Shreyas ME B2
Valid Functional Dependency
Functional Dependency Example
Rollno Student_Name Dept_Name Dept_Build • Functional Dependency :
ing
Dept_Name Dept_Building
2 Amit CS A4
3 Geeta IT A3 Case 2:
4 Ashish CS A4
Ex. : CS A4
CS A4
5 Ashish IT A3
Detarminant Dependant
6 Yusuf EC B2 1 A
1 A
7 Shreyas ME B2
Valid Functional Dependency
Functional Dependency Example
Rollno Student_Name Dept_Name Dept_Build • Functional Dependency :
ing
Dept_Name Dept_Building
2 Amit CS A4
Case 3: Determinant Dependant
3 Geeta IT A3 Ex. : EC B2
1 A
4 Ashish CS A4
ME B2 2 A
Valid Functional
5 Ashish IT A3 Dependency
5 Ashish IT A3
Determinant Dependant
6 Yusuf EC B2 1 A
1 B
7 Shreyas ME B2
Invalid Functional Dependency
Functional Dependency
Fully functional dependency
• An attribute is fully functional dependent on another attribute, if it is
Functionally Dependent on that attribute and not on any of its proper
subset
• It is represented as {A, B} C
Fully Functional Dependency Example -1
StudID Course_ID Marks • Fully Functional Dependency :
{A, B} C
1 Amit 87
ex : {STUDENTID, COURSEID} MARKS
1 Geeta 82 STUDENTID MARKS
1 Ashish 91
COURSEID MARKS
2 Amit 77
2 Geeta 81
2 Ashish 75
Multi valued Functional Dependency
• A {B, C}
• Consider functional dependency , A {B, C} is Multi valued
dependency if there is no functional dependency between
dependents B and C , that is there should not be any functional
dependency
• Let A, B, C are three distinct attributes, if we have A primary key and non key
attributes B and C where, C is more dependent upon B than A (B->C) and B is
directly dependent on A (A->B) then C can be considered as transitively dependent
on A.
• Delete Anomalies:
If User want to delete any sports the entire record will be deleted.
This is called as Delete Anomalies.
• Update Anomalies:
Due to this anomalies original contents of entire data will be changed
EMP table Department Table
E_ID name Age Dept_id Dept_name Dept_head Dept_phone
1 Abc 34 7 Design Pqr 123
2 Mno 27 7 Design Pqr 123
3 Xyz 26 10 Production Tuv 987
4 Slr 40 10 Production Tuv 987
5 Smg 35 3 R&D Ksi 555
6 dmr 29 3 R&D ksi 555
Normal forms
1NF (First normal form)
• The relation said to be in 1NF if values in the domain of each attribute are
atomic.
• It does not allow multivalued attribute and composite attribute.
• Ex. Supplier_info
Functional Dependencies :
Emp_ID Emp_Name, Project_ID
Project_ID Project_Name
123 X
789 Z
Functional Dependencies :
Project_ID Project_Name