Database Programming: CPC 223 (A)
Database Programming: CPC 223 (A)
The 1980s also saw SQL become the standard language used for databases, which
we still use today.
The 1990s – the internet
The early days of object-oriented database management did not see the idea as a popular one.
This was partially due to the costs and time it would take to rewrite existing databases to
support the approach. However, object oriented database systems grow more popular in the 90s.
Another key event impacting the history of databases in the 90s was the
creation of the World Wide Web. High investments in online businesses fuelled demand for
client-server database systems. As such, the internet helped to power exponential growth of the
database industry in the 1990s.
A notable outcome of this was the creation of MySQL in 1995, which was open source. This
meant that it provided an alternative to the database systems offered by big companies like
Oracle and Microsoft. MySQL is still used by many today.
THE IMPORTANCE OF DATABASE
✔ Store essential data
, such sales, order processing and customer service. They analyze that data to improve
user information, such as names, email addresses and user behavior. The data is used to
4. STORE PERSONAL DATA -Databases can also be used to store personal information.
For example, personal cloud storage is available for individual users to store media, such as
✔ Unsecured data
✔ Non-database schema
✔ Fraud/Cheating
DIGITAL ELECTION
✔ Accurate information
✔ Fast Transaction
212 HECTARES
GOOGLE
▪ Google gets over 3.5 billion searches daily.
Google remains the highest shareholder of the search
engine market, with 87.35% of the global search
engine market share as of January 2020. Big Data stats
for 2020 show that this translates into 1.2 trillion
searches yearly, and more than 40,000 search
queries per second.
GOOGLE DATA CENTER
20 HECTARES
WHATSAPP
▪ WhatsApp users exchange up to 65 billion
messages daily.
5 million businesses are actively using the WhatsApp
Business app to connect with their customers.
ACTIVITY 1. (20 pts)
From your own perspective, make an analogy
between DBMS and database programming.
Written Quiz
WEEK 3 and 4
WEEK 3
AGENDA
I. SQL
II. DATABASE
III. RELATIONAL DATABASE
SQL, WHO DISCOVER?
▪ The SQL programming language was developed in the 1970s by IBM
researchers Raymond Boyce and Donald Chamberlin.
1. Go to https://www.mysql.com/
2. Click DOWNLOADS
3. Find and Click MySQL Community (GPL) Downloads
4. Find and Click MySQL Installer for Windows
5. Click Windows (x86, 32-bit), MSI Installer 8.0.32 (2.4MB)
6. Find and Click No thanks, just start my download.
7. The file directly download
Practical Assessment
( Individual Installation of SQL workbench)
WEEK 5 and 6
WEEK 5
AGENDA
I. CREATE DATABASE
II. USE DATABASE
III. INSERT INTO
IV. DROP DATABASE
V. SQL SELECT
SQL STATEMENTS
▪ A statement is a command to be understood by the interpreter and executed by the SQL
engine.
SQL COMMANDS
▪ It is used to communicate with the
database. It is also used to perform specific
tasks, functions, and queries of data. SQL can
perform various tasks like create a table, add
data to tables, drop the table, modify the
table, set permission for users.
SQL CREATE DATABASE
▪ The SELECT statement is used to select data from a database. The data returned is stored
in a result table, called the result-set.
SELECT * FROM table_name;
DATABASE TABLES
▪ Tables are essential objects in a database because they hold all the information or data.
For example, a database for a business can have a Contacts table that stores the names of
their suppliers, e-mail addresses, and telephone numbers.
SQL CREATE TABLE
▪ The CREATE TABLE statement is used to create a new table in a database.
CREATE TABLE Persons (
PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);
SQL INSERT INTO
▪ The CREATE TABLE statement is used to create a new table in a database.
SELECT * FROM table_name;
SQL SELECT TOP
▪ The SELECT TOP clause is useful on large tables with thousands of records. Returning a
large number of records can impact performance.
SELECT TOP 3 * FROM Customers;
SELECT * FROM Customers
LIMIT 3;
SQL WHERE
▪ The WHERE clause is used to filter records.
SELECT column1, column2, ...
FROM table_name
WHERE condition;
WEEK 6
SQL BACKUP DB
▪ The BACKUP DATABASE statement is used in SQL Server to create a full back up of an
existing SQL database.
BACKUP DATABASE databasename
TO DISK = 'filepath';;
SQL DROP DB
▪ The DROP TABLE statement is used to drop an existing table in a database.
DROP TABLE table_name;
SQL ALTER TABLE
▪ The ALTER TABLE statement is used to add, delete, or modify columns in an existing
table.
ALTER TABLE Customers
ADD Email varchar(255);
SQL CREATE CONSTRAINTS
▪ Constraints can be specified when the table is created with the CREATE TABLE statement,
or after the table is created with the ALTER TABLE statement.
CREATE TABLE table_name (
column1 datatype constraint,
column2 datatype constraint,
column3 datatype constraint,
....
);
SQL NOT NULL CONSTRAINT
▪ The NOT NULL constraint enforces a column to NOT accept NULL values.
This enforces a field to always contain a value, which means that you cannot insert a new
record, or update a record without adding a value to this field.
CREATE TABLE table_name (
column1 datatype constraint,
column2 datatype constraint,
column3 datatype constraint,
....
);
SQL UNIQUE CONSTRAINT
▪ The UNIQUE constraint ensures that all values in a column are different.
CREATE TABLE Persons (
ID int NOT NULL UNIQUE,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int
);
SQL PRIMARY KEY
▪ The PRIMARY KEY constraint uniquely identifies each record in a table. Primary keys
must contain UNIQUE values, and cannot contain NULL values.
CREATE TABLE Persons (
ID int NOT NULL UNIQUE,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int
);
SQL FOREIGN KEY
▪ The FOREIGN KEY constraint is used to prevent actions that would destroy links between
tables
CREATE TABLE Orders (
OrderID int NOT NULL,
OrderNumber int NOT NULL,
PersonID int,
PRIMARY KEY (OrderID),
FOREIGN KEY (PersonID) REFERENCES Persons(PersonID)
);
SQL AUTO INCREMENT
▪ Auto-increment allows a unique number to be generated automatically when a new record is
inserted into a table.
CREATE TABLE Persons (
Personid int NOT NULL AUTO_INCREMENT,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
PRIMARY KEY (Personid)
);
Practical Assessment
( Hands on Assessment)
WEEK 7 and 8
WEEK 7
SQL MIN AND MAX
▪ The MIN() function returns the smallest value of the selected column.
▪ The MAX() function returns the largest value of the selected column.
SELECT MIN(column_name)
FROM table_name
WHERE condition;
SELECT MAX(column_name)
FROM table_name
WHERE condition;
SQL COUNT(), AVG() and SUM() Functions
▪ The COUNT() function returns the number of rows that matches a specified criterion.
SELECT MIN(column_name)
FROM table_name
WHERE condition;
SELECT MAX(column_name)
FROM table_name
WHERE condition;
SQL LIKE
▪ The LIKE operator is used in a WHERE clause to search for a specified pattern in a
column.
▪ Let's lookOrders.OrderID,
SELECT at a selection from the "Orders" table:.
Customers.CustomerName,
Orders.OrderDate
FROM Orders
INNER JOIN Customers
ON Orders.CustomerID=Customers.CustomerID;
SQL JOIN
▪ A JOIN clause is used to combine rows from two or more tables, based on a related column
between them.
▪ Let's lookOrders.OrderID,
SELECT at a selection from the "Orders" table:.
Customers.CustomerName,
Orders.OrderDate
FROM Orders
INNER JOIN Customers
ON Orders.CustomerID=Customers.CustomerID;