Updated Chapter 3 Database SQL
Updated Chapter 3 Database SQL
Updated Chapter 3 Database SQL
• Tables:
• A table is a collection of related data held in a
structured format within a database. It consists of rows
and columns.
• Each table has a unique name that identifies it within customer_id name email phone_number
the database. John
1 john@example.com 123-456-7890
• A database most often contains one or more tables. Doe
• Rows: 2
Jane
jane@example.com 987-654-3210
• Rows, also known as records or tuples, represent Smith
individual entries in the table. Each row in a table is a Bob
3 bob@example.com 555-666-7777
unique instance of data. Brown
• Columns:
• also known as fields or attributes, represent the
structure of the data in the table. Each column has a
specific data type and contains all the information of a
single type.
SQL Basics – Data types
1. Numeric data types (INT, TINYINT, BIGINT, FLOAT, REAL, etc.)
2. Date and Time data types (DATE, TIME, DATETIME, etc.)
3. Character and String data types (CHAR, VARCHAR, TEXT, etc.)
4. Unicode character string data types (NCHAR, NVARCHAR, NTEXT, etc.)
5. Binary data types (BINARY, VARBINARY, etc.)
6. Miscellaneous data types (CLOB, BLOB, XML, CURSOR, TABLE, etc.)
SQL Basics – Data types Numeric Data Types
DATE Stores date values (year, month, day). DATE birthdate = '1990-01-01';
TIME Stores time values (hour, minute, second). TIME startTime = '13:45:30';
DATETIME Stores date and time values. DATETIME event = '2023-08-07 12:00:00';
Change to
Data Manipulation Language (DML)
• DELETE:
• One or more rows can be deleted from a database table using the DELETE statement in SQL.
• The data records are not permanently deleted. A DELETE command can always be reversed by using a rollback action.
• The following is the syntax for writing a DELETE statement:
• Performing DELETE query to the Customers table where the customer name is Matt Gregory:
Data Manipulation Language (DML)
• DELETE:
Change to
SQL Query (Select statement)
Select Query
• It is used to retrieve information from the database.
• Select statement doesn’t change the database; it just retrieves the data.
Simple Select Query
Product PName Price Category Manufacturer
Gizmo $19.99 Gadgets GizmoWorks
Powergizmo $29.99 Gadgets GizmoWorks
SingleTouch $149.99 Photography Canon
MultiTouch $203.99 Household Hitachi
SELECT
SELECT **
FROM
FROM Product
Product
WHERE
WHERE category=‘Gadgets’
category=‘Gadgets’
SELECT
SELECT <attributes>
<attributes>
FROM
FROM <oneorormore
<one morerelations>
relations>
WHERE
WHERE <conditions>
<conditions>
Select Query
Assume that we have the following table:
Output:
Select Query
Output:
Select Query
Output:
Select Query
• You can apply several select queries.
• The reserved words (e.g., select, update, delete…etc.) are not case-sensitive.
• Select stamen doesn’t change the database; it just retrieves the data.
The End
Thanks!