Schema Diagram
Schema Diagram
Relational Model
• In this model, data is organised in two-dimensional tables and the
relationship is maintained by storing a common field.
• This model was introduced by E.F Codd in 1970, and since then it
has been the most widely used database model, in fact, we can say
the only database model used around the world.
• The basic structure of data in the relational model is tables. All the
information related to a particular type is stored in rows of that
table.
• Hence, tables are also known as relations in relational model.
• In the coming tutorials we will learn how to design tables, normalize
them to reduce data redundancy and how to use Structured Query
language to access data from tables.
Relational Model
Overview of Database Design Process
Steps - Database Design Process
1. Collecting and analyzing all the requirements
◼ Requirements collection and analysis
Database designers interview prospective database
users to understand and document their data
requirements
◼ Functional requirements
User defined operations that will be applied to the
database (retrievals and updates)
Steps - Database Design Process
2. Conceptual design
◼ Create a conceptual schema for the database using a high-level
conceptual data model
◼ Includes detailed descriptions of the entity types,
relationships and constraints
◼ Used as reference to ensure that all users’ data
requirements are met and that the requirements do not
conflict
◼ Modifications to the conceptual schema can be introduced if
some functional requirements cannot be specified using the
initial schema
Steps - Database Design Process
3. Logical design or data model mapping
◼ Actual implementation of the database using a commercial
DBMS
4. Physical design
◼ Specifying internal storage structures, indexes, access paths
and file organizations for the database files
◼ Application programs are designed and implemented
Instances and Schemas
• Instance – the actual content of the database at a particular point in
time
• Schema
• overall design of DB, schema changes are infrequent
• The Skeleton of the database is created by the attributes and this
skeleton is named as Schema.
• Schema is mentioning the logical constraints like table, primary key
etc.
• Schema does not represent the data type of the attributes.
Database Schema
• A database schema is a logical representation of data that shows how the
data in a database should be stored logically. It shows how the data is
organized and the relationship between the tables.
• Database schema contains table, field, views and relation between
different keys like primary key, foreign key.
• Data are stored in the form of files which is unstructured in nature which
makes accessing the data difficult. Thus to resolve the issue the data are
organized in structured way with the help of database schema.
• Database schema provides the organization of data and the relationship
between the stored data.
• Database schema defines a set of guidelines that control the database
along with that it provides information about the way of accessing and
modifying the data.
Entities and Attributes
• A real-world thing either living or non-living that is easily recognizable
and no recognizable. It is anything in the enterprise that is to be
represented in our database. It may be a physical thing or simply a
fact about the enterprise or an event that happens in the real world.
• An entity can be place, person, object, event or a concept, which
stores data in the database.
• Attributes are properties used to describe an entity.
• For example: If we consider a car entity, it can have its attributes as a
car's registration number, car's model, car's name, car's color, number
of seats that are there inside the car, etc. Below is the tabular
representation of the car entities.
Entities and Attributes
Entities and Attributes
• A specific entity will have a value for each of its attributes.
• For example a specific employee entity may have Name='John Smith',
SSN='123456789', Address ='731, Fondren, Houston, TX’,
Gender='M', BirthDate='09- JAN- 5 ‘
• Each attribute has a value set (data type) associated with it – e.g.
integer, string, subrange, enumerated type, …
Types of Attributes
• Simple (Atomic) versus Composite
• Single-valued versus Multi valued
• Stored versus Derived
• Null values
Composite vs. Simple Attributes
• Simple
• Each entity has a single atomic value for the
attribute. For example, SSN or Sex.
• Composite
• The attribute may be composed of several
components. For example:
• Address(Apt#, House#, Street, City, State, ZipCode,
Country)
• Name(FirstName, MiddleName, LastName).
• Composition may form a hierarchy where some
components are themselves composite.
Example - composite attribute
Single-valued vs. Multivalued Attributes
• Single-valued
• Attributes have a single value for a particular
entity
• Ex: Age
• Multi-valued
• An entity may have multiple values for that
attribute. For example, Color of a CAR or
PreviousDegrees of a STUDENT.
• Denoted as {Color} or {PreviousDegrees}.
Stored versus Derived Attributes
• Stored versus Derived attribute
• For a person entity the value of age can be
determined from the value of that person’s
Birth_date.
• The Age attribute is called a derived attribute
and is said to be derivable from the Birth_date
attribute which is called as stored attribute.
NULL values
• Null values – in some cases, a particular entity may not have an
applicable value for an attribute
• Ex: Apartment_number, College_degree
• A special value called NULL is created
• NULL can be used
• When not applicable
• Do not the value (unknown)
• Missing – it is known that attribute value exists but is missing
• Not known – it is not known whether the attribute value exists
Complex Attributes
• In general, composite and multi-valued attributes may be
nested arbitrarily to any number of levels, although this is
rare.
• For example, PreviousDegrees of a STUDENT is a composite
multi-valued attribute denoted by {PreviousDegrees (College,
Year, Degree, Field)}
• Multiple PreviousDegrees values can exist
• Each has four subcomponent attributes:
• College, Year, Degree, Field
SCHEMA DIAGRAM
• COMPANY DATABASE:
• EMPLOYEE (SSN, Name, Address, Gender, Salary, SuperSSN, DNo)
• DEPARTMENT (DNo, DName, MgrSSN, MgrStartDate)
• DLOCATION (DNo,DLoc)
• PROJECT (PNo, PName, PLocation, DNo)
• WORKS_ON (SSN, PNo, Hours)
SCHEMA DIAGRAM
SQL
Alter table
• ALTER TABLE student ADD CHECK (Age>=19);
• ALTER TABLE Persons ADD CONSTRAINT CHK_PersonAge CHECK
(Age>=18 AND City='Sandnes’);