Professional Documents
Culture Documents
2014
DIRS MANUAL
Introduction
Database: it is a collection of related data, where data is a fact that can be recorded.
DBMS (database management system): is a collection of programs that enables the user to create and
manipulate the data.
Schema: The description of database is called database schema. Which is specified during the
database design and diagram to represent schema is called schema diagram.
Page 1
2014
EMPLOYEE
MANAGES
DEPARTMENT
In above diagram EMPLOYEE and DEPARTMENT are Entity and MANAGES are
relationship between those entity.
Types of Attributes
1. Composite vs simple attributes
Composite attributes can be divided into smaller subpart, which represents the more
basic attributes with independent meanings.
Example is Address of an person, it can be subdivided into street_address, city, State,
and Zip etc.
Simple attributes are non divisible. Example University Seat Number of student.
2. Single valued vs Multi valued
Most of attributes have single value for entity are called single valued.
Example Age of person
Multi valued attribute may have lower and upper bounds to constrain the number of
values allowed for each individual entity.
Example College Degree
Cardinality of Relationship
While creating relationship between two entities, we may often need to face the cardinality
problem. This simply means that how many entities of the first set are related to how many
entities of the second set. Cardinality can be of the following three types.
Computer Engineering Dept
Page 2
2014
One-to-One
Only one entity of the first set is related to only one entity of the second set. E.g. A teacher
teaches a student. Only one teacher is teaching only one student. This can be expressed in the
following diagram as:
One-to-Many
Only one entity of the first set is related to multiple entities of the second set. E.g. A teacher
teaches students. Only one teacher is teaching many students. This can be expressed in the
following diagram as:
Many-to-One
Multiple entities of the first set are related to multiple entities of the second set. E.g.Teachers
teach a student. Many teachers are teaching only one student. This can be expressed in the
following diagram as:
Many-to-Many
Multiple entities of the first set is related to multiple entities of the second set. E.g.Teachers
teach students. In any school or college many teachers are teaching many students. This can
be considered as a two way one-to-many relationship. This can be expressed in the following
diagram as:
Page 3
2014
Super Key or Candidate Key: It is such an attribute of a table that can uniquely identify a
row in a table. Generally they contain unique values and can never contain NULL values.
There can be more than one super key or candidate key in a table e.g. within a STUDENT
table Roll and Mobile No. can both serve to uniquely identify a student.
Primary Key: It is one of the candidate keys that are chosen to be the identifying key for the
entire table. E.g. although there are two candidate keys in the STUDENT table, the college
would obviously use Roll as the primary key of the table.
Alternate Key: This is the candidate key which is not chosen as the primary key of the table.
They are named so because although not the primary key, they can still identify a row.
Composite Key: Sometimes one key is not enough to uniquely identify a row. E.g. in a single
class Roll is enough to find a student, but in the entire school, merely searching by the Roll is
not enough, because there could be 10 classes in the school and each one of them may contain
a certain roll no 5. To uniquely identify the student we have to say something like class VII,
roll no 5. So, a combination of two or more attributes is combined to create a unique
combination of values, such as Class + Roll.
Foreign Key: Sometimes we may have to work with an attribute that does not have a primary
key of its own. To identify its rows, we have to use the primary attribute of a related table.
Such a copy of another related tables primary key is called foreign key.
Strong and Weak Entity
Based on the concept of foreign key, there may arise a situation when we have to relate an
entity having a primary key of its own and an entity not having a primary key of its own. In
such a case, the entity having its own primary key is called a strong entity and the entity not
having its own primary key is called a weak entity. Whenever we need to relate a strong and a
weak entity together, the ERD would change just a little.
Say, for example, we have a statement A Student lives in a Home. STUDENT is obviously a
strong entity having a primary key Roll. But HOME may not have a unique primary key, as
its only attribute Address may be shared by many homes (what if it is a housing estate?).
HOME is a weak entity in this case.
The ERD of this statement would be like the following
As you can see, the weak entity itself and the relationship linking a strong and weak entity
must have double border.
Page 4
2014
Page 5
2014
SECRETARY
TECHNICIAN
(class or superclass)
ENGINEER
(subclass)
Super class and subclass has a relationship called as IS A relationship. i.e. we called
ENGINEER is a EMPLOYEE.
Specialization is a process of defining a set of subclass of an entity type this entity type
called super-class of a specialization.
The set of subclasses that form a specialization defined on the basis of some
distinguishing characteristics of the entities in the super class.
Specialization Process allows us to do following
Generalization
The process of generalizing entities, where the generalized entities contain the properties of
all the generalized entities is called Generalization. In generalization, a number of entities are
brought together into one generalized entity based on their similar characteristics. For an
example, pigeon, house sparrow, crow and dove all can be generalized as Birds.
Page 6
2014
Generalization
Specialization
Specialization is a process, which is opposite to generalization, as mentioned above. In
specialization, a group of entities is divided into sub-groups based on their characteristics.
Take a group Person for example. A person has name, date of birth, gender etc. These
properties are common in all persons, human beings. But in a company, a person can be
identified as employee, employer, customer or vendor based on what role do they play in
company.
Page 7
2014
Definition of Keys
1. Primary Key
a. It is a key whose values are used to identify tuples in a relation.
b. It will be underlined in relational schema.
c. Value of primary key cannot be NULL.
2. Foreign Key
a. It is a key which is a primary key in our relation R1(table) and used in another
relation R2 (table)
R1
SSN
NAME
..
R2
CourseNO CName
SSN
In above example ssn and courseno are primary keys as they identify each row in table
uniquely and SSN in table R2 is foreign key.
Computer Engineering Dept
Page 8
2014
Constraints
Every relation has some conditions that must hold for it to be a valid relation. These
conditions are called Relational Integrity Constraints. There are three main integrity
constraints.
Key Constraints
Domain constraints
KEY CONSTRAINTS:
A primary key serves as the unique identifier for rows in the table.
The syntax of the primary key constraint (following the Constraint keyword and the
constraint name, if they're specified) is
For a table with a primary key constraint, blocks any attempt to insert or update a
row that would cause two rows in the same table to have identical value(s) for
their primary key column(s).
A table definition can have no more than one primary key constraint.
DOMAIN CONSTRAINTS:
Domain integrity means the definition of a valid set of values for an attribute. You define
- data type,
- lenght or size
- is null value allowed
- is the value unique or not
for an attribute.
You may also define the default value, the range (values in between) and/or specific values
for the attribute. These definitions ensure that a specific attribute will have a right and proper
value in the database.
Page 9
2014
Relational algebra
Relational algebra is a procedural query language, which takes instances of relations as input
and yields instances of relations as output. It uses operators to perform queries. An operator
can be either unary or binary. They accept relations as their input and yields relations as their
output. Relational algebra is performed recursively on a relation and intermediate results are
also considered relations.
Fundamental operations of Relational algebra:
Select
Project
Union
Set different
Cartesian product
Rename
subject="database"(Books)
Output : Selects tuples from books where subject is 'database'.
Page 10
2014
r s = { t | t r or t s}
Notion: r U s
Where r and s are either database relations or relation result set (temporary relation).
For a union operation to be valid, the following conditions must hold:
Page 11
2014
r s = { q t | q r and t s}
Set intersection
Assignment
Natural join
Page 12
2014
Mapping Entity
An entity is a real world object with some attributes.
Mapping Process (Algorithm):
Entity's attributes should become fields of tables with their respective data types.
Mapping relationship
A relationship is association among entities.
Mapping process (Algorithm):
Page 13
2014
Add the primary keys of all participating Entities as fields of table with their respective data
types.
Declare a primary key composing all the primary keys of participating entities.
Page 14
Add primary keys of higher level entities in the table of lower level entities
Declare primary key of higher level table the primary key for lower level table
2014
Dnum
DEPARTMENT
Dno
Dname
Dlocation
Mgr_Joining Date
Mrg_Ssn
PROJECT
Pno
Pname
Plocation
Dnum
WORKS_ON
WN_No
ESsn
Pnum
Hrs
DEPENDENT
Depen_No Name
Gender
Bod
Relation DSsn
Page 15
2014
Here's what SQL Server Management Studio looks like once you've connected (and opened a
new query):
Page 16
2014
Lets use SQL Scripting for Creating Database and steps are as follows:
Step1: Goto start menu -> all programs -> click on Microsoft Sql Server 2008 -> click on Sql
server management studio
Then following screen appears
Then click on connect, dont change anything on screen. Now you will get into sql server, to
create run your sql query we need query window so click on option called New query
1. Then click on ! Execute symbol or Press F5. And also save your query by using file
menu-> save as option for saving the query.
2. Now from dropdown in above window select your database and if your database is
not available then click on Databases side menu and click on refresh option.
Page 17
2014
1. First select your database from dropdown then type the create table command for
Employee with required data type and constraints.
2. Now select the query that need to be executed and click on
refresh your database, you can check your table created.
Similarly you can execute all the commands using query window.
Page 18