Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

SQL Syntax

SQL Statements

The majority of database operations are executed using SQL statements, which are comprised of easily comprehensible keywords.

Below is an SQL statement that retrieves all records from a table named “Customers”:

Example

Retrieve all entries from the Customers table.

SELECT * FROM Customers;

This tutorial will comprehensively cover various SQL statements.

Database Tables

A typical database comprises one or more tables, each identified by a name (e.g., “Customers” or “Orders”), and holds records (rows) containing data.

In this tutorial, we will utilize the widely recognized Northwind sample database (available in MS Access and MS SQL Server).

Displayed below is a portion of the Customers table referenced in the examples:

CustomerID

CustomerName

ContactName

Address

City

PostalCode

Country

1

Alfreds Futterkiste

Maria Anders

Obere Str. 57

Berlin

12209

Germany

2

Ana Trujillo Emparedados y helados

Ana Trujillo

Avda. de la Constitución 2222

México D.F.

05021

Mexico

3

Antonio Moreno Taquería

Antonio Moreno

Mataderos 2312

México D.F.

05023

Mexico

4

Around the Horn

Thomas Hardy

120 Hanover Sq.

London

WA1 1DP

UK

5

Berglunds snabbköp

Christina Berglund

Berguvsvägen 8

Luleå

S-958 22

Sweden

The displayed table comprises five records, each representing a distinct customer, and includes seven columns: CustomerID, CustomerName, ContactName, Address, City, PostalCode, and Country.

Keep in Mind That…

  • SQL keywords exhibit case insensitivity; hence, “select” is equivalent to “SELECT”.

Throughout this tutorial, we will render all SQL keywords in uppercase.

Semicolon after SQL Statements?

Certain database systems mandate a semicolon at the conclusion of each SQL statement.

The semicolon serves as the conventional means of delimiting individual SQL statements in systems permitting the execution of multiple SQL statements within the same server call.

Throughout this tutorial, we will adhere to using a semicolon at the conclusion of each SQL statement.

Some of The Most Important SQL Commands

  • SELECT: Retrieves data from a database.
  • UPDATE: Modifies existing data in a database.
  • DELETE: Removes data from a database.
  • INSERT INTO: Adds new data into a database.
  • CREATE DATABASE: Establishes a new database.
  • ALTER DATABASE: Adjusts the structure of a database.
  • CREATE TABLE: Generates a new table.
  • ALTER TABLE: Modifies the structure of a table.
  • DROP TABLE: Eliminates a table from the database.
  • CREATE INDEX: Establishes an index, facilitating efficient data retrieval.
  • DROP INDEX: Removes an index from the database.