Sunday, May 25, 2014

DATA Types in sql server

Integer Data Type

Bit – 0 or 1

1 byte in memory
0-false
1 true
When we want to store Boolean value then use this


Tiny int


0 to 255
1 byte in memory
1 byte


Small int
-32,768 to 32,767
2  bytes


int
-214,748,3648 to 214,748,3647
 4 bytes


Big int
8 bytes in memory
Float Data Type and Real Data TYPE
Float
-1.79E308 to 1.79E308
4 Bytes
4 bytes if the precision is the range of 1 to 24
8 bytes if the precision is in the range of 25 to 53


Real
-3.4E38 to 3.4E38
4 Bytes


Decimal Data Types
Decimal(p,s)
-10 to the power 38
(-10 ^38to 10^38-1)

1 to  9 5bytes
10 to 19 9 bytes
20 to 28 13 bytes
29 to 38 17 bytes

Example
Decimal (7,2)->12345.67

Money or Currency Data Types
To hold the currency value it provides with the following types which take a scale of 4 Bytes of Default
Small money  4 bytes
Money  8 bytes

Character Data Types
char:   fixed length char data
varchar – variable length char data
varchar(max) variable length char data
Text- variable length char data


Use of char:
when we require frequently modifying of data in char column then choose char data type

Whereas
varchar, it will delete that row and update the row in new location

Char,varchar- 8000 bytes


Varchar(max), Text- can store upto Maximum 2 GB




Example
Sname varchar(20) – abc(no blank space)
Char(10)- abc

UNICODE Character DataType
Nchar-fixed length Unicode char- 8000 bytes
Nvarchar-variable length Unicode char-8000 bytes
Nvarchar(max)- variable length Unicode char- 2GB
Ntext- variable length Unicode char- 2GB


Hierarchy Id
It is used to store the id that represents hierarchy level of the row

Geometry
Storing geometric shapes

Time Stamp
Sql server will automatically update value of that column with current system data and time indicating when the row was last modified

Time stamp column can be used to find the recently modified rows in the table

Geography
Storing geographical maps

Sql variant
Any type of data it can store

Unique identifier
Storing globally unique identifier

Binary Data Types
Are used for storing images, audio, videos
Binary-fixed length binary data-8000 bytes
Var binary- variable length  binary data- 2gb
Image-variable length binary data- 2gb

Date and Time Data Type
Date: 1 jan 0001 to 31 dec 9999- 4 bytes
Time :00:00:00  to 23:59:59 ( 6 bytes)
Date Time2: 1 jan1753 to 31 dec 9999 ( 8 bytes to 10 bytes)
Date Time OffSet : 1 jan 0001 to 31 dec 9999( 10 bytes)

Small Date Time
1 jan 1900 to 6 jun 2079 (4 bytes)
Datetime- 1jan1753 to 31dec 9999 (8 bytes)

No comments:

Post a Comment

Thank you for visiting my blog

Kubernetes

Prerequisites We assume anyone who wants to understand Kubernetes should have an understating of how the Docker works, how the Docker images...