Introduction

In this article, we will learn about Data Types in SQL with different data types.

Data Types in SQL

  1. Each column, local variable, expression, and parameter in a database has a related data type.
  2. A data type is an attribute that specifies the type of data that the object can hold.
  3. The following are the various data types
    • Integer Types
    • Boolean Type
    • Decimal Types
    • Monetary or Currency Types
    • Date and Time Values
    • String Values
    • Binary Values
    • Timestamp
    • Unique identifier
    • XML

Integer Types

  1. Integer Types hold integer values.
  2. The Integer Types are tinyint, smallint, int, and bigint data types with sizes 1, 2, 4, and 8 bytes, respectively.
    Integer Types Bytes
    tinyint 1
    Smallint 2
    Int 4
    Bigint 8

Boolean Type

  1. A Boolean Type can hold boolean values
  2. It can provide a "bit" data type that can take a value of 1, 0, or NULL. Note
    The string values TRUE and FALSE can be converted to bit values: TRUE is converted to 1, and FALSE is converted to 0.

Decimal Types

  1. Decimal Types hold decimal values.
  2. They provide the following types:
    • decimal and numeric
    • float and real

Decimal and numeric

Float and Real

Monetary or Currency Types

  1. Monetary or Currency Types hold currency values.
  2. It provides the small-money and money data types with sizes of 4 and 8 bytes, respectively.
    Monetary Types Bytes
    Smallmoney 4
    Money 8

Date and Time Values

  1. Date and Time Values hold the Date and Time values of a day.
  2. It provides the following types:
    • smalldatetime
    • datetime
    Data type Range Accuracy
    Smalldatetime January 1, 1900, through June 6, 2079 1 minute
    Datetime January 1, 1753, through December 31, 9999 3.33 milliseconds

Smalldatetime

Datetime

String Values

  1. String Values hold the string values
  2. String Values types are:
    • Char
    • Varchar
    • Text
    • Nchar
    • Nvarchar
    • Ntext

Char

Varchar

Text

Nchar

Nvarchar

Ntext

Binary Values

  1. Binary Values hold binary values like images, audio, and video clips.
  2. Binary Values types are:
    • binary
    • varbinary
    • Image

Binary

Varbinary

Image

Timestamp

Uniqueidentifier

XML

Note

Summary

In this article, we learned about Data types in SQL.