DCICT 2 Databases
DCICT 2 Databases
DCICT 2 Databases
DATABASES
DATABASE
• Data stored in transience during program execution (classes, structs, etc) do not count,
since they do not offer permanence.
DATA IN 3 LEVELS
• Level 2 – The DataBase Management System (DBMS) – interaction between data and
an application
• A software package that helps to update, maintain and secure the data.
• Level 3 – Application
• Any software package that is built on top of the other 2 layers that provides interaction with
the user. A web app, a mobile app, BI/ERP, etc.
TYPES OF DATABASES
• Flat Model
• Navigational databases
• ▫ Hierarchical (tree) database model
• ▫ Network/Graph model
• Relational Model
• Object model
• Document model
• Entity–attribute–value model
• Star schema
DISADVANTAGES OF FILE STORAGE
• Self-describing data collection of related records (meta data, data about data)
• Databases contains not just data, but also include the structure of data
• At the application level, databases can also store other application related meta data.
• This facilitates the personalization and customization of the application according to
a user’s profile.
• Two of the most important roles in defining metadata
• Identify the type of data with a unique tag
• Define the affinity of the data (tags enclose all data that is logically related)
CONTENTS OF A DATABASE
• ACID
• 4 essential properties that a DBMS has to implement to effectively interact with a database
• SQL – Structured Query Language
• A query is a result of a request to the database for information or for modification.
• SQL is the language most relational databases (the most common for of databases) use for
interaction with the data.
• CRUD – Create, Read, Update, Delete
• Self-explanatory
• The 4 major operations performed on the database.
ACID
• Most of the challenges related to ACID compliance come from multiple users/concurrent
use of the database
RELATIONAL DATABASES - RELATIONS
• Tables (formally called ‘relations’) – are the building blocks of relational databases.
• Tables store data in 2D, where each row reflects one instance of a record, and each column
reflects one aspect of the attributes for all instances.
• Rows may also be called ‘tuples’.
• Columns may also be called ‘fields’.
• For example, a ‘student’ table may contain (student id, first name, last name, grade, school
name, home address, …), and each row may represent one student’s information, and
each column of the table represents one piece of information for all students. And this is
called a ‘relation’.
ENTITIES
• Entities are theoretical constructs that help us in conceptualization of relations.
• Anything that can de identified by a fixed number of its characteristics (attributes)
• Attributes have names and values
• Attributes have a data type
• A relational database table can be empty (NULL instance)
• The values are the data that's stored in the table
• An entity could be defined by a relation (table) or be spread across several relations.
• Instances are Unordered
• Order of the rows and columns does not matter in databases
• Freedom to move the data is limited to exchanging entire rows or exchanging entire
columns
PROPERTIES OF ENTITIES
• Uniqueness
• No two rows can be the same
• Two rows can have the same value for some attributes, just not all attributes
• Atomic Data
• Values stored for attributes
• Not decomposable into any smaller parts. Separate fields for street, city, state,
postal code
• "Only atomic data" rule relaxed for certain types of data. Dates, times, currency
PROPERTIES OF ENTITIES
• Keys
• Any set of attributes for which all attribute values are different is called a
candidate key
• Pick one and call it the primary key to decide uniqueness
• Key must distinguish all potential and actual entities, not just those that happen to
be in the table at a given time
• If no combination of attributes qualify as a candidate key, assign a unique ID to
each entity
KEYS - PRIMARY KEY AND FOREIGN KEY
• Union - Combines two tables (that have the same set of attributes)
• Difference - Remove from one table the rows also listed in a second table (remove from
Table1 any rows also in Table2)
• Product – Gives the cartesian product of the two tables – one instance of a row in Table2
added to each instance of a row in Table1
• The five basic operations (select, project,+, -, x ) are all we need to make any relational
table
• Other operations we can imagine can be done with combinations of the basic 5
• One combination is so commonly wanted and useful that we name it and provide it as a
direct operation: Join
JOINS
• Combines two tables (like the Product operation) but doesn't necessarily produce all pairings
• If the two tables each have fields with a common data type, the new table combines only the
rows from the given tables that match on the fields
• When match is true for a row from each table it produces a result row that is their
concatenation
• Lookup operation on tables
• For each row in one table, locate a row (or rows) in the other table with the same value in the common
field; if found, combine the two; if not, look up the next row.
• This match on equality is called a natural join
• Possible to join using any relational operator, not just = (equality) to compare fields
STRUCTURE OF A DATABASE
• We want to arrange the information in a database in a way that users see a relevant-
to-their-needs view of the data that they will use continually
• Physical database (stored on disk)
• Logical view of the database (made on the fly and customized for a user)
• The point of the two-level system is to separate the management of the data
(physical database) from the presentation of the data (logical view of the database)
• All users work with the same physical database
• Different users will work with different views, one for each
NORMALIZATION
• No Redundancy
• No Inconsistency – changes can only be made at one place and are consistent
(because of the key constraints), in DB
• Normalization is the process of decomposition, so all business concepts can be
modeled with clear logical relationships
• The entire database system remains consistent over time as the database grows with
least redundancy and much durability.
• Strong support to be ACID compliant