Web Analytics Made Easy - Statcounter

Data types in SQL Server

In relational database, we store data in tabular form where data is divided into columns. Each column has a name and a data type which shows what type of data is going to store in that column. Below are the data types which are mostly used in SQL server.CHARACTER(n)    Character string of fixed length n

VARCHAR(n)        Character string of variable length with maximum length n

VARCHAR(MAX)   Character string of variable length with maximum length can exceed 8000 byes

NCHAR(n)            Fixed-length Unicode string data where n defines the string length and must be a value from 1 through 4,000

NVARCHAR(n)     Variable length Unicode string data where n defines the string length and must be a value from 1 through 4,000

NVARCHAR(MAX) Variable length Unicode string data where MAX indicates that the maximum storage size is 2^31-1 bytes (2 GB)

BINARY(n)           Binary string of fixed length n

BOOLEAN             It stores TRUE or FALSE values

VARBINARY(n)    Binary string of variable length with maximum length n

NTEXT                  Variable-length Unicode data with a maximum string length of 2^30 – 1 (1,073,741,823) bytes

TEXT                    Variable-length non-Unicode data in the code page of the server and with a maximum string length of 2^31-1                                       (2,147,483,647)

IMAGE                 Variable-length binary data from 0 through 2^31-1                                          (2,147,483,647) bytes.

INTEGER Or Int   A 32-bit signed integer value having range of INTEGER is                                -2147483648 to 2147483647

SMALLINT           A 16-bit signed integer value having range of SMALLINT is                              -32768 to 32767.

BIGINT               A 64-bit signed integer value having range of BIGINT is                                   -9223372036854775808 to 9223372036854775807

DECIMAL(p,s)    Exact numerical, precision p, scale s. For Example,                                         Decimal(5,3) means 22.212

NUMERIC(p,s)   Exact numerical, precision p, scale s. (Same as DECIMAL)

REAL                  Approximate numerical, mantissa precision 7

FLOAT                Approximate numerical, mantissa precision 16

DOUBLE             Approximate numerical, mantissa precision 16

DATE                  It stores year/month/day values

TIME                  It stores hour/minute/second values

TIMESTAMP       It stores year/month/day/hour/minute/second values

XML                    It stores XML data


Discover more from Technology with Vivek Johari

Subscribe to get the latest posts sent to your email.

By vivekjohari

I am currently working as a Senior Database Professional and have around 18 years of experience in database. Degree:- Master Degree in Computer(MCA) Certification course in Data Science & Machine Learning from Indian Institute of Technology (IIT), Delhi Work experience:- Designing of the database. Database Optimization. Writing Complex Stored Procedures,Functions,Triggers etc. Designing and developing SSIS & DTS packages. Designing SQL Reports using SSRS. Database Server Maintenance. Certification:- MCTS: DA-100: Analysing Data with Microsoft Power BI MCTS: DP-300: Administering Relational Databases on Microsoft Azure Microsoft certified Sql DBA in Sql server 2008 (MCTS). Microsoft certified BI professional in Sql server 2008 (MCTS). Oracle certified profession DBA in ORACLE 10g (OCP) certified profession DBA in ORACLE 9i (OCP) My other publication Technical Blog:- Technologies with Vivek Johari Guest Author and Blogger at sqlservercentral.com

32 thought on “SQL SERVER – Data types”

Leave a Reply

Discover more from Technology with Vivek Johari

Subscribe now to keep reading and get access to the full archive.

Continue reading