SlideShare a Scribd company logo
1 of 19
Data Type on MS SQL Server
3/2/2014 1:58 PM

Prepared by-

M a d h u r i ma D a s
Sc i e nc e )

(M .S c . I n C o m p u t e r

Blog URL :
http://techgig.info

2
What is Data Type?

3/2/2014 1:58 PM

▪ A data type is an attribute that specifies the
type of data. It may be integer type, decimal
type, character type, date and time type etc.

3
SQL Server Data type

3/2/2014 1:58 PM

▪ In SQL Server, each column, local variable, expression,
and parameter has a related data type.
▪ SQL Server supplies a set of system data types that
define all the types of data that can be used with SQL
Server.
▪ You can also define your own data types in Transact-SQL
or the Microsoft .NET Framework. Alias data types are
based on the system-supplied data types.

4
3/2/2014 1:58 PM

Data Type Categories
▪ Data types in SQL Server are organized into the
following categories:
Exact Numerics
Approximate Numerics
Date and Time
Character Strings
Unicode Character Strings
Binary
Other Data Types
5
3/2/2014 1:58 PM

SQL Exact Numeric Data Types
Data Type

Storage Capacity

Range

Bigint
Int
Smallint

8 bytes
4 bytes
2 bytes

–263 to 263–1
–231 to 231– 1
–215 to 215– 1

Tinyint
Bit
Decimal(p,s)

1 bytes
1 bit
19 bytes

0 to 255
1 or 0
–1038+1 to 1038–1

Numeric(p,s)
Money
Smallmoney

Same as decimal
8 bytes
4 bytes

Same as decimal
–263 to 263–1
–231 to 231– 1

6
3/2/2014 1:58 PM

SQL Approximate Numeric Data Types

Data Type

Storage Capacity

Range

Float

8 bytes

–1.79E +308 to 1.79E+308

Real

4 bytes

–3.40E+38 to 3.40E+38

7
3/2/2014 1:58 PM

SQL Date and Time Data Types
Data Type

Storage Capacity

Range

Date

3 bytes

0001-01-01 to 9999-12-31

Time

5 bytes

00:00:00.0000000 to 23:59:59.9999999

Datetime

8 bytes

January 1, 1753, to December 31,
9999(for Date) & 00:00:00 to
23:59:59.997(for Time)

Smalldatetime

4 bytes

1900-01-01 to 2079-06-06(for Date) &
00:00:00 to 23:59:59(for Time)

Datetime2

Varies

0001-01-01 to 9999-12-31(for Date) &
00:00:00 to 23:59:59.9999999(for Time)

Datetimeoffset

10 bytes

Same as Datetime2 with time zone offset
range -14:00 to +14:00

8
3/2/2014 1:58 PM

SQL Character String Data Types
Data Type

Storage Capacity

Range

Char [(n) ]

Varies

1 to 8,000 characters

Varchar [(n|max)]

Varies

8,000 characters

Text

Varies

231–1 (2,147,483,647) characters

9
3/2/2014 1:58 PM

SQL Unicode Character String Data Types
Data Type

Storage Capacity

Range

nchar [(n)]

Varies

1 to 4,000 characters

nvarchar [(n|max)]

Varies

4,000 characters

ntext

Varies

230–1 (1,073,741,823) characters

10
3/2/2014 1:58 PM

SQL Binary Data Types
Data Type

Storage Capacity

Range

binary [(n)]

Varies

8,000 bytes

varbinary [(n|max)]

Varies

8,000 bytes

Image

Varies

231–1 (2,147,483,647) bytes

11
3/2/2014 1:58 PM

SQL Other Data Types
▪ Cursor

▪ Uniqueidentifier

▪ Hierarchyid

▪ Xml

▪ Sql_variant

▪ Spatial Types
– Geography
– Geometry

▪ Table
▪ Timestamp

12
3/2/2014 1:58 PM

SQL User Define Data Types
▪ User define data type are based on system data type of MS
SQL Server.
▪ It is created when several table object use the same data in
terms of data type, length and null ability.
The syntax of creating user define data types are
mentioned bellow :
sp_addtype [
[
[
[

@typename = ] type,
@phystype = ] system_data_type
, [ @nulltype = ] 'null_type' ]
, [ @owner = ] 'owner_name' ]
13
3/2/2014 1:58 PM

Data Type Example
-- Creating User define data type
EXEC sp_addtype @typename='Postal_Code',
@phystype='Varchar(7)',
@nulltype='NOT NULL'
GO
-- Using System data type & User define data type
CREATE TABLE emp_address
(Emp_name
VARCHAR(50) NOT NULL,
Postal_code Postal_Code);
GO
14
3/2/2014 1:58 PM

Data Type Conversion
▪ Implicit Conversion

– Implicit conversions are not visible to the user.
– SQL Server automatically converts the data from one data
type to another.

▪ Explicit Conversion

– Explicit conversions use the CAST or CONVERT functions.

15
3/2/2014 1:58 PM

Data Type Precedence
▪ When an operator combines two expressions of
different data types, the rules for data type
precedence specify that the data type with the lower
precedence is converted to the data type with the
higher precedence.
▪ If the conversion is not a supported implicit
conversion, an error is returned. When both operand
expressions have the same data type, the result of
the operation has that data type.
16
3/2/2014 1:58 PM

Data Type Precedence
• SQL Server uses the following precedence order for data types:
1.

user-defined data types (highest) 11. real

21. image

2.

sql_variant

12. decimal

22. timestamp

3.

xml

13. money

23. text

4.

datetimeoffset

14. smallmoney

24. uniqueidentifier

5.

datetime2

15. bigint

25. nvarchar (including nvarchar(max) )

6.

datetime

16. int

26. Nchar

7.

smalldatetime

17. smallint

27. varchar (including varchar(max) )

8.

date

18. tinyint

28. char

9.

time

19. bit

29. varbinary (including varbinary(max) )

20. ntext

30. binary (lowest)

10. float

17
3/2/2014 1:58 PM

Questions ?

18
3/2/2014 1:58 PM

Thank You !

19

More Related Content

What's hot (20)

Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)
 
