Home Tutorials SQL Tutorial SQL Basics
SQL Basics

SQL Basics


SQL Syntax Basics

Definition: SQL syntax is the set of rules by which a SQL statement is structured and interpreted. It uses specific English-like keywords to tell the database exactly what action to perform.

Approach: Beginner SQL guides emphasize a simple, vertical statement structure. This "step-by-step" formatting makes queries easier to read, debug, and maintain as they become more complex.


Basic Statement Structure

The most fundamental query in SQL is the SELECT statement, which follows this standard order:

SELECT column_name
FROM table_name;
    

Core Keywords

  • SELECT: Tells the database which specific columns (fields) you want to see.
  • FROM: Identifies which table the data is located in.
  • WHERE: Acts as a filter to only show records that meet certain criteria.
  • ORDER BY: Sorts the final results in ascending or descending order.

Formatting Guidelines

Rule Description
Uppercase Keywords While SQL is not case-sensitive, keywords (like SELECT) are commonly written in UPPERCASE to distinguish them from table and column names.
Semicolons (;) Most database systems require a semicolon at the end of each SQL statement to signal that the command is complete.
Identifiers Table and column names (identifiers) are defined when the database is designed and must match the database schema exactly.

Key Notes

  • Whitespace: SQL ignores extra spaces and line breaks. You can write a query on one line, but using multiple lines (as shown in the example) is the professional standard for readability.
  • Selecting Everything: If you want to view every column in a table without listing them individually, you can use the asterisk symbol: SELECT * FROM table_name;.

🏋️ Test Yourself With Exercises

Take our quiz on SQL Basics to test your knowledge.

Browse Quizzes »