Database
Database
Database
Chapter 9
L.O: Define a single-table database from given
data storage requirements
• Keywords
• Database
• table
• Records (Rows)
• Fields (column)
What is a Database?
✓ A database is a collection of data stored in a logical and ordered manner. Databases
can be both electronic or paper-based
✓ Data is stored in tables consisting of records and fields
✓ A database with a single table is known as a flat-file database. Databases with multiple
tables are known as relational databases
✓ A record is a collection of data about one single item in a database
✓ Each database field must be given a datatype
✓ Tables need a primary key so records are unique and can be identified quickly.
✓ A search for data is known as a query
✓ SQL is a programming language that is used to maintain databases to create queries.
What are Databases used for?
A Database is a structured collection of data that allow information to
be easily extracted based on the conditions
Databases are useful in preventing data problems because data is only
stored once there is no duplication and the stored data is more consistent
Example Database:
• School records – data about students – parents’ occupation, illness, year/grade, etc.
• Exam results – candidates’ exam results
Customer Table: Example for Single table Database (Datasheet View)
Customer_ID CustomerName Address City PostalCode Country
1 Alfred Obere Str. 57 Berlin 12209 Germany
A primary key is a column or a group of columns in a table that uniquely identifies the rows of data in
that table.
For example, in the table below, CustomerID, which displays the ID number assigned to different
customers, is the primary key
Which of the following fields is NOT suitable for a primary key in a database?
A. An automatic number field
B. A student’s registration number
C. A Bank account number
D. Date of Birth
2018 May/ June paper 2
Question 5
Types of Data in the Table:
– SELECT
– FROM
– WHERE
– ORDER BY
– SUM
– COUNT
• Identifying the output given by an SQL statement that will query the given contents of a database table
SELECT Statement
• 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 Syntax
For example;
SELECT CustomerName, City, Country FROM Customers;
WHERE Syntax:
Operator Description
= Equal
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
<> Not equal. Note: In some versions of SQL this operator may be written as !=
SELECT… FROM… WHERE- Examples with relational operators
Produ ProductName Supp Catego Price
SELECT * FROM Products WHERE Price = 18; ctID lierID ryID
CatNo
It is a unique identifier
The AND and OR operators are used to filter records based on more than one condition:
The AND operator displays a record if all the conditions separated by AND are TRUE.
The OR operator displays a record if any of the conditions separated by OR is TRUE.
Syntax
SELECT column1, column2, ... FROM table_name
WHERE condition1 AND condition2 AND condition3 ...;