Trigger
TriggerTrigger
Trigger
 
Basic sql Commands
Basic sql CommandsBasic sql Commands
Basic sql Commands
 
Sql Functions And Procedures
Sql Functions And ProceduresSql Functions And Procedures
Sql Functions And Procedures
 
SQL
SQLSQL
SQL
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
İleri Seviye T-SQL Programlama - Chapter 13
İleri Seviye T-SQL Programlama - Chapter 13İleri Seviye T-SQL Programlama - Chapter 13
İleri Seviye T-SQL Programlama - Chapter 13
 
Css Text Formatting
Css Text FormattingCss Text Formatting
Css Text Formatting
 
MYSQL join
MYSQL joinMYSQL join
MYSQL join
 
HTML iframe
HTML iframeHTML iframe
HTML iframe
 
Alter table command
Alter table commandAlter table command
Alter table command
 
SQL select clause
SQL select clauseSQL select clause
SQL select clause
 
SQL Tutorial for Beginners
SQL Tutorial for BeginnersSQL Tutorial for Beginners
SQL Tutorial for Beginners
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
 
MS SQL Server
MS SQL ServerMS SQL Server
MS SQL Server
 
Sql commands
Sql commandsSql commands
Sql commands
 
SQL
SQLSQL
SQL
 
Sql Basics And Advanced
Sql Basics And AdvancedSql Basics And Advanced
Sql Basics And Advanced
 
Oracle naveen Sql
Oracle naveen   SqlOracle naveen   Sql
Oracle naveen Sql
 
CSS
CSSCSS
CSS
 

Similar to Data type[s] on MS SQL Server

Oracle sql in 7 days by suesh.n v 1.0
Oracle sql in 7 days by suesh.n v 1.0Oracle sql in 7 days by suesh.n v 1.0
Oracle sql in 7 days by suesh.n v 1.0nsureshreddy51
 
Structured Query Language (SQL) _ Edu4Sure Training.pptx
Structured Query Language (SQL) _ Edu4Sure Training.pptxStructured Query Language (SQL) _ Edu4Sure Training.pptx
Structured Query Language (SQL) _ Edu4Sure Training.pptxEdu4Sure
 
14 22 size sql book(1)
14 22 size sql book(1)14 22 size sql book(1)
14 22 size sql book(1)bhganesh
 
Sql server ___________session 2(sql 2008)
Sql server  ___________session 2(sql 2008)Sql server  ___________session 2(sql 2008)
Sql server ___________session 2(sql 2008)Ehtisham Ali
 
Time Machines and Attribute Alchemy
Time Machines and Attribute AlchemyTime Machines and Attribute Alchemy
Time Machines and Attribute AlchemySafe Software
 
SQL Query Interview Questions
SQL Query Interview QuestionsSQL Query Interview Questions
SQL Query Interview Questionssoniajessica2
 
