← Back to Chapters

MySQL SQL — Overview

? MySQL SQL — Overview

? Quick Overview

MySQL SQL is the standard language used to interact with a MySQL database. It allows you to store, retrieve, update, and manage data efficiently using structured commands like SELECT, INSERT, UPDATE, and DELETE.

? Key Concepts

  • Database: A structured collection of data.
  • Table: Stores data in rows and columns.
  • Record: A single row in a table.
  • Field: A single column in a table.
  • Query: A request for data.
  • Primary Key: A unique identifier for each row.

? Common MySQL Commands

  • SELECT — Retrieve records
  • INSERT INTO — Add new records
  • UPDATE — Modify existing records
  • DELETE — Remove records
  • CREATE DATABASE — Create a database
  • CREATE TABLE — Create a table
  • DROP DATABASE — Delete a database
  • DROP TABLE — Delete a table

? Syntax / Theory

? View Code Example
// Basic SQL operations
SELECT column1, column2 FROM table_name;
INSERT INTO table_name (column1, column2) VALUES (value1, value2);
UPDATE table_name SET column1 = value1 WHERE condition;
DELETE FROM table_name WHERE condition;

? Code Examples

? View Code Example
// Creating a table and performing CRUD operations
CREATE TABLE customers (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100),
email VARCHAR(100)
);

INSERT INTO customers (name, email) VALUES ('Jane Doe','jane.doe@example.com');
UPDATE customers SET email='jane.doe@newdomain.com' WHERE name='Jane Doe';
DELETE FROM customers WHERE name='Jane Doe';

? Live Output / Explanation

  • CREATE TABLE creates a structure for data storage.
  • INSERT INTO adds a new row into the table.
  • UPDATE edits existing records.
  • DELETE removes rows that match a condition.

✅ Tips & Best Practices

  • Always use WHERE while updating or deleting records.
  • Keep meaningful column names.
  • Use PRIMARY KEY to uniquely identify records.
  • Backup your database before major changes.

? Try It Yourself

  • Create a table students with id, name, and marks.
  • Insert at least 3 records.
  • Update one student's marks.
  • Delete one student using a condition.
  • Display all data using SELECT *.