Back to SQL Notes
Topic #73

CREATE TABLE in SQL

CREATE TABLE defines a new table — its columns, their data types, and the rules (constraints) each column must follow.

Syntax

CREATE TABLE table_name (
    column1 datatype constraints,
    column2 datatype constraints,
    ...
);

Example

CREATE TABLE employees (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    department VARCHAR(50),
    salary DECIMAL(10,2) DEFAULT 0,
    joined_on DATE
);

This creates an empty table — no rows yet, just structure. You'd add data with INSERT.

Auto-Incrementing Primary Keys — Dialect Differences

DatabaseSyntax
MySQLid INT AUTO_INCREMENT PRIMARY KEY
PostgreSQLid SERIAL PRIMARY KEY (or GENERATED ALWAYS AS IDENTITY in modern Postgres)
SQL Serverid INT IDENTITY(1,1) PRIMARY KEY

Avoiding Errors on Re-Run

CREATE TABLE IF NOT EXISTS employees ( ... );

Practical Use Case

This is the first statement in almost every real project setup — defining the schema before any application code touches the database. Getting data types and constraints right here saves painful migrations later.

Common Mistakes

  • Forgetting a PRIMARY KEY — every table should have one to uniquely identify rows
  • Making every column VARCHAR(255) without thinking about the actual data (see Data Types)
  • Not adding NOT NULL on columns that should never be empty (e.g. an order's customer_id)
Need SQL for backend development? Designing tables like this is a core skill in every backend role. Coding Now Tech Institute's Full Stack and Java Full Stack courses cover schema design alongside the application layer.

Interview Relevance

You'll frequently be asked to design a table from a description ("design a table to store orders for an e-commerce store") — practice reading requirements and mapping them to columns, types, and constraints.

Practice Question

Design a students table with: an auto-incrementing ID, a required name, an email that must be unique, and an enrollment date that defaults to today.

Want to go beyond the notes?

Join Coding Now Tech Institute's SQL course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

CREATE TABLE in SQL – FAQs

Quick answers about learning CREATE TABLE in SQL in SQL.

This free note from Coding Now Tech Institute explains CREATE TABLE in SQL in SQL — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every SQL topic on Coding Now Tech Institute, including CREATE TABLE in SQL, is 100% free with no signup required.
With focused practice, most students grasp CREATE TABLE in SQL in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now