Creating Tables & Inserting Data
Learn to create database tables with CREATE TABLE and add data with INSERT INTO. This is a foundational concept in database management and queries that professional developers rely on daily. The explanations below are written to be beginner-friendly while covering the depth and nuance that comes from real-world SQL experience. Take your time with each section and practice the examples
25 min•By Priygop Team•Last updated: Feb 2026
CREATE TABLE and INSERT INTO
CREATE TABLE defines the structure of a new table — the column names and their data types. INSERT INTO adds new rows of data to a table. Every table should have a primary key column (usually id) that uniquely identifies each row.
SQL Data Types
- INT — Whole numbers (age, id, quantity)
- VARCHAR(n) — Variable-length text up to n characters (name, email)
- TEXT — Long text (descriptions, comments)
- DECIMAL(p,s) — Precise decimal numbers (price: DECIMAL(10,2))
- DATE — Date: YYYY-MM-DD
- BOOLEAN — True or false
- PRIMARY KEY — Unique identifier for each row
- NOT NULL — Column cannot be empty
CREATE TABLE & INSERT Example
Example
-- Create a students table
CREATE TABLE students (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100) NOT NULL,
age INT,
city VARCHAR(50),
grade CHAR(1)
);
-- Insert one student
INSERT INTO students (name, age, city, grade)
VALUES ('Alice', 20, 'Mumbai', 'A');
-- Insert multiple students at once
INSERT INTO students (name, age, city, grade)
VALUES
('Bob', 22, 'Delhi', 'B'),
('Charlie', 19, 'Bangalore', 'A'),
('Diana', 21, 'Mumbai', 'C');
-- Now retrieve all students
SELECT * FROM students;Try It Yourself: Create & Insert
Try It Yourself: Create & InsertJavaScript
JavaScript Editor
✓ ValidTab = 2 spaces
JavaScript|24 lines|745 chars|✓ Valid syntax
UTF-8