Final Project Write-up
Final Project Write-upFinal Project Write-up
Final Project Write-upshiyang feng
 
Dev Sql Beyond Relational
Dev Sql Beyond RelationalDev Sql Beyond Relational
Dev Sql Beyond Relationalrsnarayanan
 
AWS re:Invent 2016: Workshop: Converting Your Oracle or Microsoft SQL Server ...
AWS re:Invent 2016: Workshop: Converting Your Oracle or Microsoft SQL Server ...AWS re:Invent 2016: Workshop: Converting Your Oracle or Microsoft SQL Server ...
AWS re:Invent 2016: Workshop: Converting Your Oracle or Microsoft SQL Server ...Amazon Web Services
 
Using New Data Types In2008
Using New Data Types In2008Using New Data Types In2008
Using New Data Types In2008PhilWinstanley
 
Sql server 2016: System Databases, data types, DML, json, and built-in functions
Sql server 2016: System Databases, data types, DML, json, and built-in functionsSql server 2016: System Databases, data types, DML, json, and built-in functions
Sql server 2016: System Databases, data types, DML, json, and built-in functionsSeyed Ibrahim
 
Introduction to PostgreSQL
Introduction to PostgreSQLIntroduction to PostgreSQL
Introduction to PostgreSQLJim Mlodgenski
 
Njug presentation
Njug presentationNjug presentation
Njug presentationiwrigley
 
ACL London User Group - Question Box Session
ACL London User Group - Question Box SessionACL London User Group - Question Box Session
ACL London User Group - Question Box SessionAlex Psarras
 
New fordevelopersinsql server2008
New fordevelopersinsql server2008New fordevelopersinsql server2008
New fordevelopersinsql server2008Aaron Shilo
 
Intro to Database Design
Intro to Database DesignIntro to Database Design
Intro to Database DesignSondra Willhite
 

Similar to Data type[s] on MS SQL Server (20)

Oracle sql in 7 days by suesh.n v 1.0
Oracle sql in 7 days by suesh.n v 1.0Oracle sql in 7 days by suesh.n v 1.0
Oracle sql in 7 days by suesh.n v 1.0
 
Structured Query Language (SQL) _ Edu4Sure Training.pptx
Structured Query Language (SQL) _ Edu4Sure Training.pptxStructured Query Language (SQL) _ Edu4Sure Training.pptx
Structured Query Language (SQL) _ Edu4Sure Training.pptx
 
14 22 size sql book(1)
14 22 size sql book(1)14 22 size sql book(1)
14 22 size sql book(1)
 
Sql server ___________session 2(sql 2008)
Sql server  ___________session 2(sql 2008)Sql server  ___________session 2(sql 2008)
Sql server ___________session 2(sql 2008)
 
Time Machines and Attribute Alchemy
Time Machines and Attribute AlchemyTime Machines and Attribute Alchemy
Time Machines and Attribute Alchemy
 
Using T-SQL
Using T-SQL Using T-SQL
Using T-SQL
 
SQL Query Interview Questions
SQL Query Interview QuestionsSQL Query Interview Questions
SQL Query Interview Questions
 
Final Project Write-up
Final Project Write-upFinal Project Write-up
Final Project Write-up
 
Dev Sql Beyond Relational
Dev Sql Beyond RelationalDev Sql Beyond Relational
Dev Sql Beyond Relational
 
AWS re:Invent 2016: Workshop: Converting Your Oracle or Microsoft SQL Server ...
AWS re:Invent 2016: Workshop: Converting Your Oracle or Microsoft SQL Server ...AWS re:Invent 2016: Workshop: Converting Your Oracle or Microsoft SQL Server ...
AWS re:Invent 2016: Workshop: Converting Your Oracle or Microsoft SQL Server ...
 
Using New Data Types In2008
Using New Data Types In2008Using New Data Types In2008
Using New Data Types In2008
 
Sql server 2016: System Databases, data types, DML, json, and built-in functions
Sql server 2016: System Databases, data types, DML, json, and built-in functionsSql server 2016: System Databases, data types, DML, json, and built-in functions
Sql server 2016: System Databases, data types, DML, json, and built-in functions
 
Introduction to PostgreSQL
Introduction to PostgreSQLIntroduction to PostgreSQL
Introduction to PostgreSQL
 
Njug presentation
Njug presentationNjug presentation
Njug presentation
 
ACL London User Group - Question Box Session
ACL London User Group - Question Box SessionACL London User Group - Question Box Session
ACL London User Group - Question Box Session
 
