0% found this document useful (0 votes)
12 views28 pages

Database

The document provides an overview of databases, explaining their structure including tables, records, fields, and keys such as primary and foreign keys. It also covers SQL (Structured Query Language) functions like COUNT, SUM, and operators like BETWEEN, LIKE, and IN, with examples for each. The content serves as a foundational guide for understanding database concepts and SQL operations.

Uploaded by

jakeisaloman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views28 pages

Database

The document provides an overview of databases, explaining their structure including tables, records, fields, and keys such as primary and foreign keys. It also covers SQL (Structured Query Language) functions like COUNT, SUM, and operators like BETWEEN, LIKE, and IN, with examples for each. The content serves as a foundational guide for understanding database concepts and SQL operations.

Uploaded by

jakeisaloman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

Topic: Database

Database
Why are database Useful?
What are database used for?
Database Object
Table
The table contains all of the fields and the records for one type of entity. A database
may contain more than one table.

Records
Records contain a collection of data for each entity, usually recorded as a row in the
table.

Fields
The column headings are called the fields. Each field contains a different attribute.
Database Keys
Primary Key
The Primary key contains a unique identifier for each record. To make each record in a database unique we
normally assign them a primary key. Even if a record is deleted from a database, the primary key will not be
used again. The primary key can be automatically generated and will normally just be a unique number or
mix of numbers and letters.
Foreign Key
A foreign key is a field in one table that uniquely identifies a row of another table. In simpler words,
the foreign key is defined in a second table, but it refers to the primary key or a unique key in the first
table.
Basic Database
What is Data Type?
Data Types Description
SQL(Structured Query Language)
SQL Script
SQL Query Statement
SQL Structure
Example of SQL Statement
Example of SQL Statement
Operators Used in SQL QUERY
Example 1:Display Consultant’s
Patients
Example 1:Display Consultant’s
Patients in alphabetic Order
SQL Count()Function
The Count function returns the no of rows that matches specific Criteria.

Count() Syntax:

SELECT COUNT(column_name)
FROM table_name
WHERE condition;

Note: NULL values are not counted.


Example of Count() Function
Below is a selection from the "Products" table in the Northwind sample database:

SQL Statement:
SELECT COUNT(ProductID)
FROM Products
WHERE ProductID>2;
SQL SUM()Function
The SUM() function returns the total sum of a numeric column.

SUM()Syntax
SELECT SUM(column_name
)
FROM table_name
WHERE condition;
Example of SUM() Function
Below is a selection from the "OrderDetails" table in the Northwind sample database:

The following SQL statement finds the sum of the "Quantity" fields in the "OrderDetails"
table:
SQL Statement:

SELECT SUM(Quantity)
FROM OrderDetails;
SQL Between Operator
The BETWEEN operator selects values within a given
range. The values can be numbers, text, or dates.
The BETWEEN operator is inclusive: begin and end
values are included.

Between Syntax:
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value
2;
BETWEEN Example

Example:
SELECT * FROM Products
WHERE Price BETWEEN 10 AND 20;
SQL LIKE Operator
The LIKE operator is used in a WHERE clause to search for a specified pattern in a
column.

LIKE Syntax
SELECT column1, column2, ...
FROM table_name
WHERE columnN LIKE pattern;
SQL LIKE Example

The following SQL statement selects all customers with a CustomerName starting with
"a":
SELECT * FROM Customers
WHERE CustomerName LIKE 'a%';
The following SQL statement selects all customers with a CustomerName ending with "a":
SELECT * FROM Customers
WHERE CustomerName LIKE '%a';
SQL IN Operator
The IN operator allows you to specify multiple values in a WHERE clause.

IN Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1, value2, ..
.);
SQL IN Operator Example

Example:
SELECT * FROM Customers
WHERE Country IN ('Germany','UK');

You might also like