You are on page 1of 9

6IMAN

DATABASE CONCEPTS CATEGORIES OF DBMS


⤷ Businesses have records that are stored in a Relational
database to be available for decision ⤷ usually referred to as SQL.
makers. ⤷ data is stored in a table structure which are
⤷ Good Decision requires Good Information. linked to each other using relationships.
⤷ AT&T and Sprint Telecommunications are ⤷ collection of tables with relationships.
two of the top ten largest databases in the ⤷ are single attributes that are being
world. shared across tables
Data ⤷ are the primary key of one table to
⤷ are classified as raw facts. another that would be called a
⤷ are facts that have not yet been foreign key.
processed. ⤷ Are common columns in two or more
⤷ a list with values is called data. tables
⤷ if the data has been manipulated, ⤷ Oracle, MySQL, SQL Server (Microsoft),
per se the sort function, it will be Microsoft Access are popular RDBMS.
called information. ⤷ MySQL
⤷ building block of information. ⤷ most commonly used RDBMS
⤷ Records/Rows are a collection of related ⤷ used for warehousing,
data items. e-commerce, and logging
⤷ Tables are a collection of related applications.
records/tuples. ⤷ most common used for it is
⤷ Databases are a collection of related tables. for the purpose of a web.
⤷ Entities are fields where the data is ⤷ Oracle
to be extracted from. ⤷ an RDBMS that implements
Information OOP features.
⤷ result of processing raw data for its purpose ⤷ it is called an
⤷ it can be as simple as organizing object-relational database
data. management system
⤷ information can be used as the foundation (ORDBMS).
for decision making ⤷ SQL Server
Database ⤷ RDBMS made by Microsoft.
⤷ is a computer structure that stores a ⤷ Microsoft Access
collection of: ⤷ is an RDBMS made for
⤷ End-user data - raw facts of interest storing reference, reports
to the end-user. and analysis.
⤷ Metadata, fields/attributes, or data ⤷ overcomes the limitations
about data, the end-user’s data is found in Excel.
integrated and managed. Non-Relational
Database Management System (DBMS) ⤷ usually referred to as NoSQL.
⤷ collection of programs that manages the ⤷ does NOT store data in a tabular structure,
structure and controls access to data. no relationships.
⤷ is the intermediary (interface) between the ⤷ NRDBMS have a specified language for its
user and the database. use, they do not understand other langaues.
⤷ similar to an operating system ⤷ NoSQL
⤷ MongoDB is a popular NRDBMS.
SQL
⤷ Structured Query Language Database Location(s)
⤷ Programming language that the DBMS ⤷ Centralized database: data located at a
processes to manipulate the data. single site (Ex. HAU)
⤷ Distributed database: data distributed
MySQL across several different sites (Ex. Socmed)
⤷ is a relational database management
system (RDBMS) that uses SQL as its query Expected type and extent of use
language. ⤷ Most popular way of classifying databases
⤷ Open-source database system, widely used ⤷ Operational database: supports a
for web applications. company’s day-to-day operations
⤷ Also called transactional or
Relational Model 1 production database
⤷ Relational Databases ⤷ Critical day-to-day operations
⤷ each entity in own table ⤷ Data warehouse: stores data used for
⤷ Attributes are fields(columns) in tactical or strategic decisions
table
⤷ order of rows and columns are
immaterial (unimportant)
⤷ Repeating groups are not permitted
⤷ Entries with repeating groups are
unnormalized.

EVOLUTION OF FILE SYSTEM DATA PROCESSING

Manual File System

Data Organization Organizes data using


physical documents, folders,
and filing cabinets.

Data Retrieval Manual searching and


retrieval; time-consuming.

Data Limited data independence;


⤷ Repeating groups are PartNum, Independence changes can be challenging.
NumOrdered and QuotedPrice
Data Integrity Prone to errors and data
redundancy.
TYPES OF DATABASES
Number of Users Scalability Limited scalability; physical
⤷ Single-user database supports only one constraints.
user at a time
Security Relies on physical measures
⤷ Desktop database: single-user; runs (locks, access control).
on PC
⤷ Multi User database supports multiple Complexity Simple and straightforward,
users at the same time but limited in capabilities.
⤷ Workgroup and enterprise
databases
Computerized File System (Flat File System) Database Management System (DBMS)

Data Organization Organizes data into tables Data Organization Organizes data into tables
with rows and columns. with relationships between

