×

SQL Data Types

In SQL DATA TYPES, each column holds value. Data types can be an integer type, character type, etc., and such data is stored in the database table.

The data type is a source for SQL columns to understand which kind of records to be added to the table columns. Suppose we have table name employee, and we store employee id then we have to declare the numeric data type.

SQL DATA TYPES are classified into three different types:

1. String Data Types.

2. Numeric Data Types.

3. Data and Time Data Types.

Now, we will discuss the types of datatypes one by one. So, Let’s start with String data type.

1 String Data Type: -

String Data types are related to character type, allowing the user to define the character data type, which can be variable length or fixed length.

(I). Char(n): -

Char(n) is a non-Unicode character. Char(n) is the Fixed-length character string data type.

(II). Varchar(n): -

Varchar(n) is non-Unicode data. Varchar(n) is a character string data type of variable length.

(III). Varchar(max): -

Varchar(max) is a non-Unicode data. Varchar(max) is character string data type of a variable length. Varchar(max) can store a max of 1,073,741,824 characters.

(IV). Text: -

Text is non-Unicode data. Text is the character string data type of a variable length. The text data type can store a maximum of 2,147,483,647 characters.

Let’s discuss Unicode Character String Data Types.

(V). nchar: -

nchar is a Unicode Character String Data Types of fixed length. nchar can store a max of 4000 characters.

(VI). nvarchar: -

nvarchar is a Unicode character String Data Types of variable length. nvarchar stores a max of 4000 characters.

(VII). nvarchar(max): -

nvarchar(max) is a Unicode character String Data Types of variable length. nvarchar(max) stores a max of 536,870,912 characters.

(VIII). ntext: -

ntext is a Unicode character String Data Types of variable length. ntext stores a max of 1,073,741,823 characters.

The data types below are binary string types containing a binary string of fixed or variable length.

(IX). Binary: -

Binary is a fixed-length binary string data type. The binary data type can store a max of 8000 bytes.

(X). VarBinary: -

VarBinary is a variable-length binary string data type. The VarBinary can store a max of 8000 bytes.

(XI). Image: -

Image is a variable-length binary string data type. Image stores a max of 2,147,483,647 bytes.

2. Numeric Data Types: -

(I). Bit: -

The Bit is an integer that can take 0, 1 and null values.

(II). Tinyint: -

In tinyint, the whole number stores whose range is from 0 to 255.

(III). Smallint: -

Smallint stores wholes number in the range given between -32,768 and 32,767.

(IV). Int: -

Int stores whole number in the range given between -2,147,483,648 and 2,147,483,647.

(V). Bigint: -

Bigint stores whole number in the range given between -9,223,372,036,854,775,808 and 9,223,372,036,854,775,807.

(VI). Float(n): -

The Float used to declare float precision number data start from -1.79E + 308 and ends at 1.79E + 308. The n argument in the float data types specifies the field that can hold 4 or 8 bytes. 53 is the default value of parameter n.

(VII). Real: -

The Real data type is used for floating precision data numbers from -3.40E+38 to 3.40E+38.

(VIII). Money: -

Money is used to mention monetary records from -922,337,233,685,477.5808 to 922,337,233,685,477.5807.

(IX). Small money: -

 The Small money is used to specify monetary data from -214,748.3648 to 214,748.3647.

(X). Decimal (p, s): -

Decimal is used to specify fixed precision numbers and scale precision numbers.

Decimal allow numbers from -10^38 + 1 to 10^38-1. The parameter p in the decimal data type mentions the total topmost number of digits that can store. P defines a value between 1 to 38. The default value of p is 18.

The parameter s specifies the topmost number of digits stored to the right of the decimal point. S defines a value between 0 to p. Default value of s is 0.

(XI). Numeric (p, s): -

Numeric is used to specify fixed precision numbers and scale precision numbers.

Numeric allow numbers from -10^38 + 1 to 10^38-1. The parameter p in the numeric data type mentions total topmost number of digits that can store. P defines a value between 1 to 38. The default value of p is 18.

The parameter s specifies the topmost number of digits stored to the right of the decimal point. S defines a value between 0 to p. Default value of s is 0.

3. Date and Time Data Types: -

The date and time type of data is stored using the date and time data type.

