Basics of Relation Model
Basics of Relation Model
KCS-501
UNIT-2
RDBMS
• Most popular database system.
Film Attributes
4
Relation Instance
• Relation is a set of tuples
• Tuple ordering immaterial
• No duplicates
• Cardinality of relation = number of tuples
• All tuples in a relation have the same structure;
constructed from the same set of attributes
• Attributes named (=> ordering immaterial)
• Value of an attribute drawn from the attribute’s domain
• Degree of a relation = number of attributes
5
Relation Instance (Example)
Student
6
Differences between DBMS
and RDBMS
DBMS
• DBMS – In this case you would have to enter the tenants information for
each property (remember the tenant is the same, so time is wasted), as
well as the information about the property itself.
• The incorporation of „KEY‟ fields can help to save time and reduce the
chance of errors from occurring upon the inputting of information into the
database
Differences continued…..
• Enter RDBMS……
• There needs to be the introduction of 'KEY' fields which allows more immediate
access to what you are looking for. For example „tenant number' would be a key field
and this would lead to all the information about that tenant being in one place.
• Other 'KEY' fields could be introduced for other 'OBJECTS' (data files) of the
tenancies which leads to 'relationships' being formed. For example two of the objects
would be; tenant and property. The 'KEY' fields can be displayed by underlining them;
OBJECT FIELDS
• The idea of relationships comes from being able to input two or more „KEY‟ fields into
the system and being able to find out exactly what you want.
• So by creating 'KEY' fields you can find certain information by searching through that
'KEY' field. This means that the input of duplicate data is not required constantly and
you can find what you are looking for easier through objects and fields.
12 Rules….
• Rule 0: The system must qualify as relational, as a database, and as a
management system
• Rule 1: The information rule:
• Rule 2: The guaranteed access rule:
• Rule 3: Systematic treatment of null values:
• Rule 4: Active online catalogue based on the relational model:
• Rule 5: The comprehensive data sublanguage rule: (fix language SQL)
• Rule 6: The view updating rule: (account, sales, manager)
• Rule 7: High-level insert, update, and delete:
• Rule 8: Physical data independence: (structure, location, access)
• Rule 9: Logical data independence: (col/table add/break)
• Rule 10: Integrity independence:
• Rule 11: Distribution independence: (user unaware about distribution)
• Rule 12: The non-subversion rule: (no sublanguage)
Integrity Constraints
• Part of schema
• Restriction on state (or sequence of states) of
data base
• Enforced by DBMS
• Intra-relational - involve only one relation
• Part of relation schema
• e.g., all Ids are unique
• Inter-relational - involve several relations
• Part of relation schema or database schema
11
Types of Integrity Constraint
Entity Integrity Constraint
Entity integrity is concerned with ensuring that each
row of a table has a unique and non-null primary key
value; this is the same as saying that each row in a
table represents a single instance of the entity type
modeled by the table.
Example:
13
Referential Integrity Constraint
16
Key Constraint (con’t)
• Minimality - no subset of a key is a key
• (StudId, CrsCode) is not a key of Transcript
• Superkey - set of attributes containing key
• (Id, Name) is a superkey of Student
• Every relation has a key
• Relation can have several keys:
• primary key (Id in Student) – (cannot be null)
• candidate key ((Name, Address) in Student)
17
Domain Constraint
• Domain constraint ensures that the value associated
with an attribute is justifying its domain.
• Whenever we declare any relation to the database
while declaring its attribute we specify a particular
domain for each attribute.
• There are three constraints which we can study
under domain constraint.
• not null constraint
• default constraint
• check clause constraint
18
Specifying Domain Constraint
• The domain of an attribute specifies all the possible values that
attribute can hold.
• Declaring the domain of an attribute it acts as a constraint on that
attribute which specifies the possible values that it can take.
• create table Student
(Student_id varchar (5) , name varchar (20) not null,
depart_name varchar (20),
primary key (Student_id),
foreign key(depart_name) references Department);