CREATE TABLE
Every database begins with a table. A table is where your data lives. In SQL, the CREATE TABLE statement helps you define this storage space — specifying what kind of data you’ll collect, and how it should behave. It's like designing a form before collecting responses.
Syntax of CREATE TABLE
CREATE TABLE table_name (
column1 datatype constraint,
column2 datatype constraint,
...
);
Let’s break it down:
table_name: Name of your table (e.g., students)
column: Name of each field (e.g., roll_no, name)
datatype: Defines the kind of value stored (e.g., INT, VARCHAR)
constraint: Optional rules (e.g., PRIMARY KEY, NOT NULL)
1. Creating a Basic Students Table
Let’s design a table to store student details at a school in India.
CREATE TABLE students (
roll_no INT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
class VARCHAR(10),
age INT,
city VARCHAR(30)
);
2. Creating a Table with Default Values
We can predefine values using DEFAULT. Suppose most students belong to ‘Hyderabad:
CREATE TABLE students (
roll_no INT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
class VARCHAR(10),
age INT,
city VARCHAR(30) DEFAULT 'Hyderabad'
);

About the authorSrinivas Namala
Software Engineer
Srinivas focuses on backend development, databases, systems, and the technologies used to build reliable server-side applications.
View LinkedIn profile ↗