SQL Data Types (2024)

Binary

BINARY

1 to 65,000

Fixed-length binary string

NULLSLAST VARBINARY

1 to 65,000

Variable-length binary string

NULLSLAST LONG VARBINARY

1to32,000,000

Long variable-length binary string

NULLSLAST BYTEA

SynonymsforVARBINARY

RAW

Boolean

BOOLEAN

1

True or False or NULL

NULLSLAST

Character / Long

CHAR

1 to 65,000

Fixed-length character string

NULLSLAST VARCHAR

1 to 65,000

Variable-length character string

NULLSLAST LONG VARCHAR

1 to 32,000,000

Long variable-length character string

NULLSLAST

Date/Time

DATE

8

Represents a month, day, and year

NULLSFIRST TIME

8

Represents a time of day without timezone

NULLSFIRST DATETIME SynonymsforTIMESTAMP SMALLDATETIME TIME WITH TIMEZONE

8

Represents a time of day with timezone

NULLSFIRST TIMESTAMP

8

Represents a date and time without timezone

NULLSFIRST TIMESTAMPWITHTIMEZONE

8

Represents a date and time with timezone

NULLSFIRST INTERVAL

8

Measures the difference between two points in time

NULLSFIRST INTERVALDAYTOSECOND 8

Represents an interval measured in days and seconds

NULLSFIRST INTERVALYEARTOMONTH 8

Represents an interval measured in years and months

NULLSFIRST

Approximate Numeric

DOUBLE PRECISION

8

Signed 64-bit IEEE floating point number, requiring 8 bytes of storage

NULLSLAST FLOAT

8

Signed 64-bit IEEE floating point number, requiring 8 bytes of storage

NULLSLAST FLOAT(n)

8

Signed 64-bit IEEE floating point number, requiring 8 bytes of storage

NULLSLAST FLOAT8

8

Signed 64-bit IEEE floating point number, requiring 8 bytes of storage

NULLSLAST REAL

8

Signed 64-bit IEEE floating point number, requiring 8 bytes of storage

NULLSLAST

Exact Numeric

INTEGER 8

Signed 64-bit integer, requiring 8 bytes of storage

NULLSFIRST INT 8

Signed 64-bit integer, requiring 8 bytes of storage

NULLSFIRST BIGINT 8

Signed 64-bit integer, requiring 8 bytes of storage

NULLSFIRST INT8 8

Signed 64-bit integer, requiring 8 bytes of storage

NULLSFIRST SMALLINT 8

Signed 64-bit integer, requiring 8 bytes of storage

NULLSFIRST TINYINT 8

Signed 64-bit integer, requiring 8 bytes of storage

NULLSFIRST DECIMAL 8+

8 bytes for the first 18 digits of precision, plus 8 bytes for each additional 19 digits

NULLSFIRST NUMERIC 8+

8 bytes for the first 18 digits of precision, plus 8 bytes for each additional 19 digits

NULLSFIRST NUMBER 8+

8 bytes for the first 18 digits of precision, plus 8 bytes for each additional 19 digits

NULLSFIRST MONEY 8+

8 bytes for the first 18 digits of precision, plus 8 bytes for each additional 19 digits

NULLSFIRST Spatial GEOMETRY 1 to 10,000,000 Coordinates expressed as (x,y) pairs, defined in the Cartesian plane. NULLSLAST GEOGRAPHY 1 to 10,000,000 Coordinates expressed in longitude/latitude angular values, measured in degrees UUID UUID 16 Stores universally unique identifiers (UUIDs). NULLSFIRST Complex ARRAY 1to32,000,000 Collection of values of a primitive type. Same as the primitive type SET 1to32,000,000 Collection of unique values of a primitive type. Same as the primitive type
SQL Data Types (2024)

FAQs

What is the best practice of data types in SQL? ›

A best practice is to “right size” data types by asking business questions and determining the data types that are best suited to the organization's and application's needs. Right-sizing can result in tremendous storage savings, which can lead to faster database performance.

How many data types are in SQL? ›

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. In MySQL there are three main data types: string, numeric, and date and time.

How to check datatypes in SQL? ›

In SQL Runner, you can use these queries:
  1. MySQL: SELECT. COLUMN_NAME, DATA_TYPE. FROM. INFORMATION_SCHEMA.COLUMNS. WHERE. ...
  2. PostgreSQL: pg_typeof(col_name)
  3. Redshift: SELECT "column", type. FROM PG_TABLE_DEF. WHERE tablename = 'table_name' AND "column" = 'column_name' BQ Legacy and Standard don't support these types of queries.