Data Retrieval Basic querying; may involve Data Retrieval Advanced querying with
scanning entire files. SQL; optimized for efficient
retrieval.
Data Some separation between
Independence physical and logical data. Data Offers significant data
Independence independence, both logical
Data Integrity Relatively better but still and physical.
susceptible to redundancy.
Data Integrity Enforces data integrity
Scalability Faces challenges with larger through constraints.
datasets.
Scalability Scalable to handle growing
Security Limited security features. data volumes and user
loads.
Complexity More complex than manual
systems but lacks relational Security Offers robust security
capabilities. features (user
authentication, encryption).

Complexity Complex with support for


Modern Productivity Tools System relational structures,
transactions, and advanced
Data Organization Utilizes digital tools for features.
organization; structure may
vary.
Problems with File System Data Processing
Data Retrieval Improved retrieval using
digital tools; capabilities ⤷ Lengthy development times
vary. ⤷ Difficulty of getting quick answers
⤷ Complex system administration
Data Provides a degree of ⤷ Lack of security and limited data sharing
Independence independence; varies by ⤷ Extensive Programming
tool.
Data Systems
Data Integrity Depends on the tool; may
have built-in checks. ⤷ consists of logically related data stored in a
single logical data repository (single unit)
Scalability Scalability depends on the ⤷ May be physically distributed among
tool's architecture. multiple storage facilities
⤷ DBMS eliminates most of file system’s
Security Varied security measures
problems
depending on the tool.
⤷ Current generation stores data structures,
Complexity Varies by tool; can range relationships between structures, and
from simple to moderately access paths
complex. ⤷ Also defines, stores, and manages all access
paths and components
Database System Environment
⤷ Database system defines and regulates the Customer RepNum is a foreign key while Rep
collection, storage, management, use of RepNum is a primary key.
data
⤷ Five major parts of a database system:
Primary key - the column or collection of columns
⤷ Hardware: all the system’s physical
that uniquely identifies a given row in a table.
devices
⤷ Software: three types of software
Structured Query Language (SQL)
required Aspects of data management:
⤷ Operating system software 1.Data Definition - instructing the DBMS
⤷ DBMS software software on what tables will be in the
⤷ Application programs and database attributes will be in the tables
utility software ⤷ In simple words, DDL commands
⤷ People: all users of the database are used to create or define what a
system database, table, attribute and data
⤷ System and database to be inputted is.
administrators ⤷ eg. CREATE database, CREATE
⤷ Database designers tables
⤷ Systems analysts and 2. Data Manipulation - refers to the four basic
programmers operations that can and must be performed
⤷ End users on the data stored in any DBMS.
⤷ Procedures: instructions and rules ⤷ Data Retrieval
that govern the design and use of ⤷ Data update
the database system ⤷ Insertion of New Records
⤷ Data: the collection of facts stored in ⤷ Deletion of Existing Records
the database ⤷ DML commands are used to
manipulate the tables, attribute, and
BUILDING A DATABASE data that are already in the database
⤷ Database design determines the structure Syntaxes below
of a database.
⤷ design entered into DBMS during Table and Column Naming Conventions:
construction ⤷ Names cannot exceed 18 characters.
⤷ Must start with a letter.
⤷ Database
⤷ Can contain letters, numbers, and underscores.
⤷ Tables ⤷ Should not contain spaces.
⤷ Data
⤷ design entered into DBMS during MySQL DataTypes:
construction ⤷ Each column in a table is required to have a
name and data type.
DATABASE STRUCTURE REPRESENTATION Common Data Types:
⤷ Rep (RepNum, LastName, FirstName, Street, ⤷ STRING datatypes:
City, State, PostalCode, Commission, Rate) ⤷ able to store up to 8,000 characters long
⤷ CHAR(n)
⤷ Customer (CustomerNum, CustomerName,
⤷ uses static memory allocation
Street, City, State, PostalCode, Balance, Credit
⤷ Example: CHAR(20)
Limit, RepNum)
⤷ It consumes 20 bytes of storage,
⤷ Orders (OrderNum, OrderDate, CustomerNum)
regardless of whether the value
⤷ OrderLine (OrderNum, ItemNum, NumOrdered, is only 10 bytes.
QuotedPrice) ⤷ VARCHAR(n)
⤷ Item (ItemNum, Description, OnHand, ⤷ uses dynamic memory allocation
Category, Storehouse, Price) ⤷ Example: VARCHAR(20)
⤷ The byte value is configured to >PRIMARY KEY
be 20, but when the actual value ⤷ A primary key is a field or a combination of fields
is only 10 bytes, it utilizes only in a database table that uniquely identifies each
the specified 10 bytes. record in the table.
⤷ DATE and TIME datatypes: ⤷ Primary key attributes contain both a NOT NULL
⤷ Default value will be 0? and a UNIQUE specification
⤷ DATE >FOREIGN KEY
⤷ stores date in the format ⤷ A foreign key is a field in a database table that is
YYYY-MM-DD. a reference to the primary key in another table.
⤷ TIME ⤷ It establishes a link between the data in two
⤷ stores in the format HH-MI-SS tables, creating a relationship between them.
⤷ DATETIME ⤷ The foreign key ensures referential integrity,
⤷ stores in the format meaning that values in the foreign key column
YYYY-MM-DD-HH-MI-SS must match values in the primary key of the
⤷ YEAR referenced table.
⤷ stores year in 2 digits or 4 digit
format, Range 1901 to 2155 in Listing Table Rows
4-digit format. Range 70 to 69 SELECT - is used to list contents of table
representing 1970 to 2069. ⤷ Columnlist represents one or more attributes,
⤷ NUMERIC datatypes: separated by commas
⤷ DECIMAL(p, q) ⤷ Asterisk can be used as wildcard character to list
⤷ “p” - Total number of digits all attributes
(precision) in the number. Saving Table Changes
⤷ “q” - Number of digits to the ⤷ Changes made to table contents are not
right of the decimal point physically saved on disk until:
(scale). ⤷ Database is closed
⤷ INT ⤷ Program is closed
⤷ INT(p) ⤷ COMMIT command is used
⤷ NULLS:
Will permanently save any changes made to any table in the
⤷ a special value to represent when actual database
value is unknown for a column
⤷ should not allow nulls for primary key Edit/update records
columns. ⤷ Used to modify the existing records in a table.
⤷ NOT NULL constraint, the system will Restoring Table Contents
reject any attempt to store a null value ⤷ ROLLBACK
there. ⤷ Undoes changes since last COMMIT
Note: Data Types may have different names in different ⤷ Brings data back to pre change values
databases. And even if the name is the same, the size and
⤷ COMMIT and ROLLBACK only work with
other details may be different.
commands to add, modify, or delete table rows
SQL Constraints: Deleting table rows
>NOT NULL constraint ⤷ Deletes table row
⤷ A special value to represent situation when ⤷ WHERE condition is optional
actual value is not known for a column ⤷ If WHERE condition is not specified, all rows
⤷ Ensures that column does not accept nulls from specified table will be deleted
⤷ NULL is the default.
Syntaxes:
>UNIQUE constraint
Syntax for LOGGING to a server:
⤷ Ensures that all values in column are unique
>DEFAULT constraint # mysql -u root
⤷ Assigns value to attribute when a new row is Welcome to the database_name monitor… etc etc

