Basic SQL Commands

SQL (Structured Query Language) is a domain-specific language used for managing and querying relational databases. 



Here are some of the most basic SQL commands you'll use to interact with a database:

  1. SELECT: Used to retrieve data from one or more tables.

    SELECT column1, column2
    FROM table_name
    WHERE condition;
    
  2. INSERT: Used to add new records (rows) to a table.

    INSERT INTO table_name (column1, column2)
    VALUES (value1, value2);
    
  3. UPDATE: Used to modify existing records in a table.

    UPDATE table_name
    SET column1 = value1, column2 = value2
    WHERE condition;
    
  4. DELETE: Used to remove records from a table.

    DELETE FROM table_name
    WHERE condition;
    
  5. CREATE TABLE: Used to create a new table in the database.

    CREATE TABLE table_name (
        column1 datatype,
        column2 datatype,
        ...
    );
    
  6. ALTER TABLE: Used to modify an existing table (e.g., add, modify, or delete columns).

    ALTER TABLE table_name
    ADD column_name datatype;
    
    ALTER TABLE table_name
    MODIFY column_name new_datatype;
    
    ALTER TABLE table_name
    DROP COLUMN column_name;
    
  7. DROP TABLE: Used to delete an existing table and all of its data.

    DROP TABLE table_name;
    
  8. CREATE DATABASE: Used to create a new database.

    CREATE DATABASE database_name;
    
  9. USE: Used to select a specific database to work with.

    USE database_name;
    
  10. SHOW DATABASES: Used to list all available databases.

    SHOW DATABASES;
    
  11. SHOW TABLES: Used to list all tables in the current database.

    SHOW TABLES;
    
  12. SELECT DISTINCT: Used to retrieve unique values from a column.

    SELECT DISTINCT column_name
    FROM table_name;
    

These are some of the most fundamental SQL commands, and they provide the building blocks for more complex database operations. Remember to adapt these commands to your specific database system (e.g., MySQL, PostgreSQL, SQL Server) as there may be some variations in syntax and additional features supported by each system.

Post a Comment

Previous Post Next Post