How to create a SQL Server Create 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. Just 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.
How to create a SQL Server table?
This simple SQL Server query creates a Sales table to store data. Indeed the dbo.Sales table can store for example the month name, the current month, the employee number, the number of sales and their respective amounts.
CREATE TABLE [dbo].[SALES] ( [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
We saw in this article how to create a SQL Server table, to go further, check this article on how to modify a SQL Server Table.