week 1 (handout 1)
DESCRIPTION
TRANSCRIPT
Advance Database Systems
Review of Theory of Databases *Property of STI Page 1 of 12
TOPIC TITLE: Review of Theory of Databases SPECIFIC OBJECTIVES: At the end of the topic session, the students are expected to: Cognitive:
1. Recall basic database concepts. Affective:
1. Listen to others with respect. 2. Actively participate in class discussions.
MATERIALS/EQUIPMENT:
o topic slides o OHP
TOPIC PREPARATION:
o Review the Theory of Databases course. o The instructor must explain briefly the different components of
the DBMS environment. o The instructor explains briefly the different entity relationships.
TOPIC PRESENTATION:
The topic discusses the database concepts. This will be the suggested flow of discussion for the course topic:
1. Start the class by defining database. Explain it further by giving additional examples.
2. Define schema and differentiate it from database. Provide additional examples of schema.
3. Define database systems and explain how it is used to interact the application programs with database.
4. Enumerate the components of DBMS Environment. Provide a brief explanation about each component.
5. Explain the different facilities provided by DBMS. 6. Enumerate and explain the different entity relationships. 7. Define relational database and provide examples that can
support it. 8. Discuss the other database concepts such as relation,
attribute, domain and primary key and provide examples of each.
9. Define SQL and enumerate the main categories of SQL commands.
10. Discuss further each main category of SQL commands and enumerate the commands used.
11. Define integrity constraints and explain its different types. 12. Define normalization and discuss the different normal forms. 13. Discuss the advantages of normalization.
Advance Database Systems
Review of Theory of Databases *Property of STI Page 2 of 12
Review of Database Concepts Page 1 of 17
Advance Database Systems
* Property of STIPage 1 of 17
Review of Theory of Databases
Review of Database Concepts
� What is a Database?
� A database is a collection of
logically related data. Example: Personal information such as name, address, birthday and gender
� What is a Schema?
� A schema or a database schema
is the over-all design of a
database.
� What is a Database System?
� A database system is an
automated system that enables
users to define, create,
maintain and control access to
the database.
Review of Database Concepts Page 2 of 17
Advance Database Systems
* Property of STIPage 2 of 17
Review of Theory of Databases
� What are the components of the DBMS Environment?
� Data
� Hardware
� Software
� End Users
� Procedure
Review of Database Concepts
Review of Database Concepts What is a Database? A database is a collection of logically related data. It is a collection of persistent data that is used by the application systems and that is managed by a database management system. Personal information such as name, address, birthday and gender can be considered as a database. The large files of banks, health care companies, insurance companies, telephone companies, or student records in schools can be considered databases. These databases contain data about addresses, account balances, patient history, car registration plates, weights of vehicles, school grades and so on. For example, the school where you study has its own databases and these are used to store student related data. What is a Schema? A schema or a database schema is the over-all design of a database. It is a complete description of the content and structures of the fields, records and data relationships for the database. A schema is associated with one particular database username. This username is called the schema owner. In a database, it can have one or multiple schemas. Any user who creates an object has just created its own schema. What is a Database System? A database system is an automated system that enables users to define, create, maintain and control access to the database. It is a software system that interacts with the application programs and the database. This system is called the database-management system (DBMS). A DBMS enables users to process data stored in a database. Without it, it is impossible to look at data or to update or delete obsolete data, in the database. Some of the examples of DBMS include Microsoft Access, FileMaker, DB2, MySQL, Adaptive SQL Anywhere and Oracle. What are the components of the DBMS Environment?
• Data The data stored in the database is integrated and shared. It is said to be integrated because data redundancy or the repetition of data within the files must be minimized or completely eliminated. It is also shared because it can be accessed by more than one user.
• Hardware The hardware component is used to store the database itself and the software applications that are used to create and maintain the database. The hardware and software components complement each other.
• Software The software components refer to the interface layer between the users and the physical database. All requests from users to access the database are handled by the software layer.
• End Users The end users refer to the people whose tasks require access to the database system for querying, updating and generating useful reports.
Advance Database Systems
Review of Theory of Databases *Property of STI Page 3 of 12
Review of Database Concepts Page 3 of 17
Advance Database Systems
* Property of STIPage 3 of 17
Review of Theory of Databases
Review of Database Concepts
� What are the different facilities that DBMS provide?
� Users can define the database
through a Data Definition
Language (DDL).
� Users can manipulate data
through a Data Manipulation
Language (DML).
� DBMS can provide security
system.
� DBMS can provide an integrity
system.
� DBMS can provide a concurrency
control system.
� DBMS can provide a recovery
control system.
Review of Database Concepts Page 4 of 17
Advance Database Systems
* Property of STIPage 4 of 17
Review of Theory of Databases
Review of Database Concepts
� What are the different entity relationships?
� One-to-One
Table A Table B
A1
A2
A3
A4
B1
B2
B3
B4
What are the different facilities that DBMS provide?
• Users can define the database through a Data Definition Language (DDL). The DDL allows users to specify the structures, data types and constraints on the data to be stored on the database. It is used to define the parts of the database that are required.
• Users can manipulate data through a Data Manipulation Language (DML). The DML is a special language that allows users to insert, update, delete and retrieve data from the database. In other words, DML is used to manipulate the data.
• DBMS can provide security and recovery control system. The DBMS prevents unauthorized users accessing the database. As we all know, data is data is valuable and must be stored safely. That means protection of the stored data not only from malicious human activities, such as unauthorized logins, accidental information deletions or modifications and so on, but also recovering from hardware failures and natural disasters.
• DBMS can provide an integrity system. This means that the DBMS has to make sure that database data always satisfies the rules that apply in the real world. For example, the case of an employee who is allowed to work for one department only. It should never be possible for that particular employee to be registered as working for two or more departments. In addition, integrity means that two different pieces of database data do not contradict one another.
• DBMS can provide a concurrency control system. DBMS allows shared access of the database. It is important that information stored in a database must be accessible to many users simultaneously at different levels of security. For example, if two users try to change the same piece of information at the same time, the result can lead to data corruption. This type of situation has to be handled appropriately by internal database mechanisms.
What are the different entity relationships?
• One-to-One In the one-to-one relationship, an entity in table A is associated with at most one entity in table B and an entity in table B is associated with at most one entity in table A. The diagram in Figure 1.1 illustrates this relationship.
Advance Database Systems
Review of Theory of Databases *Property of STI Page 4 of 12
Review of Database Concepts Page 5 of 17
Advance Database Systems
* Property of STIPage 5 of 17
Review of Theory of Databases
Review of Database Concepts
� What are the different entity relationships?
� One-to-Many
Review of Database Concepts Page 6 of 17
Advance Database Systems
* Property of STIPage 6 of 17
Review of Theory of Databases
Review of Database Concepts
� What are the different entity relationships?
� Many-to-One
Figure 1.1 One-to-One Entity Relationships
• One-to-Many In the one-to-many relationship, an entity in Table A is associated with any number of entities in Table B. On the other hand, an entity in Table B can only be associated with at most one entity in A. The diagram in Figure 1.2 illustrates this relationship.
Figure 1.2 One-to-Many Entity Relationships
• Many-to-One In the many-to-one relationship, an entity in Table A is associated with at most one entity in Table B. On the other hand, an entity in Table B can be associated with any number of entities in Table A. The diagram in Figure 1.3 illustrates this relationship.
Figure 1.3 Many-to-One Entity Relationships
Advance Database Systems
Review of Theory of Databases *Property of STI Page 5 of 12
Review of Database Concepts Page 7 of 17
Advance Database Systems
* Property of STIPage 7 of 17
Review of Theory of Databases
Review of Database Concepts
� What are the different entity relationships?
� Many-to-Many
Table A Table B
A1
A2
A3
A4
B1
B2
B3
B4
Review of Database Concepts Page 8 of 17
Advance Database Systems
* Property of STIPage 8 of 17
Review of Theory of Databases
Review of Database Concepts
� What is relational database?
� A relational database is divided
into logical units called table
which is composed of rows and
columns of data.
• Many-to-Many In the many-to-many relationship, an entity in Table A is associated with any number of entities in Table B. On the other hand, an entity in Table B can be associated with any number of entities in Table A. The diagram in Figure 1.4 illustrates this relationship.
Figure 1.4 Many-to-Many Entity Relationships
What is relational database? A relational database is divided into logical units called table which is composed of rows and columns of data. In a relational database, the rows of data contain data that describe a particular real-world entity such as a product. The columns of data contain in a particular characteristic of real-world entity being describes by the rows of data. The rows of data are called records or tuples. On the other hand, the columns of data are called fields or attributes. Table 1.1 is an example of a relational table.
Table 1.1 Product Table
Advance Database Systems
Review of Theory of Databases *Property of STI Page 6 of 12
Review of Database Concepts Page 9 of 17
Advance Database Systems
* Property of STIPage 9 of 17
Review of Theory of Databases
Review of Database Concepts
� What is a relation?
� A relation is composed of rows
and columns of data.
� What is an attribute?
� In relational database, the table
columns correspond to
attributes.
� What is a domain?
� A domain refers to a set of valid
atomic values for a given
attribute.
� What is a primary key?
� A primary key refers to an
attribute or field that serves as
a unique identifier for a
particular record within a
relation.
Review of Database Concepts Page 10 of 17
Advance Database Systems
* Property of STIPage 10 of 17
Review of Theory of Databases
Review of Database Concepts
� What is SQL?
� Structured Query Language (SQL)
is the standard language used to
define, query, update and
maintain relational databases.
� Main categories of SQL
commands are as follows:
• Data Definition Language
(DDL)
• Data Manipulation Language
(DML)
• Data Query Language (DQL)
• Data Control Language (DCL)
• Transactional control
commands
What is a relation? A relation is a table composed of rows and columns of data. The figure above is an example of a relation. Names are given to relations for purposes of identification. What is an attribute? In relational database, the table columns correspond to attributes. An attribute is a named column of a relation. In the sample table above, the attributes are id, name, description, size, color, quantity and unit price. What is a domain? A domain refers to a set of valid atomic values for a given attribute. Atomic means that the attribute can no longer be divided into smaller units. In the table above, possible atomic data are id, description, size, color, quantity and unit_price. What is a primary key? A primary key refers to an attribute or field that serves as a unique identifier for a particular record within a relation. It is used to locate a record within a relation. Another use of primary key is that it is needed for foreign key support. In the table above, the primary key is the id. What is SQL? Structured Query Language (SQL) is the standard language used to define, query, update and maintain relational databases. It is a relational database language that is used to create and define the structure of the database. It is used to perform manipulations on the database and control the security in the database. Using Table 1.1, h is a list of statements that can be formulated with SQL:
• Insert a new record in the product table.
• Delete all the product data for product Shorts.
• Show the quantity of product Tee Shirts.
• Show the quantity of products with unit price greater than 15. There are main categories of SQL commands as follows:
• Data Definition Language (DDL)
• Data Manipulation Language (DML)
• Data Query Language (DQL)
• Data Control Language (DCL)
• Transactional control commands
Advance Database Systems
Review of Theory of Databases *Property of STI Page 7 of 12
Review of Database Concepts Page 11 of 17
Advance Database Systems
* Property of STIPage 11 of 17
Review of Theory of Databases
Review of Database Concepts
� What is Data Definition Language (DDL)?
� The DDL allows the user to
create and restructure database
objects.
� Some of the most fundamental
DDL commands are:
• CREATE TABLE
• ALTER TABLE
• DROP TABLE
• CREATE INDEX
• ALTER INDEX
• DROP INDEX
• CREATE VIEW
• DROP VIEW
What is Data Definition Language (DDL)? The DDL allows the user to create and restructure database objects, such as the creation or the deletion of a table. Some of the most fundamental DDL commands include the following:
• CREATE TABLE Syntax:
CREATE TABLE name_of_table
(
name_of_column column_datatype
)
Example:
CREATE TABLE MRTSched
(
sched_id varchar(10),
start_location varchar(75),
destination varchar(75),
departs datetime,
arrives datetime
);
• ALTER TABLE
Syntax: ALTER TABLE name_of_table
ADD name_of_field data_type
Example:
ALTER TABLE MRTSched
ADD runs_at_weekend char(1);
• DROP TABLE
Syntax: DROP TABLE name_of_table
Example:
DROP TABLE MRTSched
• CREATE INDEX
Syntax: CREATE INDEX <index_name>
ON <table_name> (<column_names>)
Example:
CREATE INDEX schedule_index
ON MRTSched (departs, arrive);
• DROP INDEX
Syntax: DROP INDEX <index_name>
Example:
DROP INDEX schedule_index
• CREATE VIEW
Advance Database Systems
Review of Theory of Databases *Property of STI Page 8 of 12
Review of Database Concepts Page 12 of 17
Advance Database Systems
* Property of STIPage 12 of 17
Review of Theory of Databases
Review of Database Concepts
� What is Data Control Language (DML)?
� DML allows the user to
manipulate data within objects
of a relational database.
� The three basic DML commands
are
• INSERT
• UPDATE
• DELETE
� What is Data Query Language (DQL)?
� DQL allows the user to select a
data or a group of data.
� The base command is SELECT
Syntax:
CREATE VIEW <view_name>
AS SELECT column1, column2,.....columnx FROM
table_name
Example:
CREATE VIEW Schedview
AS SELECT start_location, destination,
departs, arrives FROM MRTSched
• DROP VIEW
Syntax: DROP VIEW <view_name>
Example:
DROP VIEW SchedView
What is Data Control Language (DML)? DML allows the user to manipulate data within objects of a relational database. The three basic DML commands are
• INSERT
Syntax: INSERT INTO table_name (column_names) VALUES
(data_values)
Example:
INSERT INTO Category (CategoryId, Category)
VALUES (1, ‘Thriller’);
INSERT INTO Category (CategoryId, Category)
VALUES (2, ‘Romance’);
INSERT INTO Category (CategoryId, Category)
VALUES (3, ‘Horror’);
INSERT INTO Category (CategoryId, Category)
VALUES (4, ‘War’);
INSERT INTO Category (CategoryId, Category)
VALUES (5, ‘Sci-fi’);
• UPDATE
Syntax: UPDATE table_name
SET column_name = value
WHERE condition
Example:
UPDATE Category
SET Category = “War Crime”
WHERE Category = “War”
• DELETE
Syntax: DELETE FROM table_name [WHERE condition]
Example:
Advance Database Systems
Review of Theory of Databases *Property of STI Page 9 of 12
Review of Database Concepts Page 13 of 17
Advance Database Systems
* Property of STIPage 13 of 17
Review of Theory of Databases
Review of Database Concepts
� What is Data Control Language (DCL)?
� The DCL allows the user to
create objects related to user
access and also control the
distribution of privileges among
users.
� Some data control commands
are as follows:
• ALTER PASSWORD
• GRANT
• REVOKE
• CREATE SYNONYM
Review of Database Concepts Page 14 of 17
Advance Database Systems
* Property of STIPage 14 of 17
Review of Theory of Databases
Review of Database Concepts
� What is Transactional Control Commands (TCC)?
� The TCC allow the user to
manage database transactions.
� Some commands are as follows:
• COMMIT
• ROLLBACK
• SAVEPOINT
• SET TRANSACTION
DELETE FROM Category
DELETE FROM Category WHERE CategoryId = 1
What is Data Query Language (DQL)? DQL allows the user to select a data or a group of data. It is the most concentrated focus of SQL for modern relational database users. The base command is SELECT
Syntax: SELECT column1, column2,.....columnx FROM
table_name
Example: SELECT start_location, destination, departs,
arrives FROM MRTSched What is Data Control Language (DCL)? The DCL allows the user to create objects related to user access and also control the distribution of privileges among users. Some data control commands are as follows:
• GRANT
Syntax: GRANT ALL [PRIVILEGES] |
<system privilege,...> |
<role> TO <user> | <role>
Note: the syntax may vary from one RDBMS to another. Example:
SELECT start_location, destination, departs,
arrives FROM MRTSched
• REVOKE What is Transactional Control Commands (TCC)? The TCC allow the user to manage database transactions. These are the commands used to specify the start and end of transactions. It is also used in data locking and concurrency control.
• COMMIT
Syntax: COMMIT The commit operation is used to indicate the completion of a transaction. All updates performed by a transaction on the database can now be made permanent.
• ROLLBACK
Syntax: ROLLBACK The rollback operation is used to indicate the cancellation of a transaction. It sends a signal on the transaction manager which states that a transaction cannot be completed.
Advance Database Systems
Review of Theory of Databases *Property of STI Page 10 of 12
Review of Database Concepts Page 15 of 17
Advance Database Systems
* Property of STIPage 15 of 17
Review of Theory of Databases
Review of Database Concepts
� What is Integrity Constraint?
� Integrity constraints are used to
ensure accuracy and consistency
of data in a relational database.
� What are the types of integrity constraints?
� Primary key Constraints
� Unique Constraints
� Foreign Key Constraints
� Not Null Constraints
� Check Constraints
What is Integrity Constraint? Integrity constraints are used to ensure accuracy and consistency of data in a relational database. Data integrity means consistency and correctness of the data. Data is consistent if individual items do not contradict one another. Data is correct if it satisfies all relevant rules or semantics. For example, if in the example database the total number of sets in a match is greater than ten, this data item is incorrect. Integrity constraints are the rules with which the contents of a database must comply at all times and they describe which updates to the database are permitted. What are the types of integrity constraints?
• Primary key Constraints
PRIMARY KEY is the most important and most commonly used constraint. It provides a link between tables. For example, StudentId is the primary key in the Student Record database’s Student table and is linked to the Registration and Assessment tables. In order for the relationship to work, the primary key must uniquely identify a record, which means that you can include only unique values and no NULLs. In fact, the PRIMARY KEY constraint is essentially a combination of the UNIQUE and NOT NULL constraints. Whereas you can have more than one UNIQUE or CHECK constraint on a table, only one PRIMARY KEY constraint per table is allowed.
• Unique Constraints
The UNIQUE constraint prevents two records from having identical values in a particular column. In the Student table, for example, you might want to prevent two or more student from having identical email addresses.
• Foreign Key Constraints
Foreign keys are columns that refer to primary keys in another table. Primary and foreign keys establish relations between data in different tables.
• Not Null Constraints
This constraint ensures that the column must have a value or else the record cannot be inserted.
• Check Constraints
The CHECK constraint enables a condition to check the value being entered into a record. If the condition evaluates to false, the record violates the constraint and isn’t entered into the table.
Advance Database Systems
Review of Theory of Databases *Property of STI Page 11 of 12
Review of Database Concepts Page 16 of 17
Advance Database Systems
* Property of STIPage 16 of 17
Review of Theory of Databases
Review of Database Concepts
� What is normalization?
� Normalization is a process of
reducing data redundancy in a
database.
� The different levels of normal
forms:
• First Normal Form (1NF)
• Second Normal Form (2NF)
• Third Normal Form (3NF)
What is normalization? Normalization is a process of reducing data redundancy in a database. It is a mechanism that is used when designing and redesigning a database. It is also a process or set of guidelines used to optimally design a database to reduce redundant data. The different levels of normal forms, each one being a refinement of the preceding one are:
• First Normal Form (1NF) The first normal form provides the foundation for the second and third forms. The first form includes the following guidelines:
� Each attribute of a column must contain only one value. � Each column in a relation must contain the same number
of values. � Each column in a relation must be different.
• Second Normal Form (2NF)
First normal form requires every table to have a primary key. This primary key can consist of one or more columns. The primary key is the unique identifier for that record, and second normal form states that there must be no partial dependences of any of the columns on the primary key. For example, assume in a Student Record database, you decide to store a list of subjects and faculty who taught in them. The data being stored is subject ID, subject name, units, faculty ID, faculty name and department. This example is in first normal form, in that it obeys all the rules of first normal form. In this table, the primary key consists of SubjectId and FacultyId. However, the example is not in second normal form because there are partial dependencies of primary keys and columns. To make this table comply with second normal form, you need to separate the columns into three tables. First, create a table to store the subject detail. Next, create a table to store details of each faculty. Finally, create a third table storing just SubjectId and FacultyId to keep track of which faculty taught in which subject.
• Third Normal Form (3NF)
A table is said to be in the third normal form when the following conditions are met:
� It is in second normal form. � All nonprimary fields are dependent on the primary key.
The dependency of nonprimary fields is between the data. For example, street name, barangay and city are unbreakably bound to the zip code. For example, Ayala Ave, Legaspi Village, Makati has an assigned and unique zip code. If you mail a letter, in theory supplying the street address and zip code is enough for someone to locate the house.
Advance Database Systems
Review of Theory of Databases *Property of STI Page 12 of 12
Review of Database Concepts Page 17 of 17
Advance Database Systems
* Property of STIPage 17 of 17
Review of Theory of Databases
Review of Database Concepts
� What are the advantages of normalization?
� Better overall database
organization
� Reduction of redundant data
� Data consistency within the
database
� Flexible database design
� Efficient database security
handling
� Enforces concept of referential
integrity
What are the advantages of normalization? Some of the major benefits of normalization include the following:
• Better overall database organization
• Reduction of redundant data
• Data consistency within the database
• Flexible database design
• Efficient database security handling
• Enforces concept of referential integrity [Review of Database Concepts, Pages 1 – 17 of 17]
GENERALIZATION:
o A database is a shared collection of logically related data. o A schema or a database schema is the over-all design of a
database. o A relational database is divided into logical units called table
which is composed of rows and columns of data. o Structured Query Language (SQL) is the standard language
used to define, query, update and maintain relational databases.
o Normalization is a process of reducing data redundancy in a database.
REFERENCES:
o Ramez Elmasri and Shamkant Navathe. Fundamentals of
Database Systems. Pearson Education, fourth edition, 2007. o Database Management Systems by Raghu Ramakrishnan and
Johannes Gehrke, McGraw-Hill, 3rd edition o An Introduction to Database Systems by C. J. Date, Addison
Wesley, 7th edition o Database Management Systems", Raghu Ramakrishnan,
Johannes Gehrke, McGraw-Hill Science, ISBN 0072465638, 2002
o R. Elmasri and S.B. Navathe, fundamentals of Database System, Addison Wesley Co., 2006
Advance Database Systems
Review of Theory of Databases *Property of STI Page 1 of 12
TOPIC TITLE: Review of Theory of Databases SPECIFIC OBJECTIVES: At the end of the topic session, the students are expected to: Cognitive:
1. Recall basic database concepts. Affective:
1. Listen to others with respect. 2. Actively participate in class discussions.
MATERIALS/EQUIPMENT:
o topic slides o OHP
TOPIC PREPARATION:
o Review the Theory of Databases course. o The instructor must explain briefly the different components of
the DBMS environment. o The instructor explains briefly the different entity relationships.
TOPIC PRESENTATION:
The topic discusses the database concepts. This will be the suggested flow of discussion for the course topic:
1. Start the class by defining database. Explain it further by giving additional examples.
2. Define schema and differentiate it from database. Provide additional examples of schema.
3. Define database systems and explain how it is used to interact the application programs with database.
4. Enumerate the components of DBMS Environment. Provide a brief explanation about each component.
5. Explain the different facilities provided by DBMS. 6. Enumerate and explain the different entity relationships. 7. Define relational database and provide examples that can
support it. 8. Discuss the other database concepts such as relation,
attribute, domain and primary key and provide examples of each.
9. Define SQL and enumerate the main categories of SQL commands.
10. Discuss further each main category of SQL commands and enumerate the commands used.
11. Define integrity constraints and explain its different types. 12. Define normalization and discuss the different normal forms. 13. Discuss the advantages of normalization.
Advance Database Systems
Review of Theory of Databases *Property of STI Page 2 of 12
Review of Database Concepts Page 1 of 17
Advance Database Systems
* Property of STIPage 1 of 17
Review of Theory of Databases
Review of Database Concepts
� What is a Database?
� A database is a collection of
logically related data. Example: Personal information such as name, address, birthday and gender
� What is a Schema?
� A schema or a database schema
is the over-all design of a
database.
� What is a Database System?
� A database system is an
automated system that enables
users to define, create,
maintain and control access to
the database.
Review of Database Concepts Page 2 of 17
Advance Database Systems
* Property of STIPage 2 of 17
Review of Theory of Databases
� What are the components of the DBMS Environment?
� Data
� Hardware
� Software
� End Users
� Procedure
Review of Database Concepts
Review of Database Concepts What is a Database? A database is a collection of logically related data. It is a collection of persistent data that is used by the application systems and that is managed by a database management system. Personal information such as name, address, birthday and gender can be considered as a database. The large files of banks, health care companies, insurance companies, telephone companies, or student records in schools can be considered databases. These databases contain data about addresses, account balances, patient history, car registration plates, weights of vehicles, school grades and so on. For example, the school where you study has its own databases and these are used to store student related data. What is a Schema? A schema or a database schema is the over-all design of a database. It is a complete description of the content and structures of the fields, records and data relationships for the database. A schema is associated with one particular database username. This username is called the schema owner. In a database, it can have one or multiple schemas. Any user who creates an object has just created its own schema. What is a Database System? A database system is an automated system that enables users to define, create, maintain and control access to the database. It is a software system that interacts with the application programs and the database. This system is called the database-management system (DBMS). A DBMS enables users to process data stored in a database. Without it, it is impossible to look at data or to update or delete obsolete data, in the database. Some of the examples of DBMS include Microsoft Access, FileMaker, DB2, MySQL, Adaptive SQL Anywhere and Oracle. What are the components of the DBMS Environment?
• Data The data stored in the database is integrated and shared. It is said to be integrated because data redundancy or the repetition of data within the files must be minimized or completely eliminated. It is also shared because it can be accessed by more than one user.
• Hardware The hardware component is used to store the database itself and the software applications that are used to create and maintain the database. The hardware and software components complement each other.
• Software The software components refer to the interface layer between the users and the physical database. All requests from users to access the database are handled by the software layer.
• End Users The end users refer to the people whose tasks require access to the database system for querying, updating and generating useful reports.
Advance Database Systems
Review of Theory of Databases *Property of STI Page 3 of 12
Review of Database Concepts Page 3 of 17
Advance Database Systems
* Property of STIPage 3 of 17
Review of Theory of Databases
Review of Database Concepts
� What are the different facilities that DBMS provide?
� Users can define the database
through a Data Definition
Language (DDL).
� Users can manipulate data
through a Data Manipulation
Language (DML).
� DBMS can provide security
system.
� DBMS can provide an integrity
system.
� DBMS can provide a concurrency
control system.
� DBMS can provide a recovery
control system.
Review of Database Concepts Page 4 of 17
Advance Database Systems
* Property of STIPage 4 of 17
Review of Theory of Databases
Review of Database Concepts
� What are the different entity relationships?
� One-to-One
Table A Table B
A1
A2
A3
A4
B1
B2
B3
B4
What are the different facilities that DBMS provide?
• Users can define the database through a Data Definition Language (DDL). The DDL allows users to specify the structures, data types and constraints on the data to be stored on the database. It is used to define the parts of the database that are required.
• Users can manipulate data through a Data Manipulation Language (DML). The DML is a special language that allows users to insert, update, delete and retrieve data from the database. In other words, DML is used to manipulate the data.
• DBMS can provide security and recovery control system. The DBMS prevents unauthorized users accessing the database. As we all know, data is data is valuable and must be stored safely. That means protection of the stored data not only from malicious human activities, such as unauthorized logins, accidental information deletions or modifications and so on, but also recovering from hardware failures and natural disasters.
• DBMS can provide an integrity system. This means that the DBMS has to make sure that database data always satisfies the rules that apply in the real world. For example, the case of an employee who is allowed to work for one department only. It should never be possible for that particular employee to be registered as working for two or more departments. In addition, integrity means that two different pieces of database data do not contradict one another.
• DBMS can provide a concurrency control system. DBMS allows shared access of the database. It is important that information stored in a database must be accessible to many users simultaneously at different levels of security. For example, if two users try to change the same piece of information at the same time, the result can lead to data corruption. This type of situation has to be handled appropriately by internal database mechanisms.
What are the different entity relationships?
• One-to-One In the one-to-one relationship, an entity in table A is associated with at most one entity in table B and an entity in table B is associated with at most one entity in table A. The diagram in Figure 1.1 illustrates this relationship.
Advance Database Systems
Review of Theory of Databases *Property of STI Page 4 of 12
Review of Database Concepts Page 5 of 17
Advance Database Systems
* Property of STIPage 5 of 17
Review of Theory of Databases
Review of Database Concepts
� What are the different entity relationships?
� One-to-Many
Review of Database Concepts Page 6 of 17
Advance Database Systems
* Property of STIPage 6 of 17
Review of Theory of Databases
Review of Database Concepts
� What are the different entity relationships?
� Many-to-One
Figure 1.1 One-to-One Entity Relationships
• One-to-Many In the one-to-many relationship, an entity in Table A is associated with any number of entities in Table B. On the other hand, an entity in Table B can only be associated with at most one entity in A. The diagram in Figure 1.2 illustrates this relationship.
Figure 1.2 One-to-Many Entity Relationships
• Many-to-One In the many-to-one relationship, an entity in Table A is associated with at most one entity in Table B. On the other hand, an entity in Table B can be associated with any number of entities in Table A. The diagram in Figure 1.3 illustrates this relationship.
Figure 1.3 Many-to-One Entity Relationships
Advance Database Systems
Review of Theory of Databases *Property of STI Page 5 of 12
Review of Database Concepts Page 7 of 17
Advance Database Systems
* Property of STIPage 7 of 17
Review of Theory of Databases
Review of Database Concepts
� What are the different entity relationships?
� Many-to-Many
Table A Table B
A1
A2
A3
A4
B1
B2
B3
B4
Review of Database Concepts Page 8 of 17
Advance Database Systems
* Property of STIPage 8 of 17
Review of Theory of Databases
Review of Database Concepts
� What is relational database?
� A relational database is divided
into logical units called table
which is composed of rows and
columns of data.
• Many-to-Many In the many-to-many relationship, an entity in Table A is associated with any number of entities in Table B. On the other hand, an entity in Table B can be associated with any number of entities in Table A. The diagram in Figure 1.4 illustrates this relationship.
Figure 1.4 Many-to-Many Entity Relationships
What is relational database? A relational database is divided into logical units called table which is composed of rows and columns of data. In a relational database, the rows of data contain data that describe a particular real-world entity such as a product. The columns of data contain in a particular characteristic of real-world entity being describes by the rows of data. The rows of data are called records or tuples. On the other hand, the columns of data are called fields or attributes. Table 1.1 is an example of a relational table.
Table 1.1 Product Table
Advance Database Systems
Review of Theory of Databases *Property of STI Page 6 of 12
Review of Database Concepts Page 9 of 17
Advance Database Systems
* Property of STIPage 9 of 17
Review of Theory of Databases
Review of Database Concepts
� What is a relation?
� A relation is composed of rows
and columns of data.
� What is an attribute?
� In relational database, the table
columns correspond to
attributes.
� What is a domain?
� A domain refers to a set of valid
atomic values for a given
attribute.
� What is a primary key?
� A primary key refers to an
attribute or field that serves as
a unique identifier for a
particular record within a
relation.
Review of Database Concepts Page 10 of 17
Advance Database Systems
* Property of STIPage 10 of 17
Review of Theory of Databases
Review of Database Concepts
� What is SQL?
� Structured Query Language (SQL)
is the standard language used to
define, query, update and
maintain relational databases.
� Main categories of SQL
commands are as follows:
• Data Definition Language
(DDL)
• Data Manipulation Language
(DML)
• Data Query Language (DQL)
• Data Control Language (DCL)
• Transactional control
commands
What is a relation? A relation is a table composed of rows and columns of data. The figure above is an example of a relation. Names are given to relations for purposes of identification. What is an attribute? In relational database, the table columns correspond to attributes. An attribute is a named column of a relation. In the sample table above, the attributes are id, name, description, size, color, quantity and unit price. What is a domain? A domain refers to a set of valid atomic values for a given attribute. Atomic means that the attribute can no longer be divided into smaller units. In the table above, possible atomic data are id, description, size, color, quantity and unit_price. What is a primary key? A primary key refers to an attribute or field that serves as a unique identifier for a particular record within a relation. It is used to locate a record within a relation. Another use of primary key is that it is needed for foreign key support. In the table above, the primary key is the id. What is SQL? Structured Query Language (SQL) is the standard language used to define, query, update and maintain relational databases. It is a relational database language that is used to create and define the structure of the database. It is used to perform manipulations on the database and control the security in the database. Using Table 1.1, h is a list of statements that can be formulated with SQL:
• Insert a new record in the product table.
• Delete all the product data for product Shorts.
• Show the quantity of product Tee Shirts.
• Show the quantity of products with unit price greater than 15. There are main categories of SQL commands as follows:
• Data Definition Language (DDL)
• Data Manipulation Language (DML)
• Data Query Language (DQL)
• Data Control Language (DCL)
• Transactional control commands
Advance Database Systems
Review of Theory of Databases *Property of STI Page 7 of 12
Review of Database Concepts Page 11 of 17
Advance Database Systems
* Property of STIPage 11 of 17
Review of Theory of Databases
Review of Database Concepts
� What is Data Definition Language (DDL)?
� The DDL allows the user to
create and restructure database
objects.
� Some of the most fundamental
DDL commands are:
• CREATE TABLE
• ALTER TABLE
• DROP TABLE
• CREATE INDEX
• ALTER INDEX
• DROP INDEX
• CREATE VIEW
• DROP VIEW
What is Data Definition Language (DDL)? The DDL allows the user to create and restructure database objects, such as the creation or the deletion of a table. Some of the most fundamental DDL commands include the following:
• CREATE TABLE Syntax:
CREATE TABLE name_of_table
(
name_of_column column_datatype
)
Example:
CREATE TABLE MRTSched
(
sched_id varchar(10),
start_location varchar(75),
destination varchar(75),
departs datetime,
arrives datetime
);
• ALTER TABLE
Syntax: ALTER TABLE name_of_table
ADD name_of_field data_type
Example:
ALTER TABLE MRTSched
ADD runs_at_weekend char(1);
• DROP TABLE
Syntax: DROP TABLE name_of_table
Example:
DROP TABLE MRTSched
• CREATE INDEX
Syntax: CREATE INDEX <index_name>
ON <table_name> (<column_names>)
Example:
CREATE INDEX schedule_index
ON MRTSched (departs, arrive);
• DROP INDEX
Syntax: DROP INDEX <index_name>
Example:
DROP INDEX schedule_index
• CREATE VIEW
Advance Database Systems
Review of Theory of Databases *Property of STI Page 8 of 12
Review of Database Concepts Page 12 of 17
Advance Database Systems
* Property of STIPage 12 of 17
Review of Theory of Databases
Review of Database Concepts
� What is Data Control Language (DML)?
� DML allows the user to
manipulate data within objects
of a relational database.
� The three basic DML commands
are
• INSERT
• UPDATE
• DELETE
� What is Data Query Language (DQL)?
� DQL allows the user to select a
data or a group of data.
� The base command is SELECT
Syntax:
CREATE VIEW <view_name>
AS SELECT column1, column2,.....columnx FROM
table_name
Example:
CREATE VIEW Schedview
AS SELECT start_location, destination,
departs, arrives FROM MRTSched
• DROP VIEW
Syntax: DROP VIEW <view_name>
Example:
DROP VIEW SchedView
What is Data Control Language (DML)? DML allows the user to manipulate data within objects of a relational database. The three basic DML commands are
• INSERT
Syntax: INSERT INTO table_name (column_names) VALUES
(data_values)
Example:
INSERT INTO Category (CategoryId, Category)
VALUES (1, ‘Thriller’);
INSERT INTO Category (CategoryId, Category)
VALUES (2, ‘Romance’);
INSERT INTO Category (CategoryId, Category)
VALUES (3, ‘Horror’);
INSERT INTO Category (CategoryId, Category)
VALUES (4, ‘War’);
INSERT INTO Category (CategoryId, Category)
VALUES (5, ‘Sci-fi’);
• UPDATE
Syntax: UPDATE table_name
SET column_name = value
WHERE condition
Example:
UPDATE Category
SET Category = “War Crime”
WHERE Category = “War”
• DELETE
Syntax: DELETE FROM table_name [WHERE condition]
Example:
Advance Database Systems
Review of Theory of Databases *Property of STI Page 9 of 12
Review of Database Concepts Page 13 of 17
Advance Database Systems
* Property of STIPage 13 of 17
Review of Theory of Databases
Review of Database Concepts
� What is Data Control Language (DCL)?
� The DCL allows the user to
create objects related to user
access and also control the
distribution of privileges among
users.
� Some data control commands
are as follows:
• ALTER PASSWORD
• GRANT
• REVOKE
• CREATE SYNONYM
Review of Database Concepts Page 14 of 17
Advance Database Systems
* Property of STIPage 14 of 17
Review of Theory of Databases
Review of Database Concepts
� What is Transactional Control Commands (TCC)?
� The TCC allow the user to
manage database transactions.
� Some commands are as follows:
• COMMIT
• ROLLBACK
• SAVEPOINT
• SET TRANSACTION
DELETE FROM Category
DELETE FROM Category WHERE CategoryId = 1
What is Data Query Language (DQL)? DQL allows the user to select a data or a group of data. It is the most concentrated focus of SQL for modern relational database users. The base command is SELECT
Syntax: SELECT column1, column2,.....columnx FROM
table_name
Example: SELECT start_location, destination, departs,
arrives FROM MRTSched What is Data Control Language (DCL)? The DCL allows the user to create objects related to user access and also control the distribution of privileges among users. Some data control commands are as follows:
• GRANT
Syntax: GRANT ALL [PRIVILEGES] |
<system privilege,...> |
<role> TO <user> | <role>
Note: the syntax may vary from one RDBMS to another. Example:
SELECT start_location, destination, departs,
arrives FROM MRTSched
• REVOKE What is Transactional Control Commands (TCC)? The TCC allow the user to manage database transactions. These are the commands used to specify the start and end of transactions. It is also used in data locking and concurrency control.
• COMMIT
Syntax: COMMIT The commit operation is used to indicate the completion of a transaction. All updates performed by a transaction on the database can now be made permanent.
• ROLLBACK
Syntax: ROLLBACK The rollback operation is used to indicate the cancellation of a transaction. It sends a signal on the transaction manager which states that a transaction cannot be completed.
Advance Database Systems
Review of Theory of Databases *Property of STI Page 10 of 12
Review of Database Concepts Page 15 of 17
Advance Database Systems
* Property of STIPage 15 of 17
Review of Theory of Databases
Review of Database Concepts
� What is Integrity Constraint?
� Integrity constraints are used to
ensure accuracy and consistency
of data in a relational database.
� What are the types of integrity constraints?
� Primary key Constraints
� Unique Constraints
� Foreign Key Constraints
� Not Null Constraints
� Check Constraints
What is Integrity Constraint? Integrity constraints are used to ensure accuracy and consistency of data in a relational database. Data integrity means consistency and correctness of the data. Data is consistent if individual items do not contradict one another. Data is correct if it satisfies all relevant rules or semantics. For example, if in the example database the total number of sets in a match is greater than ten, this data item is incorrect. Integrity constraints are the rules with which the contents of a database must comply at all times and they describe which updates to the database are permitted. What are the types of integrity constraints?
• Primary key Constraints
PRIMARY KEY is the most important and most commonly used constraint. It provides a link between tables. For example, StudentId is the primary key in the Student Record database’s Student table and is linked to the Registration and Assessment tables. In order for the relationship to work, the primary key must uniquely identify a record, which means that you can include only unique values and no NULLs. In fact, the PRIMARY KEY constraint is essentially a combination of the UNIQUE and NOT NULL constraints. Whereas you can have more than one UNIQUE or CHECK constraint on a table, only one PRIMARY KEY constraint per table is allowed.
• Unique Constraints
The UNIQUE constraint prevents two records from having identical values in a particular column. In the Student table, for example, you might want to prevent two or more student from having identical email addresses.
• Foreign Key Constraints
Foreign keys are columns that refer to primary keys in another table. Primary and foreign keys establish relations between data in different tables.
• Not Null Constraints
This constraint ensures that the column must have a value or else the record cannot be inserted.
• Check Constraints
The CHECK constraint enables a condition to check the value being entered into a record. If the condition evaluates to false, the record violates the constraint and isn’t entered into the table.
Advance Database Systems
Review of Theory of Databases *Property of STI Page 11 of 12
Review of Database Concepts Page 16 of 17
Advance Database Systems
* Property of STIPage 16 of 17
Review of Theory of Databases
Review of Database Concepts
� What is normalization?
� Normalization is a process of
reducing data redundancy in a
database.
� The different levels of normal
forms:
• First Normal Form (1NF)
• Second Normal Form (2NF)
• Third Normal Form (3NF)
What is normalization? Normalization is a process of reducing data redundancy in a database. It is a mechanism that is used when designing and redesigning a database. It is also a process or set of guidelines used to optimally design a database to reduce redundant data. The different levels of normal forms, each one being a refinement of the preceding one are:
• First Normal Form (1NF) The first normal form provides the foundation for the second and third forms. The first form includes the following guidelines:
� Each attribute of a column must contain only one value. � Each column in a relation must contain the same number
of values. � Each column in a relation must be different.
• Second Normal Form (2NF)
First normal form requires every table to have a primary key. This primary key can consist of one or more columns. The primary key is the unique identifier for that record, and second normal form states that there must be no partial dependences of any of the columns on the primary key. For example, assume in a Student Record database, you decide to store a list of subjects and faculty who taught in them. The data being stored is subject ID, subject name, units, faculty ID, faculty name and department. This example is in first normal form, in that it obeys all the rules of first normal form. In this table, the primary key consists of SubjectId and FacultyId. However, the example is not in second normal form because there are partial dependencies of primary keys and columns. To make this table comply with second normal form, you need to separate the columns into three tables. First, create a table to store the subject detail. Next, create a table to store details of each faculty. Finally, create a third table storing just SubjectId and FacultyId to keep track of which faculty taught in which subject.
• Third Normal Form (3NF)
A table is said to be in the third normal form when the following conditions are met:
� It is in second normal form. � All nonprimary fields are dependent on the primary key.
The dependency of nonprimary fields is between the data. For example, street name, barangay and city are unbreakably bound to the zip code. For example, Ayala Ave, Legaspi Village, Makati has an assigned and unique zip code. If you mail a letter, in theory supplying the street address and zip code is enough for someone to locate the house.
Advance Database Systems
Review of Theory of Databases *Property of STI Page 12 of 12
Review of Database Concepts Page 17 of 17
Advance Database Systems
* Property of STIPage 17 of 17
Review of Theory of Databases
Review of Database Concepts
� What are the advantages of normalization?
� Better overall database
organization
� Reduction of redundant data
� Data consistency within the
database
� Flexible database design
� Efficient database security
handling
� Enforces concept of referential
integrity
What are the advantages of normalization? Some of the major benefits of normalization include the following:
• Better overall database organization
• Reduction of redundant data
• Data consistency within the database
• Flexible database design
• Efficient database security handling
• Enforces concept of referential integrity [Review of Database Concepts, Pages 1 – 17 of 17]
GENERALIZATION:
o A database is a shared collection of logically related data. o A schema or a database schema is the over-all design of a
database. o A relational database is divided into logical units called table
which is composed of rows and columns of data. o Structured Query Language (SQL) is the standard language
used to define, query, update and maintain relational databases.
o Normalization is a process of reducing data redundancy in a database.
REFERENCES:
o Ramez Elmasri and Shamkant Navathe. Fundamentals of
Database Systems. Pearson Education, fourth edition, 2007. o Database Management Systems by Raghu Ramakrishnan and
Johannes Gehrke, McGraw-Hill, 3rd edition o An Introduction to Database Systems by C. J. Date, Addison
Wesley, 7th edition o Database Management Systems", Raghu Ramakrishnan,
Johannes Gehrke, McGraw-Hill Science, ISBN 0072465638, 2002
o R. Elmasri and S.B. Navathe, fundamentals of Database System, Addison Wesley Co., 2006