0% found this document useful (0 votes)
33 views

What Is SQL?: Database Background

SQL is a standard language used to communicate with relational database management systems. It allows users to store, manipulate, and retrieve data held in relational databases. Some key aspects of SQL include: 1) SQL allows users to easily find, sort, and select specific data from database tables using commands like SELECT, WHERE, and ORDER BY. 2) Relational databases organize data into tables which can be related through common fields. This allows for flexible data retrieval. 3) Popular relational database systems like MySQL, SQL Server, Oracle, etc. use SQL as their standard language to interface with the database.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

What Is SQL?: Database Background

SQL is a standard language used to communicate with relational database management systems. It allows users to store, manipulate, and retrieve data held in relational databases. Some key aspects of SQL include: 1) SQL allows users to easily find, sort, and select specific data from database tables using commands like SELECT, WHERE, and ORDER BY. 2) Relational databases organize data into tables which can be related through common fields. This allows for flexible data retrieval. 3) Popular relational database systems like MySQL, SQL Server, Oracle, etc. use SQL as their standard language to interface with the database.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

What is SQL?

 Stands for structured Query Language


 is a computer language for storing, manipulating and retrieving data
stored in relational database.

Database Background

Originally, databases were flat. This means that the information was stored
in one long text file, called a tab delimited file. Each entry in the tab
delimited file is separated by a special character, such as a vertical bar (|).
Each entry contains multiple pieces of information (fields) about a particular  allows you to easily find specific information.
object or person grouped together as a record. The text file makes it difficult
 It also allows you to sort based on any field and generate
to search for specific information or to create reports that include only
reports that contain only certain fields from each record.
certain fields from each record. Here's an example of the file created by a
flat database:  use tables to store information.
Lname, FName, Age, Salary|dela Cruz, Juan, 35, 15000|Doe, Jane, 28,
 The standard fields and records are represented as columns
13589|Brown, Scott, 41, 19290|Manalo, Ronnel, 48, 20000|Taylor, Swift,
(fields) and rows (records) in a table.
22, 12990
 you can quickly compare information because of the
You can see that you have to search sequentially through the entire file arrangement of data in columns.
to gather related information, such as age or salary.
SQL is the standard language for Relation Database System
What is Relational DBase?
Relational databases are created using a special computer language,
is a collection of data items organized as a set of formally structured query language (SQL), that is the standard for database
described tables from which data can be accessed easily. interoperability. SQL is the foundation for all of the popular database
applications available today

LName FName Age Salary All relational database management systems like

dela Cruz Juan 35 15,000  MySQL,


 MS Access,
Doe Jane 28 13,589
 Oracle,
Brown Scott 41 19,290
 Sybase,
Manalo Ronnel 48 20,000

Taylor Swift 22 12,990


 Informix, It is very important to understand that a NULL
value is different than a zero value or a field
 postgres and that contains spaces. A field with a NULL value
is one that has been left blank during record
creation.
 SQL Server uses SQL
o Constraints - are the rules enforced on data
as standard database language. columns on table. These are used to limit the
type of data that can go into a table. This
Understanding SQL ENVIRONMENT ensures the accuracy and reliability of the data
in the database.
 Server
 Objects Understanding data

 Database

 Objects

 Tables - table is the most common and simplest


form of data storage in a relational database

 Table Parts
SQL Commands
o Field - is a column in a table that is designed
o DQL - Data Query Language
to maintain specific information about every
record in the table Command Description
SELECT Retrieves certain records from one or more tables
o Row / Record - is a horizontal entity in a
table.
o DML - Data Manipulation Language
o Column - is a vertical entity in a table that Command Description
contains all information associated with a INSERT Creates a record
specific field in a table. UPDATE Modifies records
DELETE Deletes records

o Null Value - A NULL value in a table is a


