bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/SQL/SQL References
SQL•SQL References

SQL Data Types for MySQL, SQL Server, and MS Access

SQL Data Types

The data type of a column defines what value the column can hold: integer, character, money, date and time, binary, and so on.

Each column in a database table is required to have a name and a data type.

An SQL developer must decide what type of data that will be stored inside each column when creating a table. The data type is a guideline for SQL to understand what type of data is expected inside of each column, and it also identifies how SQL will interact with the stored data.

Always check the documentation! Data types might have different names in different databases. And even if the name is the same, the size and other details may be different!

MySQL Data Types (Version 8.4)

In MySQL there are three main data types: String, Numeric, and Date and Time.

String Data Types

Data typeDescription
CHAR(size)A fixed-length string (can contain letters, numbers, and special characters). size specifies the column length in characters, from 0 to 255. Default size is 1
VARCHAR(size)A variable-length string (can contain letters, numbers, and special characters). size specifies the maximum column length in characters, from 0 to 65535
BINARY(size)Similar to CHAR(), but stores binary byte strings. size specifies the column length in bytes. Default size is 1
VARBINARY(size)Similar to VARCHAR(), but stores binary byte strings. size specifies the maximum column length in bytes.
BLOB(size)A BLOB column with a maximum length of 65535 bytes
TINYBLOBA BLOB column with a maximum length of 255 bytes
MEDIUMBLOBA BLOB column with a maximum length of 16777215 bytes
LONGBLOBA BLOB column with a maximum length of 4294967295 or 4GB bytes
TEXT(size)Holds a string with a maximum length of 65535 bytes
TINYTEXTA TEXT column with a maximum length of 255 characters
MEDIUMTEXTA TEXT column with a maximum length of 16777215 characters
LONGTEXTA TEXT column with a maximum length of 4294967295 or 4GB bytes
ENUM(val1, val2, val3, ...)A string object that can have only one value, chosen from the list of possible values (val1, val2, val3,..). You can list up to 65535 values. If a value is inserted that is not in the list, a blank value will be inserted
SET(val1, val2, val3, ...)A string object that can have zero or more values, chosen from the list of possible values (val1, val2, val3,..). You can list up to 64 values

Numeric Data Types

Data typeDescription
BIT( size )A bit-value type. size indicates the number of bits per value, from 1 to 64. The default value for size is 1.
TINYINT( size )A very small integer. Signed range is from -128 to 127. Unsigned range is from 0 to 255. size specifies the minimum display width (max display width is 255)
BOOLA value of zero is considered as false, nonzero values are considered as true.
BOOLEANEqual to BOOL
SMALLINT( size )A small integer. Signed range is from -32768 to 32767. Unsigned range is from 0 to 65535. size specifies the minimum display width (max display width is 255)
MEDIUMINT( size )A medium-sized integer. Signed range is from -8388608 to 8388607. Unsigned range is from 0 to 16777215. size specifies the minimum display width (max display width is 255)
INT( size )A normal-size integer. Signed range is from -2147483648 to 2147483647. Unsigned range is from 0 to 4294967295. size specifies minimum display width (max display width is 255)
INTEGER( size )Synonym for INT( size )
BIGINT( size )A large integer. Signed range is from -9223372036854775808 to 9223372036854775807. Unsigned range is from 0 to 18446744073709551615. size specifies the minimum display width (max display width is 255)
DECIMAL( size , d )An exact fixed-point number. size indicates the total number of digits (max 65). d indicates the number of digits after the decimal point (max 30). The default value for size is 10. The default value for d is 0.
DEC( size , d )Synonym for DECIMAL( size , d )
FLOAT( size , d )A small floating-point number. FLOAT( size , d ) is deprecated in MySQL 8.0.17, and it will be removed in future MySQL versions
FLOAT( p )A floating-point number. The p value determines whether to use FLOAT or DOUBLE for the resulting data type. If p is from 0 to 24, the data type becomes FLOAT. If p is from 25 to 53, the data type becomes DOUBLE
DOUBLE( size , d )A normal-size floating-point number. Permissible values are -1.7976931348623157E+308 to -2.2250738585072014E-308, 0, and 2.2250738585072014E-308 to 1.7976931348623157E+308. The total number of digits is specified in size . The number of digits after the decimal point is specified in the d parameter
DOUBLE PRECISION( size , d )Synonym for DOUBLE( size , d )

