SQL Server uses data types to define the kind of values in each column and variable. These data types help the database store and read values with speed and order.
Data types decide how much space a value takes and how SQL Server compares one value to another.
Categories of Data Types in SQL Server
SQL Server groups data types into main sets. Each one holds types that share a role.
Exact Number Types:
Numbers store whole or decimal numbers without error.
Here are examples:
intbigintdecimalnumeric
You can use them like in the command below:
CREATE TABLE Sales(
SaleID int,
Quantity int,
Price decimal(10,2)
);This table stores sale records with exact counts and prices without loss.
Approximate Number Types:
Number types store numbers with floating point. Here is an example:
CREATE TABLE Measures(
MeasureID int,
Temperature float
);It keeps measures with decimal values that may change over large ranges.
Date and Time Types:
This holds dates and times with combined values. Here is the example:
CREATE TABLE Events(
EventID int,
EventDate datetime2
);It saves event dates with high precision for logs and reports.
Character Types:
Character types store text in fixed or variable length.
Example:
CREATE TABLE Users(
UserID int,
UserName varchar(50)
);This stores user names with room for letters of different sizes.
Unicode Character Types:
Unicode Character types hold text in many language sets:
CREATE TABLE Books(
BookID int,
Title nvarchar(200)
);This table stores book titles with characters from different languages.
Binary Types:
Binary types store raw bytes. For example:
CREATE TABLE Files(
FileID int,
FileData varbinary(max)
);It saves files or images in a binary column.
Other Types:
These types cover unique values and spatial data for:
uniqueidentifierxmlgeometrygeography
For example:
CREATE TABLE Locations(
LocationID uniqueidentifier,
GeoData geography
);This table stores unique IDs and spatial points for mapping.
A developer checks the range of values and the type of operation before choosing a data type.
Large ranges use bigint instead of int, text with multiple languages uses nvarchar instead of varchar, and large binary data uses varbinary(max) instead of binary.
Examples with SQL Queries
Use decimal for money:
CREATE TABLE Payments(
PaymentID int,
Amount decimal(12,2)
);
INSERT INTO Payments VALUES(1,125.75);
SELECT * FROM Payments; This query creates a table for payments with a decimal column to hold money values without rounding errors.
Store dates with datetime2:
CREATE TABLE Appointments(
AppointmentID int,
AppointmentDate datetime2
);
INSERT INTO Appointments VALUES(1,'2025-09-15 14:30:00');
SELECT * FROM Appointments;This query stores an appointment date with high precision, which helps when events happen many times per day.
Use nvarchar for multilingual text:
CREATE TABLE User_comments(
CommentID int,
CommentText nvarchar(500)
);
INSERT INTO User_comments VALUES(1,N'مرحبا');
SELECT * FROM User_comments;You can store any other language with nvarchar the type. So here the n that before varchar refers to “National Language”. It keeps full Unicode support for many scripts
Store binary files:
CREATE TABLE Attachments(
AttachmentID int,
FileData varbinary(max)
);Here, it shows you how to store large binary data like images or documents inside a database column with the varbinary
Wrapping Up
You learned the role of SQL Server data types and how they define storage, comparison, and speed.
SQL Server has a lot of data types. Here is a quick list showing you them:
- number
- date
- text
- binary
- special types.
Each type fits a certain use and can change how a database works.
FAQs
What are the main SQL Server data types?
- Exact numeric:
int,decimal,numeric - Approximate numeric:
float,real - Character types:
char,varchar,text - Date and time:
date,datetime,time - Other:
binary,varbinary,xml
How do you declare a data type in SQL Server?
CREATE TABLE Employees (
EmpID int,
Name varchar(100),
HireDate date
);
What is the difference between char and varchar in SQL Server?
- char(n): Fixed length. Always uses
nbytes. - varchar(n): Variable length. Uses only required space.
CREATE TABLE TestChar (
FixedChar char(10),
VarCharCol varchar(10)
);
Which SQL Server data type is best for storing money values?
decimal(p,s): High precision. Recommended for accuracy.money: Fixed precision. Easy but less flexible.
CREATE TABLE Products (
ProductID int,
Price decimal(10,2)
);
Similar Reads
In this article, you will learn how to insert more than a million records into the SQL Server database table.…
This is an Introduction for SQL Server, which is a relational database management system (RDBMS). Which allows users to store,…
This tutorial will teach you how to store a big data table in C# or .NET into a database table…
SQL Server keeps data safe and makes it easy to run requests and get answers fast. This guide shows how…
The collation in SQL Server defines rules for sorting and comparing data. It covers default options, types, setup, checks, changes,…
SQL Server has a set of parts that work as one system. Each part has a task and connects to…
DROP DATABASE in SQL Server lets you remove one or many databases. Understand the "drop database" and How It Works…