added to table
To confirm if you have connected:
Server_name [(none)]>
Syntax for CREATING databases: Syntax for FOREIGN KEY:
Server_name [(none)]> CREATE DATABASE Format:
database_name; Server_name [(Student)]> CREATE TABLE table_name2
>(
Example: > column_name data_type(size) constraints,
Server_name [(none)]> CREATE DATABASE Student; > FOREIGN KEY(column_name) REFERENCES
table_name2(column_name)
To confirm if the database has been created: > );
Server_name [(none)]> SHOW DATABASES;
*Displays list of databases* Server_name [(Student)]> CREATE TABLE table_name2
>(
> StudentNum varchar(5),
Syntax for SELECTING a database: > Lastname varchar(50) NOT NULL,
> FirstName varchar(50) NOT NULL,
Server_name [(none)]> USE Student; > Address varchar(50),
Server_name [(Student)]> > City varchar(20),
> Birthday date,
> StudentID varchar(5),
Syntax for DELETING a database: > FOREIGN KEY(StudentID) REFERENCES
table_name2(StudentID)
Note: When deleting a database, have a backup of it.
>);
Server_name [(Student)]> DROP DATABASE;

Syntax for ADDING VALUES:


Syntax for CREATING tables:
Server_name [(Student)]> INSERT INTO table_name
Format: > VALUES(value1, value2, value3);
Server_name [(Student)]> CREATE TABLE table_name
>( Server_name [(Student)]> INSERT INTO table_name
> column_name data_type(size) constraints, (column1, column2, column3)
> ); > VALUES(value1, value2, value3);

Server_name [(Student)]> CREATE TABLE table_name


