SQL & Databases Masterclass Course
Welcome to the ultimate postgresql tutorial for beginners 2026. Work through interactive sql practice problems with solutions, master our comprehensive sql window functions tutorial modules, and prepare for tough sql interview questions at Google and Amazon entirely in your browser. Claim your course completion XP and build production-ready database mastery today!
SQL Lesson 16: Creating tables
Introduction & Core Concept
We now enter Data Definition Language (DDL). To construct brand new table schemas inside a relational database, we write a CREATE TABLE statement defining the primary key, column headers, and structural datatypes.
CREATE TABLE table_name (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
balance REAL DEFAULT 0.0,
join_date DATE
);Core Structural Datatypes
INTEGER: Whole numeric numbers without decimals.TEXT (or VARCHAR): Character sequences and text strings.REAL (or DECIMAL / FLOAT): Floating-point decimal numbers.DATE / DATETIME: Calendar timestamps.Why & Where We Use It
Real-World Example
ShopMart wants to build a new customer support ticketing module. The database architect writes a CREATE TABLE support_tickets query specifying an auto-incrementing ticket ID, customer ID linking key, issue details text block, and a default status of 'Open'.
Best Practices: What to Do & What NOT to Do
IF NOT EXISTS in your creation statements (e.g., CREATE TABLE IF NOT EXISTS my_table). This prevents script crash errors if the table was already created during an earlier deployment.Syntax & Pro Tips
CREATE TABLE IF NOT EXISTS audit_logs (
log_id INTEGER PRIMARY KEY AUTOINCREMENT,
action TEXT NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);