Create a SQL Server table

How to create a SQL Server table with a simple query? This basic SQL example creates a table to store Sales data. It is using different data types, such as strings, numeric values, decimal values, integers and Boolean.

This SQL Server example is easy to customize. Copy and paste the code to your computer or laptop, inside your SQL code editor (like SQL Server Management Studio) and execute it!  Indeed, it’s easy to have the exact syntax by doing a copy paste. A table is the base object of a database, consider it as the raw material for SQL.

How to create a SQL Server table?

This simple SQL Server query creates a Sales table to store data. Indeed the sales table can store for example the year, month name, current month, employee number, the number of sales and their respective amounts.

[Year] INT, 
[MonthName] NVARCHAR(50), -- alphanumeric
[MonthCurrent] BIT, -- Boolean, 0 or 1 , false / true
[NumberMonth] TINYINT, -- very small integer, from 0 to 255
[EmployeeNumber] SMALLINT, -- small integer, minimum -2^15, maximum 2^15
[NumberOfClients] INTEGER, -- integer, minimum -2^31, maximum 2^31
[NumberOfSales] BIGINT, -- big integer, minimum: -2^63, maximum 2^63
[Amount_ET] NUMERIC(15,5), -- numeric, 15 digits, with 5 after the comma 
[Amount_IT] DECIMAL(15,5) -- decimal, 15 digits, with 5 after the comma
-- Note: 
-- Amount_ET stands for Amount Excluding Taxes
-- Amount_IT stands for Amount Including Taxes

To go further, check the official page for T-SQL create table on Microsoft.

To conclude, this article shows how to create a table using T-SQL code. The series about tables also explains how to modify an existing SQL Server Table.