Jul 5, 2021

What are the limits of datatype in SQL? ›

The integer data types
SQL integer data typeNumber of bytesRange of values
SMALLINT2-32767 to 32767
INTEGER, INT, SERIAL4-2,147,483,647 to 2,147,483,647
INT8, BIGINT, SERIAL8, BIGSERIAL8-9,223,372,036,854,775,807 to 9,223,372,036,854,775,807

What data types should be avoided in SQL Server? ›

Note: SQL Server will deprecate ntext, text and image data type in future releases. We should avoid the use of these data types. You can use Nvarchar(max), varchar(max), and varbinary(max).

How do you choose the correct data type? ›

The general rule of thumb for choosing a data type for the columns in your tables is to choose the data type that most closely matches the domain of correct values for the column. That means you should try to adhere to the following rules: If the data is numeric, favor SMALLINT, INTEGER, BIGINT, or DECIMAL data types.

What are the basic data types in SQL? ›

A data type is an attribute that specifies the type of data that the object can hold: integer data, character data, monetary data, date and time data, binary strings, and so on. SQL Server supplies a set of system data types that define all the types of data that can be used with SQL Server.

What are the 5 types of SQL? ›

These SQL commands are mainly categorized into five categories:
  • DDL – Data Definition Language.
  • DQL – Data Query Language.
  • DML – Data Manipulation Language.
  • DCL – Data Control Language.
  • TCL – Transaction Control Language.
Aug 2, 2023

Why are data types important in SQL? ›

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. Note: Data types might have different names in different database. And even if the name is the same, the size and other details may be different!

What is the real data type in SQL Server? ›

Real data can hold a value 4 bytes in size, meaning it has 7 digits of precision (the number of digits to the right of the decimal point). It's also a floating-point numeric that is identical to the floating point statement float(24).

What is VARCHAR in SQL? ›

Varchar is a datatype in SQL that holds characters of variable length. This data type stores character strings of up to 255 bytes in a variable-length field. The data can consist of letters, numbers, and symbols. It uses dynamic memory location.

What is the limit of data type? ›

In this article
Type NameBytesRange of Values
unsigned short20 to 65,535
long4-2,147,483,648 to 2,147,483,647
unsigned long40 to 4,294,967,295
long long8-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
21 more rows
Aug 2, 2021

How to write number data type in SQL? ›

SQL numeric data types are used to store numeric values in a database. The most commonly used numeric data types are INT and FLOAT . The INT data type is used to store whole numbers, while the FLOAT data type is used to store decimal numbers. The INT data type can store values ranging from -2^31 to 2^31-1.

What is the limitation of number data type? ›

"The NUMBER data type stores zero as well as positive and negative fixed numbers with absolute values from 1.0 x 10^-130 to but not including 1.0 x 10^126." "The precision p can range from 1 to 38. The scale s can range from -84 to 127."

How to practice SQL for data analysis? ›

1. Use Meaningful Alias Names. A key principle of writing clean SQL queries is using meaningful aliases for tables and columns. This practice improves query readability and helps others understand your code more easily.

What is the most efficient SQL database? ›

According to the 2023 Developer Survey by Stack Overflow, PostgreSQL is the best database, followed by MySQL and SQLite.

Which of the following are best practices for data management? ›

7 Best Practices for Successful Data Management
  1. Build strong file naming and cataloging conventions. ...
  2. Carefully consider metadata for data sets. ...
  3. Data Storage. ...
  4. Documentation. ...
  5. Commitment to data culture. ...
  6. Data quality trust in security and privacy. ...
  7. Invest in quality data-management software.

Top Articles
Latest Posts
Article information

Author: Rubie Ullrich

Last Updated:

Views: 6412

Rating: 4.1 / 5 (72 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Rubie Ullrich

Birthday: 1998-02-02

Address: 743 Stoltenberg Center, Genovevaville, NJ 59925-3119

Phone: +2202978377583

Job: Administration Engineer

Hobby: Surfing, Sailing, Listening to music, Web surfing, Kitesurfing, Geocaching, Backpacking

Introduction: My name is Rubie Ullrich, I am a enthusiastic, perfect, tender, vivacious, talented, famous, delightful person who loves writing and wants to share my knowledge and understanding with you.