DEV Community

avery
avery

Posted on

27. SQL

BootCamp by Dr.Angela

1. SQL Commands: CREATE TABLE and INSERT Data

2. SQL Commands: READ, SELECT, and WHERE

  • Reading Data
    • Retrieve all columns from a table, ex) SELECT * FROM products;
    • Retrieve specific data using a condition, ex) SELECT * FROM products WHERE id = 1;
  • WHERE Clause : Used to filter records based on specific conditions.

3. Updating Values and Modifying Tables

  • Updating Existing Data
    • ex) UPDATE products SET price = 1.00 WHERE id = 1;
    • SET : specifies the new value.
    • WHERE : determines which row(s) will be updated.
  • Adding a New Column
    • ex) ALTER TABLE products ADD stock INT;
    • ALTER TABLE : modifies an existing table structure.

4. SQL Commands: DELETE

  • Deleting Data
    • ex) DELETE FROM products WHERE id = 2;
  • Removes rows that match the condition.
  • Always use a WHERE clause unless you intend to delete all records.

5. Understanding SQL Relationships, Foreign Keys, and INNER JOINs

  • Foreign Keys : Creates a relationship between two tables, Helps maintain data integrity
  • INNER JOIN : Used to combine related data from multiple tables.
    • ex) SELECT orders.order_number, customers.first_name, customers.last_name, customers.address FROM orders INNER JOIN customers ON orders.customer_id = customers.id;
  • How INNER JOIN Works : Only matching records from both tables are returned.

Top comments (0)