🔍
👶 Kids📝 Blog About Contact 🚀 Get Started Free

SQL – CREATE TABLE

Define the structure of a new database table using CREATE TABLE with column names, data types, and constraints.

CREATE TABLE defines the structure of a new table — column names, their data types, and any constraints. Getting table design right at the start is critical; changing table structures later (adding columns, changing types) in a live database can be complex and risky.

The key decisions: choosing appropriate data types for each column, identifying the primary key, and deciding which columns should allow NULL values. Good table design is the foundation of a fast, reliable database.

Common SQL data types

TypeUsed for
INTEGER / INTWhole numbers
REAL / DECIMALDecimal numbers
TEXT / VARCHARCharacter strings
BLOBBinary data
DATE / DATETIMETemporal values

Try It Yourself — Interactive SQL Editor

Edit the query below and click Run Query ▶ to see live results powered by SQLite running directly in your browser.

SQLite – edit & run
Results
← Click Run Query ▶ to see results

Key Points

  • Always define a PRIMARY KEY for every table
  • NOT NULL prevents empty values where data is required
  • DEFAULT sets a fallback value for omitted columns
  • CHECK constraints validate data at the database level

Pro Tip from CodesCompiler: The best way to learn SQL is to break things intentionally — modify the query above, change the WHERE conditions, try different columns. Every error teaches you something the docs cannot.

In the next lesson, we continue exploring SQL’s powerful feature set to build your database mastery.