Date and Time Data Types

Data typeDescription
DATEA date. Format: YYYY-MM-DD. The supported range is from '1000-01-01' to '9999-12-31'
DATETIME( fsp )A date and time combination. Format: YYYY-MM-DD hh:mm:ss. The supported range is from '1000-01-01 00:00:00' to '9999-12-31 23:59:59'. Adding DEFAULT and ON UPDATE in the column definition to get automatic initialization and updating to the current date and time
TIMESTAMP( fsp )A timestamp. Format: YYYY-MM-DD hh:mm:ss. TIMESTAMP values are stored as the number of seconds since the Unix epoch ('1970-01-01 00:00:00' UTC). The supported range is from '1970-01-01 00:00:01' UTC to '2038-01-09 03:14:07' UTC. Automatic initialization and updating to the current date and time can be specified using DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP in the column definition
TIME( fsp )A time. Format: hh:mm:ss. The supported range is from '-838:59:59' to '838:59:59'
YEARA year in a four-digit format (YYYY). Values allowed in four-digit format: 1901 to 2155, and 0000.

SQL Server Data Types

In SQL Server there are three main data types: String, Numeric, and Date and Time.

String Data Types

Data typeDescriptionMax char lengthStorage
char(n)Fixed-length non-Unicode character data (n must be between 1 and 8000)8,000n bytes (uses one byte for each character)
varchar(n)Variable-length non-Unicode character data (n must be between 1 and 8000)8,000n bytes + 2 bytes
varchar(max)Variable-length non-Unicode character dataup to 2 GB
nchar(n)Fixed-length Unicode character data (n must be between 1 and 4000)4,0002 * n bytes (uses two bytes for each character)
nvarchar(n)Variable-length Unicode character data (n must be between 1 and 4000)4,0002 * n bytes + 2 bytes (uses two bytes for each character)
nvarchar(max)Variable-length Unicode character dataup to 2 GB
binary(n)Fixed-length binary data (n must be between 1 and 8000)8,000n bytes
varbinary(n)Variable-length binary data (n must be between 1 and 8000)8,000actual length of data entered + 2 bytes
varbinary(max)Variable-length binary data2GB

Numeric Data Types

Data typeDescriptionStorage
bitInteger that can be 0, 1, or NULL
tinyintAllows whole numbers from 0 to 2551 byte
smallintAllows whole numbers between -32,768 and 32,7672 bytes
intAllows whole numbers between -2,147,483,648 and 2,147,483,6474 bytes
bigintAllows whole numbers between -9,223,372,036,854,775,808 and 9,223,372,036,854,775,8078 bytes
decimal(p,s)Fixed precision and scale numbers. Allows numbers from -10^38 +1 to 10^38 –1. The p parameter indicates the maximum total number of digits that can be stored (both to the left and to the right of the decimal point). p must be a value from 1 to 38. Default is 18. The s parameter indicates the maximum number of digits stored to the right of the decimal point. s must be a value from 0 to p. Default value is 05-17 bytes
numeric(p,s)Fixed precision and scale numbers. Allows numbers from -10^38 +1 to 10^38 –1. The p parameter indicates the maximum total number of digits that can be stored (both to the left and to the right of the decimal point). p must be a value from 1 to 38. Default is 18. The s parameter indicates the maximum number of digits stored to the right of the decimal point. s must be a value from 0 to p. Default value is 05-17 bytes
smallmoneyMonetary data from -214,748.3648 to 214,748.36474 bytes
moneyMonetary data from -922,337,203,685,477.5808 to 922,337,203,685,477.58078 bytes
float(n)Floating precision number data from -1.79E + 308 to 1.79E + 308. The n parameter indicates whether the field should hold 4 or 8 bytes. float(24) holds a 4-byte field and float(53) holds an 8-byte field. Default value of n is 53.4 or 8 bytes
realFloating precision number data from -3.40E + 38 to 3.40E + 384 bytes