>( Syntax for SHOWING tables:
> StudentID varchar(5) primary key,
> Lastname varchar(50) NOT NULL, Server_name [(Student)]> SHOW TABLES;
> FirstName varchar(50) NOT NULL,
> Address varchar(50),
> City varchar(20), Syntax for SHOWING columns:
> Birthday date
Server_name [(Student)]> DESC table_name;
>);
Server_name [(Student)]> DESCRIBE table_name;

Syntax for PRIMARY KEY:


Syntax for DROPPING tables:
Format:
Server_name [(Student)]> DROP TABLE table_name;
Server_name [(Student)]> CREATE TABLE table_name
>(
> column_name data_type(size) constraints,
> PRIMARY KEY(column_name) Syntax for ALTERING tables:
> );
Server_name [(Student)]> ALTER table_name;
Server_name [(Student)]> CREATE TABLE table_name
>(
> StudentID varchar(5),
Syntax for ALTERING (adding) columns:
> Lastname varchar(50) NOT NULL, Server_name [(Student)]> ALTER table_name
> FirstName varchar(50) NOT NULL, > ADD column_name datatype constraints;
> Address varchar(50),
> City varchar(20),
> Birthday date, Syntax for ALTERING (modifying) columns:
> PRIMARY KEY(StudentID)
>); Server_name [(Student)]> ALTER table_name
> MODIFY COLUMN
> column_name
>new_datatype constraints;
Syntax for ALTERING (renaming) columns: ⤷ Physical Data Model
Server_name [(Student)]> ALTER table_name ⤷ Represents the actual implementation of
> CHANGE COLUMN old_name to new_name; the database, including details about
storage, indexing, and other aspects
Syntax for LISTING table rows: specific to the chosen database
management system.
Server_name [(Student)]> SELECT columnlist
> FROM tablename;
Importance of Data Models:
⤷ Data models provide a clear and visual
Syntax for SAVING table changes:
representation of the structure,
> COMMIT[WORK]; relationships, and constraints within a
database.
Syntax for UPDATING records in a table: ⤷ Facilitate interaction among the designer,
the applications programmer, and the end
UPDATE table_name
SET column1 = value1, column2 = value 2, … user
WHERE condition; ⤷ Data models guide the design process.

Syntax for RESTORING records in a table: DATA MODEL BASIC BUILDING BLOCKS

ROLLBACK; ⤷ Entity: anything about which data are to be


collected and stored

Syntax for DELETING table Rows: ⤷ Attribute: a characteristic of an entity


⤷ Relationship: describes an association
DELETE FROM table_name
[WHERE conditionlist]; among entities
⤷ One-to-many (1:M) relationship
DATA MODELLING AND DATA MODELS ⤷ Many-to-many (M:N or M:M)
Data Modelling relationship
⤷ process of creating a representation of the ⤷ One-to-one (1:1) relationship
structure and relationships within a ONE-TO-MANY RELATIONSHIP
database.
⤷ Let's consider a scenario with two entities:
⤷ reduces complexities of database design
Department and Employee.
Data Models
⤷ specific representation or specification of ⤷ Business Rule: Each department can have
how data is organized and related within a multiple employees, but each employee
database. belongs to only one department.
⤷ result of the data modeling process. ○ A business rule is a brief, precise,
Types of data models: and unambiguous description of a
⤷ Conceptual Data Model policy, procedure, or principle within
⤷ Describes high-level concepts and a specific organization.
relationships, focusing on what needs to Relational Model

be represented without specifying


implementation details.
⤷ Logical Data Model
⤷ Defines the structure of the data at a
more detailed level, including tables,
fields, and relationships, without
considering specific database
management system details.
Entity Relationship Diagram

CONSTRUCTING A ONE-TO-MANY RELATIONSHIP

1. Create a table for the "one" side of the


relationship. In this example, it's the Department
table:

MANY-TO-MANY RELATIONSHIP
⤷ Let's consider a scenario with two entities:
Student and Course.
2. Create a table for the "many" side of the ⤷ Business Rule: Each student can enroll in
relationship. In this example, it's the Employee multiple courses, and each course can have
table. Include a foreign key that references the multiple students.
primary key of the "one" table: ⤷ Database designers label the relationship
“STUDENT learns COURSE” as M:N
Relational Model:

Entity-Relationship Diagram:
Query:
SELECT * FROM Employee WHERE DepartmentID = 1;
Example 2:

CONSTRUCTING A M-TO-M RELATIONSHIP


1. Create the first table for one side of the
relationship. Student.
2. Create the second table for the other side of
the relationship. Courses.

3. Create the Associative Table


a. Create the third table to manage the
many-to-many relationship. This
table typically includes foreign keys
referencing the primary keys of both
the Student and Course tables.

You might also like