Sql server tutorials

Updated : Sep 18, 2019 in SQL server

SQL Server Data Types

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

DatatypeFromTo
bit01
bigint-9,223,372,036,854,775,8089,223,372,036,854,775,807
tinyint0255
smallint-32,76832,767
int-2,147,483,6482,147,483,647
decimal-10^38 +110^38 -1
numeric-10^38 +110^38 -1
real-3.40E + 383.40E + 38
float-1.79E + 3081.79E + 308

SQL Date and Time Data Types

DatatypeDescription
DATEstores data information format YYYY-MM-DD
TIMEstores data information format HH:MI:SS
DATETIMEStores date and time format YYYY-MM-DD HH:MI:SS
TIMESTAMPstores data information format (‘1970-01-01 00:00:00’ UTC)
YEARStores 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

DatatypeDescription
CHARa maximum length of 8,000 characters
VARCHARa maximum length of 8,000 characters
VARCHAR(max)Variable-length storage with provided max characters, not supported in MySQL
TEXTmaximum size of 2GB data

SQL Unicode Character and String Data Types

DatatypeDescription
NCHARa maximum length of 4,000 characters
NVARCHARa maximum length of 4,000 characters
NVARCHAR(max)storage with provided max characters
NTEXTmaximum size of 1GB data

SQL Binary Data Types

DatatypeDescription
BINARYa maximum length of 8,000 bytes
VARBINARYa maximum length of 8,000 bytes
VARBINARY(max)Variable-length storage with provided max bytes
IMAGEmaximum size of 2GB binary data

SQL Other Data Types

DatatypeDescription
CLOBIt that can hold up to 2GB
BLOBFor binary large objects
XMLfor storing XML data
JSONfor storing JSON data

Also see the Link Cursor in SQL Server with example

Latest posts by DuttaluruVijayakumar (see all)
Like
Like Love Haha Wow Sad Angry

3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Free Stuff
January 28, 2020 10:15 pm

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 .

Hairstyles Women
February 12, 2020 5:58 am

Oh my goodness! an amazing article dude. Thank you

Google
March 13, 2020 4:45 pm

One of our guests recently suggested the following website.