New fordevelopersinsql server2008
New fordevelopersinsql server2008New fordevelopersinsql server2008
New fordevelopersinsql server2008
 
SQL for interview
SQL for interviewSQL for interview
SQL for interview
 
Intro to Database Design
Intro to Database DesignIntro to Database Design
Intro to Database Design
 
Cassandra data modelling best practices
Cassandra data modelling best practicesCassandra data modelling best practices
Cassandra data modelling best practices
 
012. SQL.pdf
012. SQL.pdf012. SQL.pdf
012. SQL.pdf
 

More from Chandan Banerjee

TPA Based Software reference
TPA Based Software referenceTPA Based Software reference
TPA Based Software referenceChandan Banerjee
 
Software reference tpa_responsive _website
Software reference tpa_responsive _websiteSoftware reference tpa_responsive _website
Software reference tpa_responsive _websiteChandan Banerjee
 
Software reference tpa_management
Software reference tpa_managementSoftware reference tpa_management
Software reference tpa_managementChandan Banerjee
 
ECG & Heart block [doctors online]
ECG & Heart block [doctors online]ECG & Heart block [doctors online]
ECG & Heart block [doctors online]Chandan Banerjee
 
Diabetes Malitus doctors onlineindia
Diabetes Malitus doctors onlineindiaDiabetes Malitus doctors onlineindia
Diabetes Malitus doctors onlineindiaChandan Banerjee
 
Obesity and lifestyle_management
Obesity and lifestyle_managementObesity and lifestyle_management
Obesity and lifestyle_managementChandan Banerjee
 
Nurses responsibility administering medicine
Nurses responsibility  administering medicineNurses responsibility  administering medicine
Nurses responsibility administering medicineChandan Banerjee
 

More from Chandan Banerjee (11)

TPA Based Software reference
TPA Based Software referenceTPA Based Software reference
TPA Based Software reference
 
Software reference tpa_responsive _website
Software reference tpa_responsive _websiteSoftware reference tpa_responsive _website
Software reference tpa_responsive _website
 
Software reference tpa_management
Software reference tpa_managementSoftware reference tpa_management
Software reference tpa_management
 
GB Network India
GB Network IndiaGB Network India
GB Network India
 
Sql triggers
Sql triggersSql triggers
Sql triggers
 
ECG & Heart block [doctors online]
ECG & Heart block [doctors online]ECG & Heart block [doctors online]
ECG & Heart block [doctors online]
 
Diabetes Malitus doctors onlineindia
Diabetes Malitus doctors onlineindiaDiabetes Malitus doctors onlineindia
Diabetes Malitus doctors onlineindia
 
Obesity and lifestyle_management
Obesity and lifestyle_managementObesity and lifestyle_management
Obesity and lifestyle_management
 
Nursing Process
Nursing ProcessNursing Process
Nursing Process
 
Nurses responsibility administering medicine
Nurses responsibility  administering medicineNurses responsibility  administering medicine
Nurses responsibility administering medicine
 
Nutrition a small tour
Nutrition a small tourNutrition a small tour
Nutrition a small tour
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 