Date and Time Data Types

Data typeDescriptionStorage
dateStore a date only. From January 1, 0001 to December 31, 99993 bytes
timeStore a time only to an accuracy of 100 nanoseconds3-5 bytes
datetimeFrom January 1, 1753 to December 31, 9999 with an accuracy of 3.33 milliseconds8 bytes
datetime2From January 1, 0001 to December 31, 9999 with an accuracy of 100 nanoseconds6-8 bytes
smalldatetimeFrom January 1, 1900 to June 6, 2079 with an accuracy of 1 minute4 bytes
datetimeoffsetThe same as datetime2 with the addition of a time zone offset8-10 bytes
timestampStores a unique number that gets updated every time a row gets created or modified. The timestamp value is based upon an internal clock and does not correspond to real time. Each table may have only one timestamp variable

Other Data Types

Data typeDescription
sql_variantStores up to 8,000 bytes of data of various data types, except text, ntext, and timestamp
uniqueidentifierStores a globally unique identifier (GUID)
xmlStores XML formatted data. Maximum 2GB
cursorStores a reference to a cursor used for database operations
tableStores a result-set for later processing

MS Access Data Types

Data typeDescriptionStorage
TextUse for text or combinations of text and numbers. 255 characters maximum
MemoMemo is used for larger amounts of text. Stores up to 65,536 characters. Note: You cannot sort a memo field. However, they are searchable
ByteAllows whole numbers from 0 to 2551 byte
IntegerAllows whole numbers between -32,768 and 32,7672 bytes
LongAllows whole numbers between -2,147,483,648 and 2,147,483,6474 bytes
SingleSingle precision floating-point. Will handle most decimals4 bytes
DoubleDouble precision floating-point. Will handle most decimals8 bytes
CurrencyUse for currency. Holds up to 15 digits of whole dollars, plus 4 decimal places. Tip: You can choose which country's currency to use8 bytes
AutoNumberAutoNumber fields automatically give each record its own number, usually starting at 14 bytes
Date/TimeUse for dates and times8 bytes
Yes/NoA logical field can be displayed as Yes/No, True/False, or On/Off. In code, use the constants True and False (equivalent to -1 and 0). Note: Null values are not allowed in Yes/No fields1 bit
Ole ObjectCan store pictures, audio, video, or other BLOBs (Binary Large Objects)up to 1GB
HyperlinkContain links to other files, including web pages
Lookup WizardLet you type a list of options, which can then be chosen from a drop-down list4 bytes

Chapter

Back to SQL References

Next

SQL ADD Keyword

This chapter

Overview
371

Lessons

778m

Read time

