Database

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

Database

Database:
A database is a well-organized compilation of data
that enables individuals to retrieve information
according to their specific requirement.
Data in a database can be any type of data
including text, images, videos, sound.
Why do we need a database?

● To store data about people, things, and events.


● Any modifications or additions need to be made only once, ensuring data
consistency.
● All users access and utilize the same set of data, promoting uniformity.
● Relational databases store data in a non-repetitive manner, eliminating
duplication.
● Data is stored in tables in databases. Each table consists of a specific type of
data e.g. cars. These tables HAVE to be named according to what they contain
e.g. a table containing patient information will be PATIENT
● These tables consist of records (rows). Each record consists of data about a
single entity (a single item, person or event ) e.g. a single car
● These tables also have columns that are known as fields. These consist of
specific information regarding the entities that are written later in records e.g. car
name, car manufacturer etc.
● A single-table database contains only one table.
Example

SELECT Name,Genre, Certificate, Rating

FROM Movie

ORDER BY Name ASC

● The results of this query would be:


Validation and Verification

● Verification checks check whether the data that has been entered is the correct
data and is accurate
● This is often completed by getting data entered by one person is then checked by
another person
● When a table is created, validation rules can be assigned to the different fields
● A validation rule controls what data can be entered into that field.
● There are different types of validation checks used to limit what data can be
entered into each field
Data Type
Each field will require a data type to be selected. A data
type classifies how the data is stored, displayed and the
operations that can be performed on the stored value.
Primary Key
SQL(Structured Query Language
● Structured Query Language (SQL) is the standard language for writing scripts
to retrieve valuable information from databases.
● Records in a database can be searched and data can be manipulated using
Structured Query Language (SQL)
● SQL statements can be written to query the data in the database and extract
useful information
● SQL statements follow this structure:
○ SELECT the fields you want to display
○ FROM the table/tables containing the data you wish to
search
○ WHERE the search criteria

SELECT * – this specifies that all fields (columns) are to be shown.


SQL Operators
ORDER BY
ORDER BY Field1, Field2, etc. – this specifies a sort in ascending or

alphabetical order starting with the first field.

ORDER BY Field1, Field2 DESC – this specifies a sort in descending or

reverse alphabetical order starting with the first field.


Example

SELECT Name, Rating

FROM Movie

WHERE Rating>8.4;

Example

SELECT Name, Rating

FROM Movie

WHERE Rating>8.4;
SELECT Name, Genre, Certificate, Rating

FROM Movie

ORDER BY Genre ASC, Rating DESC;


A SUM statement takes the form:

SELECT SUM (Field) – this specifies the field (column) for the
calculation.

The field should be integer or real.

A COUNT statement takes the form:

SELECT COUNT (Field) – this specifies the field (column) to count if


the given criteria is met.
Example

SELECT SUM(QuantityInStock)

FROM ProductTable;

● This query will add up all of the


numbers in the QuantityInStock
field
○ The result of this query
would be 25

Example

SELECT COUNT(*)

FROM ProductTable

WHERE Price>2;

● This query will count all the


records with a price greater than 2
○ The result of this query
would be 3
SELECT COUNT(*)
SELECT COUNT(*)
FROM Students
FROM Students;
WHERE Age > 20;

Result:2
Result :5
SELECT COUNT(Name)

FROM Students;

Result :5

You might also like