Recently uploaded (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 

Data type[s] on MS SQL Server

  • 1. Data Type on MS SQL Server
  • 2. 3/2/2014 1:58 PM Prepared by- M a d h u r i ma D a s Sc i e nc e ) (M .S c . I n C o m p u t e r Blog URL : http://techgig.info 2
  • 3. What is Data Type? 3/2/2014 1:58 PM ▪ A data type is an attribute that specifies the type of data. It may be integer type, decimal type, character type, date and time type etc. 3
  • 4. SQL Server Data type 3/2/2014 1:58 PM ▪ In SQL Server, each column, local variable, expression, and parameter has a related data type. ▪ SQL Server supplies a set of system data types that define all the types of data that can be used with SQL Server. ▪ You can also define your own data types in Transact-SQL or the Microsoft .NET Framework. Alias data types are based on the system-supplied data types. 4
  • 5. 3/2/2014 1:58 PM Data Type Categories ▪ Data types in SQL Server are organized into the following categories: Exact Numerics Approximate Numerics Date and Time Character Strings Unicode Character Strings Binary Other Data Types 5
  • 6. 3/2/2014 1:58 PM SQL Exact Numeric Data Types Data Type Storage Capacity Range Bigint Int Smallint 8 bytes 4 bytes 2 bytes –263 to 263–1 –231 to 231– 1 –215 to 215– 1 Tinyint Bit Decimal(p,s) 1 bytes 1 bit 19 bytes 0 to 255 1 or 0 –1038+1 to 1038–1 Numeric(p,s) Money Smallmoney Same as decimal 8 bytes 4 bytes Same as decimal –263 to 263–1 –231 to 231– 1 6
  • 7. 3/2/2014 1:58 PM SQL Approximate Numeric Data Types Data Type Storage Capacity Range Float 8 bytes –1.79E +308 to 1.79E+308 Real 4 bytes –3.40E+38 to 3.40E+38 7
  • 8. 3/2/2014 1:58 PM SQL Date and Time Data Types Data Type Storage Capacity Range Date 3 bytes 0001-01-01 to 9999-12-31 Time 5 bytes 00:00:00.0000000 to 23:59:59.9999999 Datetime 8 bytes January 1, 1753, to December 31, 9999(for Date) & 00:00:00 to 23:59:59.997(for Time) Smalldatetime 4 bytes 1900-01-01 to 2079-06-06(for Date) & 00:00:00 to 23:59:59(for Time) Datetime2 Varies 0001-01-01 to 9999-12-31(for Date) & 00:00:00 to 23:59:59.9999999(for Time) Datetimeoffset 10 bytes Same as Datetime2 with time zone offset range -14:00 to +14:00 8
  • 9. 3/2/2014 1:58 PM SQL Character String Data Types Data Type Storage Capacity Range Char [(n) ] Varies 1 to 8,000 characters Varchar [(n|max)] Varies 8,000 characters Text Varies 231–1 (2,147,483,647) characters 9
  • 10. 3/2/2014 1:58 PM SQL Unicode Character String Data Types Data Type Storage Capacity Range nchar [(n)] Varies 1 to 4,000 characters nvarchar [(n|max)] Varies 4,000 characters ntext Varies 230–1 (1,073,741,823) characters 10
  • 11. 3/2/2014 1:58 PM SQL Binary Data Types Data Type Storage Capacity Range binary [(n)] Varies 8,000 bytes varbinary [(n|max)] Varies 8,000 bytes Image Varies 231–1 (2,147,483,647) bytes 11
  • 12. 3/2/2014 1:58 PM SQL Other Data Types ▪ Cursor ▪ Uniqueidentifier ▪ Hierarchyid ▪ Xml ▪ Sql_variant ▪ Spatial Types – Geography – Geometry ▪ Table ▪ Timestamp 12
  • 13. 3/2/2014 1:58 PM SQL User Define Data Types ▪ User define data type are based on system data type of MS SQL Server. ▪ It is created when several table object use the same data in terms of data type, length and null ability. The syntax of creating user define data types are mentioned bellow : sp_addtype [ [ [ [ @typename = ] type, @phystype = ] system_data_type , [ @nulltype = ] 'null_type' ] , [ @owner = ] 'owner_name' ] 13
  • 14. 3/2/2014 1:58 PM Data Type Example -- Creating User define data type EXEC sp_addtype @typename='Postal_Code', @phystype='Varchar(7)', @nulltype='NOT NULL' GO -- Using System data type & User define data type CREATE TABLE emp_address (Emp_name VARCHAR(50) NOT NULL, Postal_code Postal_Code); GO 14
  • 15. 3/2/2014 1:58 PM Data Type Conversion ▪ Implicit Conversion – Implicit conversions are not visible to the user. – SQL Server automatically converts the data from one data type to another. ▪ Explicit Conversion – Explicit conversions use the CAST or CONVERT functions. 15
  • 16. 3/2/2014 1:58 PM Data Type Precedence ▪ When an operator combines two expressions of different data types, the rules for data type precedence specify that the data type with the lower precedence is converted to the data type with the higher precedence. ▪ If the conversion is not a supported implicit conversion, an error is returned. When both operand expressions have the same data type, the result of the operation has that data type. 16
  • 17. 3/2/2014 1:58 PM Data Type Precedence • SQL Server uses the following precedence order for data types: 1. user-defined data types (highest) 11. real 21. image 2. sql_variant 12. decimal 22. timestamp 3. xml 13. money 23. text 4. datetimeoffset 14. smallmoney 24. uniqueidentifier 5. datetime2 15. bigint 25. nvarchar (including nvarchar(max) ) 6. datetime 16. int 26. Nchar 7. smalldatetime 17. smallint 27. varchar (including varchar(max) ) 8. date 18. tinyint 28. char 9. time 19. bit 29. varbinary (including varbinary(max) ) 20. ntext 30. binary (lowest) 10. float 17