Light Mode Image

SQL Syntax

Structured Query Language (SQL) is a programming language designed for managing and manipulating relational databases.

Here are some common SQL syntax elements.

  1. SELECT Statement:

    • Retrieves data from one or more tables.
    SELECT column1, column2, ...
    FROM table_name
    WHERE condition;
  2. INSERT Statement:

    • Inserts new records into a table.
    INSERT INTO table_name (column1, column2, ...)
    VALUES (value1, value2, ...);
  3. UPDATE Statement:

    • Modifies existing records in a table.
    UPDATE table_name
    SET column1 = value1, column2 = value2, ...
    WHERE condition;
  4. DELETE Statement:

    • Deletes records from a table.
    DELETE FROM table_name
    WHERE condition;
  5. CREATE TABLE Statement:

    • Creates a new table with specified columns and data types.
    CREATE TABLE table_name (
        column1 datatype1,
        column2 datatype2,
        ...
    );
  6. ALTER TABLE Statement:

    • Modifies an existing table structure.
    ALTER TABLE table_name
    ADD column_name datatype;
  7. DROP TABLE Statement:

    • Deletes an existing table and its data.
    DROP TABLE table_name;
  8. SELECT DISTINCT:

    • Retrieves unique values in a specified column.
    SELECT DISTINCT column_name
    FROM table_name;
  9. WHERE Clause:

    • Filters records based on a specified condition.
    SELECT column1, column2, ...
    FROM table_name
    WHERE condition;
  10. ORDER BY Clause:

    • Sorts the result set based on one or more columns.
    SELECT column1, column2, ...
    FROM table_name
    ORDER BY column1 [ASC|DESC], column2 [ASC|DESC], ...;

These are some basic SQL syntax elements, and there are many more advanced features and clauses that can be used depending on the database system you are working with.