{"id":79,"date":"2018-12-05T08:58:09","date_gmt":"2018-12-05T08:58:09","guid":{"rendered":"https:\/\/barkhane.com\/sql\/2018\/12\/05\/sql-data-types\/"},"modified":"2024-03-03T18:06:02","modified_gmt":"2024-03-03T18:06:02","slug":"sql-data-types","status":"publish","type":"post","link":"https:\/\/barkhane.com\/sql\/sql-data-types\/","title":{"rendered":"SQL Data Types"},"content":{"rendered":"<p>SQL Data Types : The SQL data type defines a kind of value that a column can contain. In a database table, every column is required to have a name and a data type.<\/p>\n<p>SQL Server offers six categories of data types for your use which are listed below<\/p>\n<h2>Exact Numeric Data Types<\/h2>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<th>DATA TYPE<\/th>\n<th>FROM<\/th>\n<th>TO<\/th>\n<\/tr>\n<tr>\n<td>bigint<\/td>\n<td>-9,223,372,036,854,775,808<\/td>\n<td>9,223,372,036,854,775,807<\/td>\n<\/tr>\n<tr>\n<td>int<\/td>\n<td>-2,147,483,648<\/td>\n<td>2,147,483,647<\/td>\n<\/tr>\n<tr>\n<td>smallint<\/td>\n<td>-32,768<\/td>\n<td>32,767<\/td>\n<\/tr>\n<tr>\n<td>tinyint<\/td>\n<td>0<\/td>\n<td>255<\/td>\n<\/tr>\n<tr>\n<td>bit<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>decimal<\/td>\n<td>-10^38 +1<\/td>\n<td>10^38 -1<\/td>\n<\/tr>\n<tr>\n<td>numeric<\/td>\n<td>-10^38 +1<\/td>\n<td>10^38 -1<\/td>\n<\/tr>\n<tr>\n<td>money<\/td>\n<td>-922,337,203,685,477.5808<\/td>\n<td>+922,337,203,685,477.5807<\/td>\n<\/tr>\n<tr>\n<td>smallmoney<\/td>\n<td>-214,748.3648<\/td>\n<td>+214,748.3647<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Approximate Numeric Data Types<\/h2>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<th>DATA TYPE<\/th>\n<th>FROM<\/th>\n<th>TO<\/th>\n<\/tr>\n<tr>\n<td>float<\/td>\n<td>-1.79E + 308<\/td>\n<td>1.79E + 308<\/td>\n<\/tr>\n<tr>\n<td>real<\/td>\n<td>-3.40E + 38<\/td>\n<td>3.40E + 38<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Date and Time Data Types<\/h2>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<th>DATA TYPE<\/th>\n<th>FROM<\/th>\n<th>TO<\/th>\n<\/tr>\n<tr>\n<td>datetime<\/td>\n<td>Jan 1, 1753<\/td>\n<td>Dec 31, 9999<\/td>\n<\/tr>\n<tr>\n<td>smalldatetime<\/td>\n<td>Jan 1, 1900<\/td>\n<td>Jun 6, 2079<\/td>\n<\/tr>\n<tr>\n<td>date<\/td>\n<td colspan=\"2\">Stores a date like June 30, 1991<\/td>\n<\/tr>\n<tr>\n<td>time<\/td>\n<td colspan=\"2\">Stores a time of day like 12:30 P.M.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><b>Note<\/b>\u00a0\u2212 Here, datetime has 3.33 milliseconds accuracy where as smalldatetime has 1 minute accuracy.<\/p>\n<h2>Character Strings Data Types<\/h2>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<th>DATA TYPE<\/th>\n<th>\u00a0Description<\/th>\n<\/tr>\n<tr>\n<td><b>char<\/b><\/td>\n<td>Maximum length of 8,000 characters.( Fixed length non-Unicode characters)<\/td>\n<\/tr>\n<tr>\n<td><b>varchar<\/b><\/td>\n<td>Maximum of 8,000 characters.(Variable-length non-Unicode data).<\/td>\n<\/tr>\n<tr>\n<td><b>varchar(max)<\/b><\/td>\n<td>Maximum length of 2E + 31 characters, Variable-length non-Unicode data (SQL Server 2005 only).<\/td>\n<\/tr>\n<tr>\n<td><b>text<\/b><\/td>\n<td>Variable-length non-Unicode data with a maximum length of 2,147,483,647 characters.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Unicode Character Strings Data Types<\/h2>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<th>DATA TYPE<\/th>\n<th>\u00a0Description<\/th>\n<\/tr>\n<tr>\n<td><b>nchar<\/b><\/td>\n<td>Maximum length of 4,000 characters.( Fixed length Unicode)<\/td>\n<\/tr>\n<tr>\n<td><b>nvarchar<\/b><\/td>\n<td>Maximum length of 4,000 characters.(Variable length Unicode)<\/td>\n<\/tr>\n<tr>\n<td><b>nvarchar(max)<\/b><\/td>\n<td>Maximum length of 2E + 31 characters (SQL Server 2005 only).( Variable length Unicode)<\/td>\n<\/tr>\n<tr>\n<td><b>ntext<\/b><\/td>\n<td>Maximum length of 1,073,741,823 characters. ( Variable length Unicode )<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Binary Data Types<\/h2>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<th>DATA TYPE<\/th>\n<th>\u00a0 Description<\/th>\n<\/tr>\n<tr>\n<td><b>binary<\/b><\/td>\n<td>Maximum length of 8,000 bytes(Fixed-length binary data )<\/td>\n<\/tr>\n<tr>\n<td><b>varbinary<\/b><\/td>\n<td>Maximum length of 8,000 bytes.(Variable length binary data)<\/td>\n<\/tr>\n<tr>\n<td><b>varbinary(max)<\/b><\/td>\n<td>Maximum length of 2E + 31 bytes (SQL Server 2005 only). ( Variable length Binary data)<\/td>\n<\/tr>\n<tr>\n<td><b>image<\/b><\/td>\n<td>Maximum length of 2,147,483,647 bytes. ( Variable length Binary Data)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Misc Data Types<\/h2>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<th><\/th>\n<th>DATA TYPE &amp; Description<\/th>\n<\/tr>\n<tr>\n<td><b>sql_variant<\/b><\/td>\n<td>Stores values of various SQL Server-supported data types, except text, ntext, and timestamp.<\/td>\n<\/tr>\n<tr>\n<td><b>timestamp<\/b><\/td>\n<td>Stores a database-wide unique number that gets updated every time a row gets updated<\/td>\n<\/tr>\n<tr>\n<td><b>uniqueidentifier<\/b><\/td>\n<td>Stores a globally unique identifier (GUID)<\/td>\n<\/tr>\n<tr>\n<td><b>xml<\/b><\/td>\n<td>Stores XML data. You can store xml instances in a column or a variable (SQL Server 2005 only).<\/td>\n<\/tr>\n<tr>\n<td><b>cursor<\/b><\/td>\n<td>Reference to a cursor object<\/td>\n<\/tr>\n<tr>\n<td><b>table<\/b><\/td>\n<td>Stores a result set for later processing<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>SQL Data Types : The SQL data type defines a kind of value that a column can contain. In a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[2],"tags":[],"class_list":["post-79","post","type-post","status-publish","format-standard","hentry","category-sql"],"_links":{"self":[{"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/posts\/79","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/comments?post=79"}],"version-history":[{"count":0,"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/posts\/79\/revisions"}],"wp:attachment":[{"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/media?parent=79"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/categories?post=79"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/tags?post=79"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}