SQL Data Types | Data Types in SQL Server

Keeping you updated with latest technology trends, Join DataFlair on Telegram

1. SQL Data Types

In our last SQL tutorial, we discussed SQL Operators. Today, we will see SQL Data Types. First, we will look at what is the data type in SQL. Moreover, we will discuss SQL general data type and 6 majorly use SQL server data types.
So, let’s start SQL Data Types.

SQL Data Types

SQL Data Types | Data Types in SQL Server

2. What is Data Type in SQL?

Each column in a very database table is needed to possess a name and a data type. SQL developers ought to decide what types of data are going to be kept within every and each table column once making a SQL table. The type may be a label and a tenet for SQL to know what variety of data is anticipated within every column, and it additionally identifies. However, SQL can act with the keep data.
Do you know about SQL RDBMS Concept

3. SQL General Data Types

Following are some General SQL Data Types and their description:

Data Type Description
CHARACTER(n) Character string with fixed length n
VARCHAR(n) or
CHARACTER VARYING(n)
It is character string with fixed maximum variable length n
BINARY(n) It is a binary string with a fixed length
BOOLEAN This stores TRUE or FALSE values.
VARBINARY(n) or
BINARY VARYING(n)
It is a binary string with fixed variable length n.
INTEGER(p) It is an integer numerical with no decimal, here p is precision
SMALLINT It is also an integer numerical with no decimal and precision 5
INTEGER It is the same as the mentioned above types with the only difference of precision 10
BIGINT Here precision is 19
DECIMAL(p,s) It is an exact numerical with precision p and scale s
NUMERIC(p,s) It is an exact numerical with numerical with precision p and scale s
FLOAT It is an approximate numerical with mantissa precision 16
REAL It is an approximate numerical with mantissa precision 7
FLOAT(p) It is an approximate numerical with mantissa precision p, in this type a single precision is mentioned which specifies the minimum value.
DOUBLE PRECISION It is an approximate numerical with mantissa precision 16
DATE It stores the value for a date, time and the days
TIME It stores the value of seconds, minutes and hours
ARRAY It stores the value of seconds, minutes, hours, months and years
MULTISET It is an unordered collection of elements of variable length
XML This stores XML data
TIMESTAMP An ordered collection of data with a set length
INTERVAL It represents a period of time, which depends on the interval time and is composed of integer fields

Have a look at RDBMS Database System

TINYTEXT Holds a string with a most extreme length of 255 characters
TEXT Holds a string with a most extreme length of 65,535 characters
BLOB For BLOBs (Binary Large Object). Holds up to 65,535 bytes of information
MEDIUMTEXT Holds a string with a most extreme length of 16,777,215 characters
MEDIUMBLOB For BLOBs (Binary Large Object). It holds up to 16,777,215 bytes of information
LONGTEXT Holds a string with a most extreme length of 4,294,967,295 characters
LONGBLOB For BLOBs (Binary Large Object). Holds up to 4,294,967,295 bytes of information
ENUM(x,y,z,etc.) Let you enter a rundown of conceivable qualities. You can list up to 65535 qualities in an ENUM list. In the event that an esteem is embedded, that isn’t in the rundown, a clear esteem will be embedded.
SET Similar to ENUM with the exception of that SET may contain up to 64 list things and can store in excess of one decision

4. SQL Server Data Types

SQL server offers 6 types of data types. Let’s discuss them one by one:

SQL Data Types

SQL Server Data Types

a. Exact numeric data type SQL

  • bigint 9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
  • int  –2,147,483,648 to 2,147,483,647
  • smallint 32,768 to 32,767
  • tinyint 0 to 255
  • bit  0 to 1
  • decimal  –10^38 +1 to 10^38 -1
  • numeric  –10^38 +1 to 10^38 -1
  • money 922,337,203,685,477.5808 to +922,337,203,685,477.5807
  • smallmoney  –214,748.3648 to +214,748.3647

b. Approximate Numeric Data Types

  • float 1.79E + 308 to 1.79E + 308
  • real 3.40E + 38 to 3.40E + 38

c. Date and Time SQL Data Types

  • datetime
  • smalldatetime
  • date
  • time

d. Character Strings Data Types

  • char
  • varchar
  • varchar(max)
  • text

e. Unicode Character Strings Data Types

  • nchar
  • nvarchar
  • nvarchar(max)
  • ntext

f. Binary Data Types

  • binary
  • varbinary
  • varbinary(max)
  • image

g. Misc Data Types

  • sql_variant
  • timestamp
  • uniqueidentifier
  • xml
  • cursor
  • table

So, this was all in SQL Data Types. Hope you like our explanation.

5. Conclusion

Hence, in this SQL Data Types tutorial, we learned about the general data types used in SQL. Moreover, we discussed 6 basic SQL Server Data Types. Still, if any query regarding SQL Data Types, ask in the comment tab.
For reference

1 Response

  1. SANKET KADU says:

    Which type of datatypes is require for data analysis

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.