DB Exam
Database Systems (Week 5 & 6)
CREATE DATABASE & USE
Commands to create and select an active database.
Basic Creation
basic-creation
CREATE TABLE with Constraints
Creating a table with Primary Key, Foreign Key, Default, and cascades.
๐ก
PRIMARY KEY = UNIQUE + NOT NULL
๐ก
UNIQUE = No duplicate values allowed
๐ก
NOT NULL = Cannot be empty
๐ก
DEFAULT = Automatically assigns a value
๐ก
FOREIGN KEY = Links table to a parent table
๐ก
ON DELETE CASCADE = Removes dependent rows automatically.
Students and Departments Example
students-and-departments-example
ALTER TABLE
Modifying existing table structure.
Common Alternations
common-alternations
DROP, TRUNCATE & RENAME
Removing tables entirely, clearing data, or renaming them.
๐ก
DROP: Deletes the entire table structure and data (DDL).
๐ก
TRUNCATE: Empties the table but keeps the structure intact. Very fast! (DDL).
๐ก
DELETE: Removes rows one by one, can be rolled back (DML).
Remove Operations
remove-operations