Thursday, December 3, 2026 | London 10°C · Drizzle
DailyGlimpse

AI

Mastering SQL DDL: A Step-by-Step Guide to Creating Tables and Databases

KSR Datavizon 2 min read

In the latest session of our SQL series, we dive deep into Data Definition Language (DDL) commands, focusing on how to create tables and databases. This tutorial is ideal for beginners and intermediate users looking to strengthen their database management skills.

What is DDL?

DDL stands for Data Definition Language, a subset of SQL used to define and modify database structures. The primary commands include CREATE, ALTER, DROP, and TRUNCATE. In this session, we cover the CREATE command in detail.

Creating a Database

Before you can store data, you need a database. The syntax is straightforward:

CREATE DATABASE database_name;

For example, to create a database named School, you would run:

CREATE DATABASE School;

Creating Tables

Once a database is created, you can define tables within it. Each table consists of columns with specific data types. The basic syntax is:

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

Example: Students Table

Let's create a Students table with columns for ID, name, age, and grade:

CREATE TABLE Students (
StudentID INT PRIMARY KEY,
FirstName VARCHAR(50) NOT NULL,
LastName VARCHAR(50) NOT NULL,
Age INT,
Grade CHAR(2)
);

Key Points

  • Data Types: Choose appropriate types (INT, VARCHAR, DATE, etc.) for each column.
  • Constraints: Apply rules like PRIMARY KEY, NOT NULL, UNIQUE, and FOREIGN KEY to maintain data integrity.
  • Naming Conventions: Use descriptive names for databases and tables.

Practice Makes Perfect

To solidify your understanding, try creating a database for a library system with tables for books, members, and loans. Experiment with different data types and constraints.

Stay tuned for the next session, where we'll explore ALTER and DROP commands to modify and remove database objects.

React