value in a field that appears to be blank o DDL - Data Definition Language
which means A field with a NULL value is a
field with no value. Command Description
CREATE Creates a new table, a view of a table, or other object in database
ALTER Modifies an existing database object, such as a table.  SELECT TOP n column_name(s) FROM table_name
DROP Deletes an entire table, a view of a table or other object in the
database.

SQL is followed by unique set of rules and guidelines called


Syntax. This tutorial gives you a quick start with SQL by
listing all the basic SQL Syntax:
-------------------------------SELECT Statement -----------------------
 SELECT * FROM table_name

SELECT * FROM StockRoomBalance

 SELECT column_name(s) FROM table_name -----------------------WHERE Clause ----------------------------


SELECT cStockroomcode, cItemcode, nstockissunitsphysical  Used to specify a condition to filter the records and fetching only
necessary records.
FROM StockRoomBalance
 Not only used in SELECT statement, but it is also used in UPDATE,
DELETE statement etc.

 SELECT column_name(s)
FROM table_name
WHERE column_name operator value

 SELECT DISTINCT column_name(s) FROM table_name


SQL Operation Operators Description
NOT The NOT operator reverses the meaning of the
An operator is a reserved word or a character used primarily in an SQL logical operator which it is used.
statement's WHERE clause to perform operation(s), such as Eg. NOT BETWEEN, NOT IN, etc.
comparisons and arithmetic operations. Practice
Operators are used to specify conditions in an SQL statement and to
serve as conjunctions for multiple conditions in a statement. o Arithmetic operators

o Comparison Operators Operators Description Example


+ Addition Adds values on either side of 10 + 20
Operators the operator will give 30
= Equal - Subtraction Subtracts right hand operand 10 - 20
from left hand operand will give -10
!= or <> NOT Equal
* Multiplication Multiplies values on either 10 * 20
> Greater Than side of the operator will give 200
< Less Than / Division Divides left hand operand by 20 / 10
>= Greater Than Equal right hand operand and will give 2
<= Less Than Equal returns remainder
Practice % Modulus Divides left hand operand by 20 % 10
right hand operand and will give 0
returns remainder
SQL uses single quotes around text values. However, numeric values Practice
should not be enclosed in quotes.
---------------------ORDER BY Clause---------------------
 SELECT column_name(s)
o Logical Operators
FROM table_name
Operators Description ORDER BY column_name(s) ASC|DESC
AND The AND operator allows the existance of multiple conditions in an
SQL statement's WHERE clause.
BETWEEN The Between operator is used to search for values that are within
a set of values, given the minimum value and the maximum value.
IN The IN operator is used to compare a value to a list of literal
values that have been specified
LIKE The LIKE operator is used to compare a value to similar values
using wildcard operators.
OR The OR operator is used to combine multiple conditions in an SQL
statement's WHERE clause.
IS NULL The NULL operator is used to compare a value with a NULL value.

Practice

o Operators used to negate conditions


 MIN() - Returns the smallest value

 SUM() - Returns the sum

SQL Scalar functions

SQL scalar functions return a single value, based on the input value.

Useful scalar functions:

 UCASE() - Converts a field to upper case


 LCASE() - Converts a field to lower case

 MID() - Extract characters from a text field

 LEN() - Returns the length of a text field


------------- SQL Functions-----------------------------  ROUND() - Rounds a numeric field to the number of decimals
specified
SQL has many built-in functions for performing calculations on data.
 NOW() - Returns the current system date and time

 FORMAT() - Formats how a field is to be displayed


SQL Aggregate Functions

SQL aggregate functions return a single value, calculated from values


in a column. -------------------------- INSERT INTO Statement----------
The SQL Aggregate Functions are useful when mathematical
operations must be performed on all or a grouping of values.

Useful aggregate functions:

 AVG() - Returns the average value


 COUNT() - Returns the number of rows

 MAX() - Returns the largest value


All the SQL statements start with any of the keywords like
SELECT, INSERT, UPDATE, DELETE, ALTER, DROP,
CREATE, USE, SHOW

You might also like