(I). Datetime: -

Datetime is used to frame date and time, which support range from 1 January 1753 to 31 December 9999 with an accuracy of 3.33ms.

(II). Datetime2: -

Datetime2 is used to frame date and time, which support range from 1 January 0001 to 31 December 9999 with an accuracy of 100ns.

(III). Date: -

The Date data type is used to store data only, which support ranges from 1 January 0001 to 31 December 9999.

(IV). Time: -

Time data types use to store a time only with an accuracy of 100ns.


Related Topics

How to use the BETWEEN operator in SQL

In this entire SQL article, we will understand and learn about the BETWEEN operator concept and how to use it in SQL. What is the BETWEEN operator in SQL? The Between operator...

4 minutes read.

SQL Select Distinct

The SQL DISTINCT query is used to fetch unique values from the tables using the SELECT statement in the SQL. There may be a situation that arises when you want to...

4 minutes read.

SQL Count

Structured Query Language Count() Function is used with Structured Query Language SELECT Statement. SQL Count() function returns the number of items that match the specified criteria in the SELECT statement. Count()...

2 minutes read.

DML Commands in SQL

DML is an abbreviation of Data Manipulation Language. Data Manipulation Language commands in Structured Query Language manipulate the data in the database. DML commands are used to retrieve records, add records,...

4 minutes read.

SQL SELECT AVG

In this tutorial, we will learn about the aggregate function name avg() function concept in SQL with the help of examples. The AVG() function is one of the aggregate functions in...

3 minutes read.

What is SQL Injection?

Introduction to SQL Injection SQL injection is a vulnerability or a technique that might destroy the database of a website or a web application. It is one of the most widely...

4 minutes read.

SQL SELECT WHERE Clause

In this SQL section, we will help you understand the concept of the SQL SELECT WHERE clause with a few examples. The WHERE clause in SELECT query displays those records as...

5 minutes read.

SQL SELECT OR Operator

This SQL tutorial explains and helps us understand how to use the OR operator in the SELECT query with examples. The OR operator in the Structured Query Language is used to...

3 minutes read.

SQL Inner Join

In Structured Query Language, the most used join query is the Inner join query. Inner join query retrieves the records from one or more tables with similar data or records. The...

4 minutes read.

SQL Left Join

The SQL Left Join query displays all the records from the table and displays similar records from the right table. The query displays zero records if it doesn’t find any...

4 minutes read.

TCL Commands in SQL

In Structured Query Language, TCL is an abbreviation for Transaction Control Language. A single unit of work in a database is formed after the consecutive execution of commands is known...

6 minutes read.

SQL Queries

In a database, queries are used to request the result set of data from the table or action on the records. A Query can answer your simple or complicated question, perform...

5 minutes read.

SQL Between Operator

SQL Between operator is a logical operator in the Structured Query Language. The Between operator is used to retrieve data within the range specified in the condition in the query. The...

7 minutes read.

SQL SET Keyword

This article will provide you a good understanding of the Set keyword in Structured Query Language. What is the SET keyword? The SET keyword is used to specify values for the variables....

3 minutes read.

SQL DELETE

In this tutorial, you will learn about the SQL DELETE concept by using examples. In Structured Query Language (SQL), we fetch the data from the database table using SELECT Statement and...

3 minutes read.

SQL JOIN

As the name says, joins mean to merge something or to combine something. But in the case of SQL, joins mean to merge or combine two different tables. The Join clause...

12 minutes read.

SQL CREATE TABLE

In SQL tutorial, we learned and created different databases. To stores data in databases, we need to create a table. To create the table, we need to use CREATE TABLE...

5 minutes read.

SQL Right Join

The SQL Right Join query displays all the table records and similar records from the left table. The query display zero records if it doesn’t find any similar records. If...

4 minutes read.

WHERE Clause vs HAVING Clause

The WHERE Clause and HAVING clause filter the records in the Structured Query Language queries. The main difference between the WHERE clause and the HAVING clause is the WHERE clause...

5 minutes read.

SQL SELECT SUM

The SQL Sum() function is an aggregate function in SQL that returns the total values of an expression. The expression may be numerical, or it may be an expression. Syntax: SELECT SUM(columnname)...

3 minutes read.