1. SQL Data Types for MySQL, SQL Server, and MS Access2. SQL ADD Keyword3. SQL ADD CONSTRAINT Keyword4. SQL ALL Keyword5. SQL ALTER Keyword6. SQL ALTER COLUMN Keyword7. SQL ALTER TABLE Keyword8. SQL ALTER VIEW Keyword9. SQL AND Keyword10. SQL ANY Keyword11. SQL AS Keyword12. SQL ASC Keyword13. SQL BACKUP DATABASE Keyword14. SQL BETWEEN Keyword15. SQL CASE Keyword16. SQL CHECK Keyword17. SQL COLUMN Keyword18. SQL CONSTRAINT Keyword19. SQL CREATE Keyword20. SQL CREATE DATABASE Keyword21. SQL CREATE INDEX Keyword22. SQL CREATE OR REPLACE VIEW Keyword23. SQL CREATE TABLE Keyword24. SQL CREATE PROCEDURE Keyword25. SQL CREATE UNIQUE INDEX Keyword26. SQL CREATE VIEW Keyword27. SQL DATABASE Keyword28. SQL DEFAULT Keyword29. SQL DELETE Keyword30. SQL DESC Keyword31. SQL SELECT DISTINCT Keyword32. SQL DROP Keyword33. SQL DROP COLUMN Keyword34. SQL DROP CONSTRAINT Keyword35. SQL DROP DATABASE Keyword36. SQL DROP DEFAULT Keyword37. SQL DROP INDEX Keyword38. SQL DROP TABLE and TRUNCATE TABLE Keywords39. SQL DROP VIEW Keyword40. SQL EXEC Keyword41. SQL EXISTS Keyword42. SQL FOREIGN KEY Keyword43. SQL FROM Keyword44. SQL FULL OUTER JOIN Keyword45. SQL GROUP BY Keyword46. SQL HAVING Keyword47. SQL IN Keyword48. SQL INDEX Keyword49. SQL INNER JOIN Keyword50. SQL INSERT INTO Keyword51. SQL INSERT INTO SELECT Keyword52. SQL IS NULL Keyword53. SQL IS NOT NULL Keyword54. SQL JOIN Keyword55. SQL LEFT JOIN Keyword56. SQL LIKE Keyword57. SQL SELECT TOP, LIMIT and ROWNUM Keywords58. SQL NOT Keyword59. SQL NOT NULL Keyword60. SQL OR Keyword61. SQL ORDER BY Keyword62. SQL FULL OUTER JOIN Keyword63. SQL PRIMARY KEY Keyword64. SQL CREATE PROCEDURE Keyword65. SQL RIGHT JOIN Keyword66. SQL SELECT TOP, LIMIT and ROWNUM Keywords67. SQL SELECT Keyword68. SQL SELECT DISTINCT Keyword69. SQL SELECT INTO Keyword70. SQL SELECT TOP, LIMIT and ROWNUM Keywords71. SQL SET Keyword72. SQL TABLE Keyword73. SQL SELECT TOP, LIMIT and ROWNUM Keywords74. SQL DROP TABLE and TRUNCATE TABLE Keywords75. SQL UNION Keyword76. SQL UNION ALL Keyword77. SQL UNIQUE Keyword78. SQL UPDATE Keyword79. SQL VALUES Keyword80. SQL VIEW Keyword81. SQL WHERE Keyword82. MySQL Functions83. MySQL ASCII() Function84. MySQL CHAR_LENGTH() Function85. MySQL CHARACTER_LENGTH() Function86. MySQL CONCAT() Function87. MySQL CONCAT_WS() Function88. MySQL FIELD() Function89. MySQL FIND_IN_SET() Function90. MySQL FORMAT() Function91. MySQL INSERT() Function92. MySQL INSTR() Function93. MySQL LCASE() Function94. MySQL LEFT() Function95. MySQL LENGTH() Function96. MySQL LOCATE() Function97. MySQL LOWER() Function98. MySQL LPAD() Function99. MySQL LTRIM() Function100. MySQL MID() Function101. MySQL POSITION() Function102. MySQL REPEAT() Function103. MySQL REPLACE() Function104. MySQL REVERSE() Function105. MySQL RIGHT() Function106. MySQL RPAD() Function107. MySQL RTRIM() Function108. MySQL SPACE() Function109. MySQL STRCMP() Function110. MySQL SUBSTR() Function111. MySQL SUBSTRING() Function112. MySQL SUBSTRING_INDEX() Function113. MySQL TRIM() Function114. MySQL UCASE() Function115. MySQL UPPER() Function116. MySQL ABS() Function117. MySQL ACOS() Function118. MySQL ASIN() Function119. MySQL ATAN() Function120. MySQL ATAN2() Function121. MySQL AVG() Function122. MySQL CEIL() Function123. MySQL CEILING() Function124. MySQL COS() Function125. MySQL COT() Function126. MySQL COUNT() Function127. MySQL DEGREES() Function128. MySQL DIV Function129. MySQL EXP() Function130. MySQL FLOOR() Function131. MySQL GREATEST() Function132. MySQL LEAST() Function133. MySQL LN() Function134. MySQL LOG() Function135. MySQL LOG10() Function136. MySQL LOG2() Function137. MySQL MAX() Function138. MySQL MIN() Function139. MySQL MOD() Function140. MySQL PI() Function141. MySQL POW() Function142. MySQL POWER() Function143. MySQL RADIANS() Function144. MySQL RAND() Function145. MySQL ROUND() Function146. MySQL SIGN() Function147. MySQL SIN() Function148. MySQL SQRT() Function149. MySQL SUM() Function150. MySQL TAN() Function151. MySQL TRUNCATE() Function152. MySQL ADDDATE() Function153. MySQL ADDTIME() Function154. MySQL CURDATE() Function155. MySQL CURRENT_DATE() Function156. MySQL CURRENT_TIME() Function157. MySQL CURRENT_TIMESTAMP() Function158. MySQL CURTIME() Function159. MySQL DATE() Function160. MySQL DATEDIFF() Function161. MySQL DATE_ADD() Function162. MySQL DATE_FORMAT() Function163. MySQL DATE_SUB() Function164. MySQL DAY() Function165. MySQL DAYNAME() Function166. MySQL DAYOFMONTH() Function167. MySQL DAYOFWEEK() Function168. MySQL DAYOFYEAR() Function169. MySQL EXTRACT() Function170. MySQL FROM_DAYS() Function171. MySQL HOUR() Function172. MySQL LAST_DAY() Function173. MySQL LOCALTIME() Function174. MySQL LOCALTIMESTAMP() Function175. MySQL MAKEDATE() Function176. MySQL MAKETIME() Function177. MySQL MICROSECOND() Function178. MySQL MINUTE() Function179. MySQL MONTH() Function180. MySQL MONTHNAME() Function181. MySQL NOW() Function182. MySQL PERIOD_ADD() Function183. MySQL PERIOD_DIFF() Function184. MySQL QUARTER() Function185. MySQL SECOND() Function186. MySQL SEC_TO_TIME() Function187. MySQL STR_TO_DATE() Function188. MySQL SUBDATE() Function189. MySQL SUBTIME() Function190. MySQL SYSDATE() Function191. MySQL TIME() Function192. MySQL TIME_FORMAT() Function193. MySQL TIME_TO_SEC() Function194. MySQL TIMEDIFF() Function195. MySQL TIMESTAMP() Function196. MySQL TO_DAYS() Function197. MySQL WEEK() Function198. MySQL WEEKDAY() Function199. MySQL WEEKOFYEAR() Function200. MySQL YEAR() Function201. MySQL YEARWEEK() Function202. MySQL BIN() Function203. MySQL BINARY Function204. MySQL CASE Function205. MySQL CAST() Function206. MySQL COALESCE() Function207. MySQL CONNECTION_ID() Function208. MySQL CONV() Function209. MySQL CONVERT() Function210. MySQL CURRENT_USER() Function211. MySQL DATABASE() Function212. MySQL IF() Function213. MySQL IFNULL() Function214. MySQL ISNULL() Function215. MySQL LAST_INSERT_ID() Function216. MySQL NULLIF() Function217. MySQL SESSION_USER() Function218. MySQL SYSTEM_USER() Function219. MySQL USER() Function220. MySQL VERSION() Function221. SQL Server Functions222. SQL Server ASCII() Function223. SQL Server CHAR() Function224. SQL Server CHARINDEX() Function225. SQL Server CONCAT() Function226. SQL Server Concat With +227. SQL Server CONCAT_WS() Function228. SQL Server DATALENGTH() Function229. SQL Server DIFFERENCE() Function230. SQL Server FORMAT() Function231. SQL Server LEFT() Function232. SQL Server LEN() Function233. SQL Server LOWER() Function234. SQL Server LTRIM() Function235. SQL Server NCHAR() Function236. SQL Server PATINDEX() Function237. SQL Server QUOTENAME() Function238. SQL Server REPLACE() Function239. SQL Server REPLICATE() Function240. SQL Server REVERSE() Function241. SQL Server RIGHT() Function242. SQL Server RTRIM() Function243. SQL Server SOUNDEX() Function244. SQL Server SPACE() Function245. SQL Server STR() Function246. SQL Server STUFF() Function247. SQL Server SUBSTRING() Function248. SQL Server TRANSLATE() Function249. SQL Server TRIM() Function250. SQL Server UNICODE() Function251. SQL Server UPPER() Function252. SQL Server ABS() Function253. SQL Server ACOS() Function254. SQL Server ASIN() Function255. SQL Server ATAN() Function256. SQL Server ATN2() Function257. SQL Server AVG() Function258. SQL Server CEILING() Function259. SQL Server COUNT() Function260. SQL Server COS() Function261. SQL Server COT() Function262. SQL Server DEGREES() Function263. SQL Server EXP() Function264. SQL Server FLOOR() Function265. SQL Server LOG() Function266. SQL Server LOG10() Function267. SQL Server MAX() Function268. SQL Server MIN() Function269. SQL Server PI() Function270. SQL Server POWER() Function271. SQL Server RADIANS() Function272. SQL Server RAND() Function273. SQL Server ROUND() Function274. SQL Server SIGN() Function275. SQL Server SIN() Function276. SQL Server SQRT() Function277. SQL Server SQUARE() Function278. SQL Server SUM() Function279. SQL Server TAN() Function280. SQL Server CURRENT_TIMESTAMP Function281. SQL Server DATEADD() Function282. SQL Server DATEDIFF() Function283. SQL Server DATEFROMPARTS() Function284. SQL Server DATENAME() Function285. SQL Server DATEPART() Function286. SQL Server DAY() Function287. SQL Server GETDATE() Function288. SQL Server GETUTCDATE() Function289. SQL Server ISDATE() Function290. SQL Server MONTH() Function291. SQL Server SYSDATETIME() Function292. SQL Server YEAR() Function293. SQL Server CAST() Function294. SQL Server COALESCE() Function295. SQL Server CONVERT() Function296. SQL Server CURRENT_USER Function297. SQL Server IIF() Function298. SQL Server ISNULL() Function299. SQL Server ISNUMERIC() Function300. SQL Server NULLIF() Function301. SQL Server SESSION_USER Function302. SQL Server SESSIONPROPERTY() Function303. SQL Server SYSTEM_USER Function304. SQL Server USER_NAME() Function305. MS Access Functions306. MS Access Asc() Function307. MS Access C hr() Function308. MS Access Concat With &309. MS Access CurDir() Function310. MS Access Format() Function311. MS Access InStr() Function312. MS Access InstrRev() Function313. MS Access LCase() Function314. MS Access Left() Function315. MS Access Len() Function316. MS Access LTrim() Function317. MS Access Mid() Function318. MS Access Replace() Function319. MS Access Right() Function320. MS Access RTrim() Function321. MS Access Space() Function322. MS Access Split() Function323. MS Access Str() Function324. MS Access StrComp() Function325. MS Access StrConv() Function326. MS Access StrReverse() Function327. MS Access Trim() Function328. MS Access UCase() Function329. MS Access Abs() Function330. MS Access Atn() Function331. MS Access Avg() Function332. MS Access Cos() Function333. MS Access Count() Function334. MS Access Exp() Function335. MS Access Fix() Function336. MS Access Format() Function337. MS Access Int() Function338. MS Access Max() Function339. MS Access Min() Function340. MS Access Randomize() Function341. MS Access Rnd Function342. MS Access Round() Function343. MS Access Sgn() Function344. MS Access Sqr() Function345. MS Access Sum() Function346. MS Access Val() Function347. MS Access Date() Function348. MS Access DateAdd() Function349. MS Access DateDiff() Function350. MS Access DatePart() Function351. MS Access DateSerial() Function352. MS Access DateValue() Function353. MS Access Day() Function354. MS Access Format() Function355. MS Access Hour() Function356. MS Access Minute() Function357. MS Access Month() Function358. MS Access MonthName() Function359. MS Access Now() Function360. MS Access Second() Function361. MS Access Time() Function362. MS Access TimeSerial() Function363. MS Access TimeValue() Function364. MS Access Weekday() Function365. MS Access WeekdayName() Function366. MS Access Year() Function367. MS Access CurrentUser() Function368. MS Access Environ() Function369. MS Access IsDate() Function370. MS Access IsNull() Function371. MS Access IsNumeric() Function

On this page

SQL Data TypesMySQL Data Types (Version 8.4)String Data TypesNumeric Data TypesDate and Time Data TypesSQL Server Data TypesString Data TypesNumeric Data TypesDate and Time Data TypesOther Data TypesMS Access Data Types