in this article, we will discuss the SQL Server Data Types and basic syntaxes
Data types column defines what value the column can hold like integer, date and time, money, character, binary, and etc. and this data types column holds specify type only and type-safe
What is Data Type in SQL?
Each column in a SQL table should have a name and a data type.
SQL Server has a different of data types, In a Database table, You have to decide what type of data you are going to be kept within every and each table column
The data type is a helper for the SQL server to understand what type of data is expected inside of column, and SQL will interact with the stored data.
SQL Server Data Types
SQL data types can be classified into the following types
- Numeric data types: int, tinyint, bigint, float, real, etc.
- Date and Time: Date, Time, Datetime, etc.
- Character and String: char, varchar, text, etc.
- Unicode character string: , nvarchar, ntext, etc.
- Binary data: binary, varbinary, etc.
- Miscellaneous data Types: clob, blob, xml, cursor, table, etc.
SQL Numeric Data Types
Datatype | From | To |
---|---|---|
bit | 0 | 1 |
bigint | -9,223,372,036,854,775,808 | 9,223,372,036,854,775,807 |
tinyint | 0 | 255 |
smallint | -32,768 | 32,767 |
int | -2,147,483,648 | 2,147,483,647 |
decimal | -10^38 +1 | 10^38 -1 |
numeric | -10^38 +1 | 10^38 -1 |
real | -3.40E + 38 | 3.40E + 38 |
float | -1.79E + 308 | 1.79E + 308 |
SQL Date and Time Data Types
Datatype | Description |
---|---|
DATE | stores data information format YYYY-MM-DD |
TIME | stores data information format HH:MI:SS |
DATETIME | Stores date and time format YYYY-MM-DD HH:MI:SS |
TIMESTAMP | stores data information format (‘1970-01-01 00:00:00’ UTC) |
YEAR | Stores year in 2 digits or 4 digit format. Range 1901 to 2155 in 4-digit format. Range 70 to 69, representing 1970 to 2069. |
SQL Character and String Data Types
Datatype | Description |
---|---|
CHAR | a maximum length of 8,000 characters |
VARCHAR | a maximum length of 8,000 characters |
VARCHAR(max) | Variable-length storage with provided max characters, not supported in MySQL |
TEXT | maximum size of 2GB data |
SQL Unicode Character and String Data Types
Datatype | Description |
---|---|
NCHAR | a maximum length of 4,000 characters |
NVARCHAR | a maximum length of 4,000 characters |
NVARCHAR(max) | storage with provided max characters |
NTEXT | maximum size of 1GB data |
SQL Binary Data Types
Datatype | Description |
---|---|
BINARY | a maximum length of 8,000 bytes |
VARBINARY | a maximum length of 8,000 bytes |
VARBINARY(max) | Variable-length storage with provided max bytes |
IMAGE | maximum size of 2GB binary data |
SQL Other Data Types
Datatype | Description |
---|---|
CLOB | It that can hold up to 2GB |
BLOB | For binary large objects |
XML | for storing XML data |
JSON | for storing JSON data |
Also see the Link Cursor in SQL Server with example
Latest posts by DuttaluruVijayakumar (see all)
- how to create ASP.NET Core 3 Web API Project - January 21, 2022
- JWT Authentication using OAUTH - January 10, 2022
- Ado.net database Transactions - January 9, 2022
Hello my friend! I wish to say that this post is awesome, nice written and include almost all significant infos. I would like to look extra posts like this .
Oh my goodness! an amazing article dude. Thank you
One of our guests recently suggested the following website.