With the amount of data present in the world, it is almost next to impossible, to manage data without proper databases. SQL is the core of relational databases which provides you with various options to deal with data, therefore SQL skills are indispensable in most of the job roles. In this article on SQL Data types, we are going to discuss the different data types used in SQL.
The following are covered in this article:
- Numeric Data Types
- Character String Data Types
- Binary Data Types
- Date & Time Data Types
- Other Data Types
So, let us get started with each one of them.
SQL Data Types: Numeric Types
This section of the article will talk about the numeric data types. These data types allow both signed and unsigned integers. I have divided the numeric data types into the following two sections:
Exact Numeric Data Types
Now, let us look into Approximate Numeric Data Types.
Approximate Numeric Data Types
Next, in this article let us look into the character string data types used in SQL.
SQL Data Types: Character String Data Types
This section of the article will talk about the character data types. These data types allow characters of fixed and variable length. Refer to the below table.
NOTE:
Also, I have extended the character strings data type sections to Unicode data types since our industry uses the Unicode for consistent representation and handling of text in most of the world’s writing systems.
Unicode Character Strings Data Types
Data Type | Description / Maximum Size | Storage | |
Description | Maximum Size | ||
ntext | Allows a variable length Unicode string | 2GB of text data | 4 bytes + number of chars |
nvarchar(max) | Allows a variable length Unicode string | 2E + 31 characters | 2 bytes + number of chars |
nvarchar | Allows a variable length Unicode string | 4,000 characters | 2 bytes + number of chars |
nchar | Allows a fixed length Unicode string | 4,000 characters | Defined width * 2 |
Next, in this article let us look into the binary data types used in SQL.
SQL Data Types: Binary Data Types
This section of the article will talk about binary data types. These data types allow binary values of fixed and variable length. Refer to the below table.
Next, in this article let us look into the date and time data types used in SQL.
SQL Data Types: Date & Time Data Types
This section of the article will talk about the date and time data types. These data types allow different formats of date and time. Refer to the below table.
Next, in this article let us look into the miscellaneous data types available in SQL.
SQL Data Types: Other Data Types
This section of the article will talk about the data types that cannot be categorized into the above categories. Refer to the below table.
Data Type | Description |
table | This data type stores a result set for later processing. |
xml | This data type stores XML formatted data. |
cursor | This data type provides a reference to a cursor object. |
uniqueidentifier | This data type stores a globally unique identifier (GUID). |
sql_variant | This data type stores values of various SQL supported data types except text, ntext, and timestamp. |
Now that you know the data types in SQL, I’m sure you’re curious to learn more SQL. Here’s a list of articles that you get started with:
So, folks, that’s an end to this article. I hope you enjoyed reading this article. We have seen the different data types that will help you write queries and play around with your databases. If you wish to learn more about MySQL and get to know this open source relational database, then check out our MySQL DBA Certification Training which comes with instructor-led live training and real-life project experience. This training will help you understand MySQL in depth and help you achieve mastery over the subject.
For details, You can even check out how to manage databases on SQL Server and its concepts with the Microsoft SQL Server Certification course.
Got a question for us? Please mention it in the comments section of this article and I will get back to you.