0% found this document useful (0 votes)
487 views3 pages

Data Types in SQL Server

There are two types of data types in SQL Server: system defined and user defined. System defined types include numeric, string, date/time, and special types. Numeric types store numbers and include exact and approximate types. String types store characters and include fixed and variable length types. Date/time types store dates. Special types include binary, Unicode, and miscellaneous types. User defined types are created by users and are based on existing system defined types.

Uploaded by

Srikanth Vuduta
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
Download as doc, pdf, or txt
0% found this document useful (0 votes)
487 views3 pages

Data Types in SQL Server

There are two types of data types in SQL Server: system defined and user defined. System defined types include numeric, string, date/time, and special types. Numeric types store numbers and include exact and approximate types. String types store characters and include fixed and variable length types. Date/time types store dates. Special types include binary, Unicode, and miscellaneous types. User defined types are created by users and are based on existing system defined types.

Uploaded by

Srikanth Vuduta
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1/ 3

Data Types in SQL SERVER:

Data Type means the type of data which users provided to a specific column
In SQL Server 2 types of data types available which includes
1. System Defined Data Types
2. User Defined Data Types.
System Defined Data Types:
SQL Server already contains some data types called System Defined data types
or Predefined Data types or Built-in Data types. System Defined Data Types again
categorized into 4 types
a.
b.
c.
d.

Numeric Data types


String Data types
Date Time Data types
Special Data types

Numeric Data types:


These Data types are used to provide numeric information for the columns, these
includes
Data Type
BIT
TINYINT
SMALLINT
* INT
BIGINT
REAL
FLOAT
DECIMAL (P, S)

Size
0 or 1
1 BYTE
2 BYTES
4BYTES
8BYTES
4BYTES
8BYTES
5-17 BYTES

TINYINT, SMALLINT, INT, BIGINT are called Exact Numerics where as REAL,
FLOAT are called Approximate Numerics.

String Data types:


These Data types are used to provide character information for the columns, these
includes
Data Type
CHAR [(N)]
* VARCHAR [(N)]
TEXT
VARCHAR(MAX)

Size
1BYTE
1BYTE
16BYTES
16 GB

CHAR [(N)]: It is a fixed length data type, which occupies by default 1 byte memory.
When we N value then it occupies N bytes of memory where N is an integer. It follows
Static memory allocation process.
VARCHAR [(N)]: It is a variable length data type, which occupies by default 1 byte
memory. When we N value then it occupies N bytes of memory where N is an integer. It
follows dynamic memory allocation process.
Note : The Maximum limit for N is 8000,if it is more than 8000 characters we will use
TEXT or VARCHAR(MAX)
Date Time Data Type:
These data types are used to provide date oriented information to the columns,
these includes
Data Type
SMALLDATETIME
* DATETIME

Size

Range

2 BYTES
4BYTES

1900-01-01 TO 2079-06-06
1753-01-01 TO 9999-12-31

Special Data types:


These data types are used to provide miscellaneous information to the columns, these
includes
Data Type
*

Size

SMALLMONEY
4 BYTE
MONEY
8 BYTES
IMAGE
16 BYTES
VARBINARY (MAX)Unlimited
1. SQL_VARIANT

1. Binary Data types: These stores binary values of a given string in ordered to hide
the original string values.
Data Type
BINARY [(N)]
* VARBINARY [(N)]

Size
1BYTE
1BYTE

2. Unicode Data types: These Data types are used to store Unicode information,
these includes
Data Type
NCHAR [(N)]
* NVARCHAR [(N)]
NTEXT
II. User Defined Data Types:

Size
2BYTE
2BYTE
16BYTES

When user create a data type then that data type is called user defined data type
Syntax:
CREATE TYPE USER_DEFINED_DATATYPE FROM SYS_DEFINED_DATATYPE
Ex:
CREATE TYPE MYINT FROM INT
CREATE TYPE MYFLOAT FROM FLOAT
CREATE TYPE CASH FROM MONEY

You might also like