SQL vs MySQL
• SQL is a query language.
• MySQL is software that uses SQL.
• SQL manages and queries data.
• MySQL stores, manages, and retrieves data using SQL.
• SQL works with various databases, MySQL is one database system.
DDL vs DML
• DDL changes table structure.
• DML changes data inside the table.
• DDL commands: CREATE, ALTER, DROP.
• DML commands: INSERT, UPDATE, SELECT.
• DDL auto-commits, DML may not auto-commit.
DELETE vs TRUNCATE vs DROP
• DELETE removes selected rows.
• TRUNCATE removes all rows quickly.
• DROP removes the entire table.
• DELETE can be rolled back.
• TRUNCATE and DROP cannot be rolled back easily.
Primary Key vs Unique Key
• Primary Key is unique and NOT NULL.
• Unique Key allows NULL but ensures uniqueness.
• A table can have only one Primary Key.
• A table can have multiple Unique Keys.
• Primary Key is used for identification.
Primary Key vs Foreign Key
• Primary Key identifies a row uniquely.
• Foreign Key links two tables.
• Primary Key exists in the parent table.
• Foreign Key exists in the child table.
• Foreign Key ensures referential integrity.
CHAR vs VARCHAR
• CHAR is fixed length.
• VARCHAR is variable length.
• CHAR is faster for fixed data.
• VARCHAR saves memory for variable data.
• CHAR pads spaces; VARCHAR does not.
WHERE vs HAVING
• WHERE filters rows before grouping.
• HAVING filters after grouping.
• WHERE cannot use aggregate functions.
• HAVING uses aggregate functions.
• WHERE applies to rows, HAVING to groups.
ORDER BY vs GROUP BY
• ORDER BY sorts output.
• GROUP BY forms groups.
• ORDER BY does not aggregate data.
• GROUP BY aggregates data.
• ORDER BY is for sorting; GROUP BY is for grouping.
Single Row vs Aggregate Functions
• Single-row functions work on one row.
• Aggregate functions work on many rows.
• Single-row returns one result per row.
• Aggregate returns one result per group.
• Examples: UPPER(), SUM().
Natural Join vs Inner Join
• Natural Join matches same-named columns.
• Inner Join uses ON condition.
• Natural Join avoids column repetition.
• Inner Join repeats columns unless specified.
• Natural Join is automatic; Inner Join is manual.
Table vs View
• Table stores data physically.
• View stores no data (virtual).
• Table is permanent.
• View updates reflect table changes.
• Tables are editable; Views may be restricted.
Super Key vs Candidate Key
• Super Key identifies a row.
• Candidate Key is minimal super key.
• Super Key may contain extra attributes.
• Candidate Key has no extra attributes.
• Candidate Key can become Primary Key.