13
SQL Server Data Types © Meganadha Reddy K., 2015 http://www.netcomlearning.com/ Meganadha Reddy K. Technical Trainer | NetCom Learning www.NetComLearning.com

SQL Server Data Types - Amazon Web Services · text Microsoft will be removing ntext, text and image data types in future versions of SQL ntext Server. So do not plan to use these

Embed Size (px)

Citation preview

SQL Server Data Types

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

Meganadha Reddy K.Technical Trainer | NetCom Learning

www.NetComLearning.com

Agenda

• Importance of Data Types : 5 Mins

• Memory Units : 5 Mins

• ASCII and Unicode : 10 Mins

• SQL Server Data Types : 25 Mins

• Samples : 10 Mins

• Q & A : 5 Mins

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

This is L100 Webinar on “SQL Server Data Types”

Importance of Data Types

Question:

Will there be any programming language without Data Types??

Well the answer is No

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

Data Types play a critical role long run for the project.

Effective and correct usage of data type is very important for any project

Memory Units

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

Smallest memory unit – 1 Bit

1 Byte = 8 Bits

1 KB = 1024 Bytes

1 MB = 1024 KB

1 GB = 1024 MB

1 TB = 1024 GB

95 to 2003

2000 – till date

How data is stored in System

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

• Computer only knows “on” and “off ” which is represented in binary as

1 and 0.

So all numbers or characters entered in Computer will be converted to

Binary and then stored in the computer.

ASCII and UNICODE

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

ASCII Code

Unicode

0 to 255

[Limited number of characters]

Only English Language Characters

Standard for all languages.

Every Language character has unique Unicode Value

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

Exact Numerics (1 of 2)

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

Data Type Size Range Where we can use?

bit 1 Bit 0 or 1 true or false

tinyint 1 Byte 0 to 255 E.g.: Age

smallint 2 Bytes

int 4 Bytes

bigint 8 Bytes

Will bigint work for storing Age?

• It works for sure but……

• If you want to Cut a small cake., will you use knife or Sword???

[Both works ]

Use Data Types depending the data range that you want to use

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

Character Data Types

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

Data Type Each Character Size Max. Length Sample Usage?

char 1 Byte 8000 Characters Fixed size data. Example : Zip Code

varchar 1 Byte 8000 Characters Varying type data. Example: Names

nchar 2 Bytes 4000 Characters Fixed size Unicode Characters

nvarchar 2 Bytes 4000 Characters Varying size Unicode Characters

text Microsoft will be removing ntext, text and image data types in future versions of SQL

Server. So do not plan to use these two types for your projects.ntext

Date and Time Data Types

Data Type Size Accuracy Range

date 3 Bytes One day 0001-01-01 through 9999-12-31

time 5 Bytes 100 nanoseconds 00:00:00.0000000 through 23:59:59.9999999

smalldatetime 4 Bytes One minute 1900-01-01 through 2079-06-06

00:00:00 through 23:59:59

datetime 8 Bytes Rounded to increments

of .000, .003, or .007

seconds

January 1, 1753, through December 31, 9999

00:00:00 through 23:59:59.997

datetime2 8 Bytes Max** 100 nano seconds 0001-01-01 through 9999-12-31

00:00:00 through 23:59:59.9999999

** 6 bytes for precisions less than 3; 7 bytes for precisions 3 and 4. All other precisions require 8 bytes.

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

Digging into smalldatetime data type

• Why smalldatetime has range from 1900-01-01 through 2079-06-06?

[Instead Microsoft could have taken till 2080-31-12, why stop at 6th June ??? ]

Demo

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

Q & A

?

© Meganadha Reddy K., 2015 http://www.netcomlearning.com/

www.NetComLearning.com