Database Reviewer!!!
Database Reviewer!!!
Understanding of a process or
Meaningful and relevant system and applying that to solve
Meaning Little or no meaning
for decision-making problems, create new things, or make
better decisions
Data can guide decisions Information enables Knowledge drives sound decision-
Decision-making
but requires interpretation informed decision-making making based on experience
Graph showing
Temperature readings Insight gained from the graph that
Example temperature trends over
recorded temperature increases in the summer
time
A database is a shared, integrated computer structure that stores a collection of the following:
• End-user data—that is, raw facts of interest to the end user.
• Metadata, or data about data, through which the end-user data is integrated and
managed. The metadata describes the data characteristics and the set of relationships that links
the data found within the database.
First, the DBMS enables the data in the database to be shared among multiple applications or
users. Second, the DBMS integrates the many different users’ views of the data into a single all-
encompassing data repository. Because data is the crucial raw material from which information
is derived, you must have a good method to manage such data. DBMS helps make data
management more efficient and effective. In particular, a DBMS provides these advantages.
Types of Database
1. single-user database supports only one user at a time. A single-user database that
runs on a personal computer is called a Desktop database.
2. multiuser database supports multiple users at the same time. the multiuser database
supports a relatively small number of users (usually fewer than 50) or a specific
department within an organization, it is called a Workgroup database.
3. Enterprise database used by the entire organization and supports many users (more
than 50, usually hundreds) across many departments.
4. A database that supports data located at a single site is called a CENTRALIZED
DATABASE. A database that supports data distributed across several different sites is
called a DISTRIBUTED DATABASE.
5. A database that is designed primarily to support a company’s day-to-day operations is
classified as an operational database, also known as an online transaction
processing (OLTP) database, transactional database, or production database.
6. analytical database focuses primarily on storing historical data and business metrics
used exclusively for tactical or strategic decision making.
Analytical databases comprise two main components: a data warehouse and an
online analytical processing front end.
Data warehouse is a specialized database that stores data in a format optimized
for decision support. The data warehouse contains historical data obtained from
the operational databases as well as data from other external sources.
Online analytical processing (OLAP) is a set of tools that work together to
provide an advanced data analysis environment for retrieving, processing, and
modeling data from the data warehouse. In recent times, this area of database
application has grown in importance and usage, to the point that it has evolved
into its own discipline: business intelligence.
Databases can also be classified to reflect the degree to which the data is structured.
1. Unstructured Data - data that exists in its original, raw state; that is, in the format in
which it was collected.
2. Structured Data - data that has been formatted to facilitate storage, use, and
information generation.
3. Semi-structured Data - data that has already been processed to some extent.
Extensible Markup Language (XML) is a special language used to represent and manipulate
data elements in a textual format. An XML database supports the storage and management of
semi structured XML data.
Database design refers to the activities that focus on the design of the database structure that
will be used to store and manage end-user data.
Data modeling, the first step in designing a database, refers to the process of creating a
specific data model for a determined problem domain.
A data model is a relatively simple representation, usually graphical, of more complex real-world
data structures.
A relational database is a collection of tables, these tables are called relations, and this is how
this type of database gets its name.
The two following elements define how a database relationship is established:
PRIMARY KEY - A column whose value uniquely identifies a table record.
FOREIGN KEY - A column whose values reference the primary key of another table.
An entity is like a noun, it is a person, place, thing, or event about which data will be collected
and stored. An entity represents a particular type of object in the real world, which means an
entity is “distinguishable”—that is, each entity occurrence is unique and distinct.
An attribute is a characteristic of an entity.
A relationship describes an association among entities.
1. ONE-TO-MANY
2. MANY-TO-MANY
3. ONE-TO-ONE.
Database designers usually use the shorthand notations 1:M or 1..*, M:N or *..*, and 1:1 or 1..1,
respectively. (Although the M:N notation is a standard label for the many-to-many relationship,
the label M:M may also be used.)
To work with a database on a computer, you must use a database management system. A
database management system (DBMS) is a software program that lets you create a database
and then use it to add, change, delete, sort, and view the data in a database. In this chapter,
you will learn how to use the database management system called MySQL.
MySQL is freely available as open-source software. Open-source software is software for which
the source code is freely and publicly available.
SQL QUERIES
SELECT command retrieves data from a database
Basic format: SELECT column(s) FROM table WHERE condition
Useful for answering questions about data stored in tables
Retrieve specific or all columns using SELECT
Retrieve all rows without a WHERE clause
WHERE clause filters rows based on conditions
Allows selection of rows with specific criteria
Simple conditions: comparisons with =, >, <, etc.
Compound conditions: combine conditions with AND, OR, NOT
Specialized operators:
BETWEEN for ranges
LIKE with wildcards (%) for pattern matching
IN for specifying a set of values
ORDER BY clause sorts query results
Multi-key sorting: specify primary and secondary sort keys
DESC keyword for descending order, ASC keyword for ascending order
Use subqueries within other queries for complex selections
Functions: COUNT, SUM, AVG, MAX, MIN
Perform calculations on groups of rows
DISTINCT keyword eliminates duplicates in counts
GROUP BY groups rows by column values
HAVING clause restricts groups based on aggregate conditions
NULL represents missing or unknown data
Use IS NULL or IS NOT NULL to filter NULL values
Important when dealing with incomplete data
A JOIN clause is used to combine rows from two or more tables, based on a related
column between them.
Joining tables in SQL requires a condition in the WHERE clause to match rows from
different tables.
SUPPORTED TYPES OF JOINS IN MYSQL
INNER JOIN: Returns records that have matching values in both tables
LEFT JOIN: Returns all records from the left table, and the matched records from the
right table
RIGHT JOIN: Returns all records from the right table, and the matched records from the
left table
CROSS JOIN: Returns all records from both tables
The IN operator allows you to specify multiple values in a WHERE clause. It is a
shorthand for multiple OR conditions.
The EXISTS operator is used to test for the existence of any record in a subquery. The
EXISTS operator returns TRUE if the subquery returns one or more records.
Subqueries allow querying based on another query's result.
MySQL evaluates from innermost to outermost subquery.
Nested subqueries are subqueries (queries within queries) that are placed within another
SQL query, typically within the WHERE, HAVING, or FROM clause. They help perform
complex operations by first executing the subquery to generate a temporary result,
which is then used by the main (outer) query.
Aliases simplify references in complex queries.
A self-join treats a single table as if it were two. Join a table to itself for hierarchical data.
Set operations in SQL (like UNION, INTERSECT, and EXCEPT/MINUS) allow
combining the results of two or more SELECT queries.
Union Operation: Combines the result sets of two SELECT statements and returns
distinct results.
Intersect Operation: Finds the common elements between two result sets (not supported
by all SQL databases natively).
The EXCEPT (or MINUS in some databases, like Oracle) operation allows you to
compare results from two queries and return records that exist in the first query but not
in the second
ALL and ANY can compare a value against subquery results.
It returns a Boolean value as a result, returns TRUE if ALL of the subquery values meet
the condition is used with SELECT, WHERE and HAVING statements
ALL means that the condition will be true only if the operation is true for all values in the
range.
The ANY Operator returns a Boolean value as a result. It returns TRUE if ANY of the
subquery values meet the condition
ANY means that the condition will be true if the operation is true for any of the values in
the range.
A Cartesian product is formed by omitting the WHERE clause in a join.
Use CREATE TABLE to define new tables
Clone an existing table structure with CREATE TABLE
LIKE Populate new tables using INSERT with SELECT queries
Use CREATE TABLE to define new tables
Clone an existing table structure with CREATE TABLE ... LIKE
Populate new tables using INSERT with SELECT queries
Use INSERT to add new data into a table
Specify column values or use SELECT for batch inserts
Use DELETE to remove rows matching a condition
Always include a WHERE clause to avoid removing all rows unintentionally
Use ALTER TABLE to:
- Add, modify, or delete columns
- Change column data types
Default values for new columns are NULL unless specified otherwise
COMMIT saves all changes permanently
ROLLBACK undoes changes made since the last COMMIT
Enable transaction control with SET AUTOCOMMIT = 0;
Use DROP TABLE to permanently delete a table and its data