Loading Data Driven Insights
Preparing your learning content.
Preparing your learning content.
A beginner-friendly guide to the SQL CREATE TABLE statement, including table planning, column names, data types, and a SQL Server-friendly example.
The CREATE TABLE statement is used to create a new table in a database.
A table gives your data a clear structure before any rows are inserted. It defines the table name, the column names, the data type for each column, and any optional rules or constraints.
A CREATE TABLE statement starts with the table name, followed by a list of columns. Each column should have a name and a data type.
CREATE TABLE table_name (
column1 data_type,
column2 data_type,
column3 data_type
);
Here is a practical SQL Server-friendly example:
CREATE TABLE Employees (
employee_id INT,
employee_name VARCHAR(100),
department VARCHAR(50),
salary DECIMAL(10, 2)
);
Before writing CREATE TABLE, decide what data the table should store.
For an Employees table, we can plan the columns like this:
This command creates a table called Employees.
CREATE TABLE Employees (
employee_id INT,
employee_name VARCHAR(100),
department VARCHAR(50),
salary DECIMAL(10, 2)
);
employee_id as a whole numberemployee_name as textdepartment as textsalary as a decimal numberAfter running the CREATE TABLE statement, the table structure is defined like this:
Learning SQL in order?
Use the roadmap to follow each SQL topic step by step, from relational database basics to advanced query techniques.
Back to SQL RoadmapRelated lessons
ALTER TABLE
A beginner-friendly guide to ALTER TABLE in SQL, including how to add, change, and remove columns from an existing table.
DELETE
A beginner-friendly guide to the SQL DELETE statement, with SQL Server-friendly examples for removing rows from a table safely.
GROUP BY
A beginner-friendly guide to the SQL GROUP BY clause, with SQL Server-friendly examples using COUNT and SUM.