You are on page 1of 12

Reviewing SQL concepts

Prof. Hitesh Mohapatra


Introduction to SQL
SQL is a standard language for storing,
manipulating and retrieving data in databases.

How to pronounce SQL properly? S-Q-L or Sequel?


According to Wikipedia:
SQL was initially developed at IBM by Donald D.
Chamberlin and Raymond F. Boyce after learning
about the relational model from Ted Codd in the
early 1970s. This version, initially called SEQUEL
(Structured English Query Language), was designed
to manipulate and retrieve data stored in IBM’s
original quasi-relational database management
system, System R, which a group at IBM San Jose
Research Laboratory had developed during the
1970s.
What is SQL?
• SQL stands for Structured Query Language
• SQL lets you access and manipulate databases
• SQL became a standard of the American
National Standards Institute (ANSI) in 1986,
and of the International Organization for
Standardization (ISO) in 1987.
What Can SQL do?
• SQL can execute queries against a database
• SQL can retrieve data from a database
• SQL can insert records in a database
• SQL can update records in a database
• SQL can delete records from a database
• SQL can create new databases
• SQL can create new tables in a database
• SQL can create stored procedures in a database
• SQL can create views in a database
• SQL can set permissions on tables, procedures, and views
SQL Syntax
A database most often contains one or more tables.
Each table is identified by a name (e.g. "Customers" or
"Orders"). Tables contain records (rows) with data.

*The table above contains five records (one for each customer) and seven columns (CustomerID, CustomerName,
ContactName, Address, City, PostalCode, and Country).
SQL Statements
Most of the actions you need to perform on a
database are done with SQL statements.
The following SQL statement selects all the
records in the "Customers" table:

SELECT * FROM Customers;

SQL keywords are NOT case sensitive: select is the same as SELECT
Semicolon after SQL Statements?
• SELECT - extracts data from a database
• UPDATE - updates data in a database
• DELETE - deletes data from a database
• INSERT INTO - inserts new data into a database
• CREATE DATABASE - creates a new database
• ALTER DATABASE - modifies a database
• CREATE TABLE - creates a new table
• ALTER TABLE - modifies a table
• DROP TABLE - deletes a table
• CREATE INDEX - creates an index (search key)
• DROP INDEX - deletes an index
SQL 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
Here, column1, column2, ... are the field names
of the table you want to select data from. If
SELECT column1, column2, ... you want to select all the fields available in the
FROM table_name; table, use the following syntax:

SELECT * FROM table_name;


SELECT Column Example
The following SQL statement selects the
"CustomerName" and "City" columns from the
"Customers" table:
SELECT CustomerName, City FROM Customers;

SELECT * Example
The following SQL statement selects all the columns from the "Customers" table:

SELECT * FROM Customers;


SQL WHERE Clause
The WHERE clause is used to filter records.
The WHERE clause is used to extract only those
records that fulfill a specified condition.

WHERE Syntax
SELECT column1, column2, ... Example:
FROM table_name SELECT * FROM Customers
WHERE condition; WHERE Country='Mexico';

You might also like