Tutorialsteacher

Follow Us

Articles
  • C#
  • C# OOP
  • ASP.NET Core
  • ASP.NET MVC
  • LINQ
  • Inversion of Control (IoC)
  • Web API
  • JavaScript
  • TypeScript
  • jQuery
  • Angular 11
  • Node.js
  • D3.js
  • Sass
  • Python
  • Go lang
  • HTTPS (SSL)
  • Regex
  • SQL
  • SQL Server
  • PostgreSQL
  • MongoDB
  • SQL Server - Get Started
  • Install SQL Server
  • SQL Server Management Studio
  • SQL Server - Windows Authentication
  • SQL Server - Authentication
  • SQL Server - Create New User
  • SQL Server - GRANT/REVOKE Permissions to User
  • SQL Server - Data Types
  • SQL Server - Naming Conventions
  • SQL Server - CREATE Database
  • SQL Server - CREATE Table
  • Add Columns
  • Identity Column
  • Rename Column, Table
  • Drop Columns
  • SQL Server - Schema
  • SQL Server - Tables Relations
  • SQL Server - Primary Keys
  • Modify/Delete Primary Keys
  • SQL Server - Foreign Keys
  • Modify/Delete Foreign Keys
  • SQL Server - Check Constraints
  • SQL Server - Unique Constraints
  • SQL Server - Views
  • Modify/Delete Views
  • SQL Server - Functions
  • SQL Server - Stored Procedures
  • Stored Procedure Parameters
  • SQL Server - Indexes
  • Non-clustered Indexes
  • Modify/Delete Indexes
  • SQL Server - Triggers
  • DDL Triggers
  • LOGON Triggers
  • Enable/Disable Triggers
  • Modify/Delete Triggers
  • SQL Server - Sequence
  • SQL Server - Synonyms
  • SQL Server - IF ELSE Statement
  • SQL Server - Loops
  • SQL Server - Insert Data
  • SQL Server - Update Data
  • SQL Server - Delete Data
  • SQL Server - Select Query
  • WHERE Clause
  • GROUP BY Clause
  • HAVING Clause
  • ORDER BY Clause
  • SQL Server - Inner Join
  • Left Join
  • Right Join
  • Full Join
  • Self Join
  • Dynamic SQL
  • Built-in Functions
Entity Framework Extensions - Boost EF Core 9
  Bulk Insert
  Bulk Delete
  Bulk Update
  Bulk Merge

SQL Server Data Types

In SQL Server, data type specifies the type of data that can be stored in a column of a table such as integer data, string data, date & time, binary strings, etc.

Assigning an appropriate data type to columns in a table is crucial while designing a database. It affects the performance and efficiency of the database and the application using the database.

SQL Server provides built-in data types for all kinds of data that can be used within SQL Server. Additionally, you can also define your own data type in T-SQL.

Data Type Categories:

CategoryData Types
Exact numericsbit, tinyint, smallint, int, bigint, decimal, numeric, money, smallmoney
Approximate numericsReal, Float
Date & Timedate, smalldatetime, datetime, datetime2, datetimeoffset, time
Character stringschar, varchar, text
Unicode Character stringsnchar, nvarchar, ntext
Other data typescursor, hierarchyid, sql_variant, spatial Geometry types, spatial Geography types, rowversion, uniqueidentifier, xml, table

Exact Numerics

Data TypeValueDescription
bit0,1 or NULLSmallest data type of 1 byte storage size
tinyint0 to 2551 bytes storage size
smallint-32,768 to 32,7672 bytes storage size
int−2,147, 483,6484 bytes storage
bigint−9,223,372, 036,854,775,8088 bytes storage
decimal−10^38+1 to 10^38−1Numeric data type that have a fixed precision and scale.
smallmoney-214,748.3648 to 214,748.36474 bytes
money-922,337,203,685,477.5808 to 922,337,203,685,477.58078 bytes

Approximate Numerics

Data TypeValueDescription
float(n)- 1.79E+308 to -2.23E-308, 0Storage depends on the value of n.
real- 3.40E + 38 to -1.18E - 38, 0 and 1.18E - 38 to 3.40E + 384 bytes

Date and Time

Data TypeValueDescription
date0001-01-01 through 9999-12-313 bytes
datetimeDate: 1753-01-01 through 9999-12-318 bytes
datetime2Date: 0001-01-01 through 9999-12-31Precision < 3 : 6 bytes
smalldatetime1900-01-01 through 2079-06-064 bytes fixed
datetimeoffsetDate: 0001-01-01 through10 bytes fixed
time00:00:00.0000000 through 23:59:59.99999995 bytes fixed

Character Strings

Data TypeValueDescription
char[(n)]1 to 8000 charactersn bytes
varchar[(n)]1 to 8000n bytes + 2 bytes
varchar(max)1 to 2^31-1n bytes + 4 bytes
text0 to 2,147,483,647n bytes + 4 bytes

Unicode Character Strings

Data TypeValueDescription
nchar[(n)]1 to 4000 characters2 times n bytes
nvarchar[(n|max)]1 to 40002 times n bytes
ntext0 to 1,073,741,8232 times the string length

Binary Strings

Data TypeValueDescription
binary[(n)]1 to 8000 bytesn bytes
varbinary[(n|max)]1 to 8000Actual length of string + 2 bytes
Image0 to 2,147,483,647Variable length binary data

Other Data Types

Data typeDescription
cursorA data type for variables or stored procedures OUTPUT parameters that contain a reference to a cursor.
rowversionIt returns automatically generated unique binary numbers within a database.
hierarchyidIt is a variable length system data type.
uniqueidentifierIs a 16 byte GUID
sql_variantA data type that stores values of various SQL Server supported data types.
xmlIt stores xml data.
Spatial Geometry typeUsed to represent data in a flat coordinate system (Euclidean).
tableIt is a special data type used to store a result-set temporarily for processing at a later time.
TUTORIALSTEACHER.COM

TutorialsTeacher.com is your authoritative source for comprehensive technologies tutorials, tailored to guide you through mastering various web and other technologies through a step-by-step approach.

Our content helps you to learn technologies easily and quickly for learners of all levels. By accessing this platform, you acknowledge that you have reviewed and consented to abide by our Terms of Use and Privacy Policy, designed to safeguard your experience and privacy rights.

[email protected]

ABOUT USTERMS OF USEPRIVACY POLICY
copywrite-symbol

2024 TutorialsTeacher.com. (v 1.2) All Rights Reserved.