Mod 1 DBMS
Mod 1 DBMS
MANAGEMENT SYSTEM
MODULE1
COURSE OUTCOMES
• Understand the basic concepts of data base system
• Develop appropriate databases by applying the various concepts of Relational
Model.
• A data mean known facts that can be recorded and that have
implicit meaning.
•
• A database can be of any size and complexity.
• For example, the list of names and addresses referred to earlier
may consist of only a few hundred records, each with a simple
structure.
• An example of a large commercial database is Amazon.com.
• A database may be generated and maintained manually or it
may be computerized.
• For example, a library card catalog is a database that may be
created and maintained manually.
• A computerized database may be created and maintained either
by a group of application programs written specifically for that
task or by a database management system.
• A database management system (DBMS) is a collection of
programs that enables users to create and maintain a database.
and
• Their job involves using large database • Maintaining the database system
everyday. environment .
• When multiple users share a large database, the type access operations must
be controlled.
• Multiple
users 🡪different levels of technical knowledge 🡪
DBMS should provide a variety of user interfaces.
• Ex:
• query languages 🡪 casual users,
• Database systems sometimes provide capabilities for defining deduction rules for
inferencing new information.
• ✔ The Hierarchical and Network Models were introduced in mid 1960s and dominated during the
70’s
• ✔ A bulk of the worldwide database processing still occurs using these models
• ✔ Relational model was originally introduced in 1970, was heavily researched and experimented
with in IBM Research and several universities
• Provide concepts that are close to the way many users perceive data
• use concepts such as entities, attributes, and relationships.
• Entities🡪 represents a real-world object or concept
• Attribute 🡪further describes an entity, such as the employee’s name or salary.
• Relationship 🡪association among 2 or more entities., for example, a works-on
relationship between an employee and a project.
• Entity-relationship model is a popular high level model conceptual data model.
2. Low-level or physical data models
• The top part of the figure refers to the various users of the
database environment and their interface
• The DDL compiler🡪 processes schema definitions,
specified in the DDL, 🡪and stores descriptions of the
schemas (meta-data) in the DBMS catalog
•SQL terms:
• table 🡪 relation
•Row 🡪 tuple
•Column🡪 attribute
Schema and Catalog Concepts in SQL
• Schema consists of tables and other constructs that belong to the same
database application
The basic data types available for attributes include numeric, character string,
bit string, Boolean, date, and time.
• Numeric
• Character-string
• Bit-string-
• Boolean
• Date
Basic Data Types
• The DATE data type has ten positions, and its components are YEAR,
MONTH, and DAY in the form YYYY-MM-DD
• The TIME data type has at least eight positions, with the components HOUR,
MINUTE, and SECOND in the form HH:MM:SS.
Data type Description
DOUBLE PRECISION(size, d)
CHAR(size) A FIXED length string (can contain letters, numbers, and special characters). The size parameter specifies the
column length in characters - can be from 0 to 255. Default is 1
VARCHAR(size) A VARIABLE length string (can contain letters, numbers, and special characters). The size parameter specifies
the maximum string length in characters - can be from 0 to 65535
BIT(size) A bit-value type. The number of bits per value is specified in size. The size parameter can hold a value
from 1 to 64. The default value for size is 1.
DATE A date. Format: YYYY-MM-DD. The supported range is from '1000-01-01' to '9999-12-31'
DATETIME(fsp) A date and time combination. Format: YYYY-MM-DD hh:mm:ss. The supported range is from '1000-01-01
00:00:00' to '9999-12-31 23:59:59'. Adding DEFAULT and ON UPDATE in the column definition to get
automatic initialization and updating to the current date and time
TIME(fsp) A time. Format: hh:mm:ss. The supported range is from '-838:59:59' to '838:59:59'
TIMESTAMP(fsp) A timestamp. TIMESTAMP values are stored as the number of seconds since the Unix epoch ('1970-01-01
00:00:00' UTC). Format: YYYY-MM-DD hh:mm:ss. The supported range is from '1970-01-01 00:00:01' UTC to
'2038-01-09 03:14:07' UTC. Automatic initialization and updating to the current date and time can be
specified using DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP in the column
definition
Specifying Constraints in SQL
These include
• key and referential integrity constraints,
• restrictions on attribute domains and NULLs, and
• constraints on individual tuples within a relation using the CHECK clause.
The following constraints are commonly used in SQL:
Dnumber INT NOT NULL CHECK (Dnumber > 0 AND Dnumber < 21);
Orders
Persons OrderID OrderNumber PersonID
PersonID LastName FirstName Age
1 77895 3
1 Hansen Ola 30
2 44678 3
4 24562 1
3 Pettersen Kari 20
SELECT-FROM-WHERE
SELECT <attribute list>
FROM <table list>
WHERE <condition>;
Where,
<attribute list> is a list of attribute names whose values are to be retrieved
by the query
<table list> is a list of the relation names required to process the query
<condition> is a conditional (Boolean) expression that identifies the tuples to
be retrieved by the query
EXAMPLES
1. Retrieve the birth date and address of the employee(s) whose name is
‘John B. Smith’.
1. Retrieve the birth date and address of the employee(s) whose name is
‘John B. Smith’.
Each tuple in the result will be a combination of one project, one department,
and one employee that satisfies the join conditions.
Ambiguous Attribute Names, Aliasing,
Renaming, and Tuple Variables
• In SQL, same name can be used for two or more attributes as long
as the attributes are in different relations.
• If this is the case, and a multi-table query refers to two or more
attributes with the same name, we must qualify the attribute name
with the relation name to prevent ambiguity.
• This is done by prefixing the relation name to the attribute name
and separating the two by a period.
Examples
Retrieve the name and address of all Students who work for the ‘CSE’
department
STUDENT
Name USN Bdate Address Sex CR_USN DNo
DEPARTMENT
Name DNo CR_USN
Examples
Retrieve the name and address of all Students who work for the ‘CSE’
department
STUDENT
Name USN Bdate Address Sex CR_USN DNo
DEPARTMENT
Name DNo CR_USN
Example:
Retrieve all employees whose address is in Houston, Texas
Retrieve all employees whose address is in Houston, Texas
SELECT *
FROM EMPLOYEE
WHERE (Salary BETWEEN 30000 AND 40000) AND Dno = 5;
UPDATE PROJECT
SET Plocation = ‘Bellaire’, Dnum = 5
WHERE Pnumber=10;
CHAPTER 3
• Entity, which is a thing or object in the real world with an independent existence.
• ✔ An entity may be an
• - object with a physical existence (for example, a particular person, car, house, or
employee)
• or
• - object with a conceptual existence (for instance, a company, a job, or a
university course)
Single-valued Multivalued
• Have a single value for a • An entity having multiple
particular entity . values for that attribute
• Entity Types
• A collection (or set) of entities that have the same attributes .
• Ex: STUDENT
Entity set or Entity collection
• The collection of all entities of a particular entity type in the database at any
point in time
Key Attributes of an Entity Type
•
• The Name attribute is a key of the COMPANY entity type in because no two
companies are allowed to have the same name
• The set of values that may be assigned to that attribute for each
individual entity
• Entity types that do not have key attributes of their own are called weak entity types
• In contrast, regular entity types that do have a key attribute—are called strong entity
types
• We call this other entity type the identifying or owner entity type, and we call the
relationship type that relates a weak entity type to its owner the identifying relationship of
the weak entity type
• A weak entity type normally has a partial key, which is
the attribute that can uniquely identify weak entities
that are related to the same owner entity
• Composite attribute:
ER Diagram
•Consider the ER diagram shown in the figure for
part of a BANK database . Each bank can have
multiple branches, and each branches can have
multiple accounts and loans.
• Sol : Yes.
• Weak Entity Type:
• Partial Key: Branch No
• Identifying Relationship: Branches
• Constraint of the identifying relationship:
i) The weak entity set must have total participation the
identifying relationship set , Branches
• For example, consider the entity types CAR and TRUCK shown in below figure . Because
they have several common attributes, they can be generalized into the entity type
VEHICLE, as shown in Figure.
• Both CAR and TRUCK are now subclasses of the generalized superclass VEHICLE. We
use the term generalization to refer to the process of defining a generalized entity type
from the given entity types.