MySQL SQL

How to Use SQL

Most Important SQL Commands

SQL CREATE DATABASE Statement

CREATE DATABASE Example

SQL DROP DATABASE Statement

DROP DATABASE Example

SQL USE DATABASE Statement

USE DATABASE Example

			USE school;
		

SQL CREATE TABLE Statement

CREATE TABLE Example

SQL DROP TABLE Statement

DROP TABLE Example

SQL ALTER TABLE Statement

SQL INSERT INTO Statement

INSERT INTO Example

Best Practice: Always Specify the Columns


SQL UPDATE Table

UPDATE Table Example

ALTER VS UPDATE

Feature ALTER UPDATE
What it does Changes the structure of a table Changes the data/values inside the table
Used for Adding/removing columns, changing data types Modifying existing rows (records)
Affects The table design (schema) The contents (data in rows)
Example ALTER TABLE students ADD gpa DECIMAL(3,2); UPDATE students SET gpa = 3.75 WHERE name = 'Alice';

SQL DELETE Statement

DELETE Example

DROP vs DELETE

Concept DROP DELETE
What it does Removes the entire table or database Removes data (rows) from a table
Structure stays? ❌ No — table is gone completely ✅ Yes — table structure remains
Used for Deleting tables, databases Deleting specific rows or all rows
Rollback? ❌ Not recoverable (in most cases) ✅ Can be rolled back (with transactions)
Example DROP TABLE students; DELETE FROM students WHERE id = 1;

SQL SELECT Statement

SELECT Columns Example

SQL TRUNCATE Statement

TRUNCATE Table Example

			TRUNCATE TABLE students;
		

SQL RENAME Statement

RENAME TABLE Example

			RENAME TABLE old_name TO new_name;
		

RENAME a Column

			ALTER TABLE table_name CHANGE old_column_name new_column_name datatype;
		

Reference