Data types
Data types
BigInt
The bigint data type is intended for use when integer values might exceed the range that is
supported by the int data type. Like x = 9007199254740995n.
For Example:
Binary(50)
Since the binary data types are unstructured types, they can store many different types of
information. It can store IP addresses, MAC addresses, or device identification numbers from
RFID tags.
For Example:
Bit
The bit data type can be used to store Boolean values. The string values TRUE and FALSE
can be converted to bit values: TRUE is converted to 1 , and FALSE is converted to 0 .
For Example:
Char(10)
CHAR(10) is a fixed-length character data type that stores exactly 10 characters. When you
define a column as CHAR(10), the database reserves space for 10 characters, regardless of how
many characters are actually stored. If you insert a string shorter than 10 characters, the
database will pad it with spaces to ensure it occupies 10 characters.
For Example:
Date
The DATE type is used for values with a date part but no time part. MySQL retrieves and
displays DATE values in YYYY-MM-DD.
For Example:
CREATE TABLE Employees (
EmployeeID INT PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
BirthDate DATE -- Stores only the date part
);
DateTime
The DATETIME data type in SQL is used to store date and time information. It includes both
the date (year, month, day) and the time (hours, minutes, seconds).
For Example:
DateTime2(7)
DATETIME2(7) is a data type in SQL Server that stores date and time values with higher
precision and a wider date range compared to the standard DATETIME.
The (7) represents the fractional seconds precision, meaning it can store up to 7 decimal places
for the seconds component, which provides precision down to 100 nanoseconds.
For Example:
EventName NVARCHAR(100),
EventTimestamp DATETIME2(7)
);
Datetimeoffset(7)
Returns a datetime2(7) value containing the date and time of the computer on which the
instance of SQL server is running.
For Example:
Decimal(18,0)
DECIMAL(18,0) is a fixed-point data type in databases that stores exact numeric values
without any fractional (decimal) places.
Precision (18): This means the value can have up to 18 digits in total.
Scale (0): The scale of 0 means there are no digits after the decimal point. In other
words, it's used to store whole numbers (integers) with high precision, but without
any fractional or decimal part.
For Example:
Float
The float data types are used to store positive and negative numbers with a decimal point.
It can store values like , 35.3, -2.34, or 3597.34987.
For Example:
Geography
The geography spatial data type, geography, is implemented as a . NET common language
runtime (CLR) data type in SQL Server. This type represents data in a round-earth coordinate
system. The SQL Server geography data type stores ellipsoidal (round-earth) data, such as GPS
latitude and longitude coordinates.
For Example:
The GEOMETRY data type in databases (such as SQL Server, MySQL, and PostgreSQL with
PostGIS extension) is used to store planar (flat) spatial data. This type is typically used for
representing spatial objects like points, lines, polygons, and more in a two-dimensional (2D)
coordinate system. Unlike the GEOGRAPHY type, which accounts for the Earth's curvature,
GEOMETRY assumes a flat, Cartesian coordinate system.
For Example:
Hierrchyid
The HIERARCHYID data type in databases, specifically in Microsoft SQL Server, is used to
store hierarchical data in an efficient manner. It is designed to represent data with a tree-like
structure, such as organizational charts, file systems, or product categories, where each node
can have a parent-child relationship.
For Example:
The IMAGE data type in databases (like older versions of SQL Server) was historically used to
store binary large objects (BLOBs), specifically for storing large binary data such as
images, videos, or other multimedia content. However, in modern versions of SQL Server,
the IMAGE data type has been deprecated in favor of the more flexible VARBINARY(MAX)
type.
For Example:
Int
The INT data type in a database is used to store integer values, which are whole numbers
without any decimal places.it can store values like , 35 ,-10.
For Example:
Money
For Example:
Nchar(10)
The NCHAR(10) data type in databases is used to store fixed-length Unicode character
strings. The 10 specifies that each value stored in this column will have a length of exactly 10
characters, and if the data is shorter, it will be padded with spaces to reach the specified length.
For Example:
Ntext
The NTEXT data type in databases is used to store large amounts of Unicode text. It is a deprecated
data type in some database systems but was historically used for storing long text data with Unicode
support.
For Example:
For Example:
Nvarchar(50)
NVARCHAR(MAX) is a data type in SQL Server used to store variable-length Unicode data.
The "MAX" keyword allows the field to store up to 2^31-1 bytes of data (which is about 2 GB).
This is useful for storing large amounts of text that might exceed the usual 4,000-character limit
of a regular NVARCHAR field.
For Example:
Smalldatetime
The SMALLDATETIME data type in SQL Server is used to store date and time values with a
smaller range and precision compared to the DATETIME type. Specifically:
For Example:
Smallint
The SMALLINT data type in SQL is used to store small integer values. It is a 2-byte (16-bit) signed
integer, meaning it can store numbers within a limited range compared to larger integer types like INT
or BIGINT.
For Example:
Smallmoney
The SMALLMONEY data type in databases is used to store small monetary values. It has a
fixed precision and scale, and is typically used in financial applications where exact decimal
values are required but the range of values is relatively small.
For Example:
Sql-variant
The SQL_VARIANT data type in databases is used to store values of different data types in a
single column. It allows for flexible storage of various data types within a single column,
accommodating different types of data without requiring a separate column for each type.
For Example:
Text
The TEXT data type stores any kind of text data. It can contain both single-byte and multibyte
characters that the locale supports.
For Example:
Time(7)
Time(7) is a data type in SQL Server that stores time values with 7 decimal places of precision.
It has a range of 00:00:00.0000000 through 23:59:59.9999999.
For Example:
TinyInt
The TINYINT data type is used to store unsigned integers requiring 1 byte of storage.
For Example:
Timestamp
The TIMESTAMP data type is used to store a unique binary number that is automatically
generated each time a row is inserted or updated. It is often used to track changes to rows and
for concurrency control
For Example:
Uniqueidentifer
The Uniqueidentifier is a data type in Microsoft SQL Server , which is used to store Globally
Unique Identifier (GUIDs) . A GUID (globally unique identifier) is a 16-bit text string that
represents an identification (ID).
Commonly used for primary keys in tables where the uniqueness needs to be maintained
independently of the database system. It’s also useful in distributed systems and for data
integration scenarios.
For Example:
Varbinary(50)
The VARBINARY(50) data type in SQL Server is used to store variable-length binary data
with a maximum length of 50 bytes. It can be used to store any kind of binary data, such as
images, files, or other binary objects, up to the specified.
For Example:
Varbinary(MAX)
The VARBINARY(MAX) data type in SQL Server is used to store variable-length binary data
with a maximum size of 2^31-1 bytes (about 2 GB). This type is useful for storing large
amounts of binary data, such as images, files, or other large binary objects.
For Example:
CREATE TABLE Files (
Varchar(50)
The VARCHAR(50) data type in databases is used to store variable-length character strings.
The 50 specifies the maximum number of characters that can be stored in the column.
VARCHAR can store strings of varying lengths up to the specified maximum.
For Example:
Varchar(MAX)
For Example:
CREATE TABLE LongComments (
CommentID int PRIMARY KEY,
CommentText VARCHAR(MAX)
);
xml
A XML database is a database that can be used to store large amounts of data or information in
the XML . They can handle data which is of any size or format. XML is a markup language that
uses “tags” or specially formatted text labels, to identify the function of varied data elements
within a document.
For Example: