Introduction to SQL
(SQL - Structured Query Language)
• SQL is a programming language designed to manage data stored in a
Relational Database Management System (RDBMS).
• SQL is simple, easy to understand and a user-friendly language.
• SQL is mainly for the users who perform ad-hoc queries and generate
reports.
• SQL is a declarative language; therefore, its syntax reads like a natural
language.
• An SQL statement begins with a verb that describes the action, for
example, SELECT, INSERT, UPDATE or DELETE.
1
Introduction to SQL
(SQL - Structured Query Language)
• Following the verb are the subject and predicate.
• As you see below example, it reads like a normal sentence.
• Get the first names of employees who were hired in 2000.
2
Introduction to SQL
SQL consists of
• Data Definition Language (DDL)
• Data Manipulation Language (DML)
• Data Control Language (DCL)
3
DDL (Data Definition Language)
The data definition language deals with the schema creation and
modification.
e.g., CREATE TABLE statement allows you to create a new table in the
database
and the ALTER TABLE statement changes the structure of an existing
table.
4
DML (Data Manipulation Language)
The data manipulation language provides the constructs to query data
such as the SELECT statement and to update the data such as INSERT,
UPDATE, and DELETE statements.
5
DCL (Data Control Language)
The data control language consists of statements that deal with user
authorization and security ;
such as GRANT and REVOKE statements.
* DCL is out of scope for our Data Analytics Course.
6
SQL Terminologies
• SQL is made up of many commands. SQL uses the semicolon (;) to
mark the end of a command.
• Each command is composed of tokens that can be literals, keywords,
identifiers, or expressions. Tokens are separated by space, tabs, or
newlines.
• Literals are explicit values which are also known as constants. SQL
provides three kinds of literals: string, numeric, and binary.
• SQL has many keywords that have special meanings such as SELECT,
INSERT, UPDATE, DELETE, and DROP.
7
SQL Terminologies
• These keywords are the reserved words; therefore, you cannot use
them as the name of tables, columns, indexes, views, stored
procedures, triggers, or other database objects.
• Identifiers refer to specific objects in the database such as tables,
columns, indexes, etc.
• SQL is case-insensitive with respect to keywords and identifiers.
• To document SQL statements, you use the SQL comments. When
parsing SQL statements with comments, the database engine ignores
the characters in the comments.
8
Sample HR Database
9
Sample HR Database
• The HR sample database has seven tables:
• The employees table stores the data of employees.
• The jobs table stores the job data including job title and salary range.
• The departments table stores department data.
• The dependents table stores the employee’s dependents.
• The locations table stores the location of the departments of the company.
• The countries table stores the data of countries where the company is
doing business.
• The regions table stores the data of regions such as Asia, Europe, America,
and the Middle East and Africa. The countries are grouped into regions.
10