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

Sql queries presentation
Sql queries presentationSql queries presentation
Sql queries presentationNITISH KUMAR
 
Sql(structured query language)
Sql(structured query language)Sql(structured query language)
Sql(structured query language)Ishucs
 
Including Constraints -Oracle Data base
Including Constraints -Oracle Data base Including Constraints -Oracle Data base
Including Constraints -Oracle Data base Salman Memon
 
Lect 08 materialized view
Lect 08 materialized viewLect 08 materialized view
Lect 08 materialized viewBilal khan
 
Best sql plsql material
Best sql plsql materialBest sql plsql material
Best sql plsql materialpitchaiah yechuri
 
Sql server basics
Sql server basicsSql server basics
Sql server basicsVishalJharwade
 
Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query LanguageEddyzulham Mahluzydde
 
Structured Query Language
Structured Query LanguageStructured Query Language
Structured Query LanguageSurkhab Shelly
 
Sql basics and DDL statements
Sql basics and DDL statementsSql basics and DDL statements
Sql basics and DDL statementsMohd Tousif
 
SQL: Creating and Altering Tables
SQL: Creating and Altering TablesSQL: Creating and Altering Tables
SQL: Creating and Altering TablesRJ Podeschi
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functionsfarwa waqar
 

What's hot (20)

Stored procedure
Stored procedureStored procedure
Stored procedure
 
Sql queries presentation
Sql queries presentationSql queries presentation
Sql queries presentation
 
Sql(structured query language)
Sql(structured query language)Sql(structured query language)
Sql(structured query language)
 
Including Constraints -Oracle Data base
Including Constraints -Oracle Data base Including Constraints -Oracle Data base
Including Constraints -Oracle Data base
 
Lect 08 materialized view
Lect 08 materialized viewLect 08 materialized view
Lect 08 materialized view
 
Best sql plsql material
Best sql plsql materialBest sql plsql material
Best sql plsql material
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
 
Sql server basics
Sql server basicsSql server basics
Sql server basics
 
SQL : introduction
SQL : introductionSQL : introduction
SQL : introduction
 
set operators.pptx
set operators.pptxset operators.pptx
set operators.pptx
 
Sql server T-sql basics ppt-3
Sql server T-sql basics  ppt-3Sql server T-sql basics  ppt-3
Sql server T-sql basics ppt-3
 
Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query Language
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
Structured Query Language
Structured Query LanguageStructured Query Language
Structured Query Language
 
Sql and Sql commands
Sql and Sql commandsSql and Sql commands
Sql and Sql commands
 
Sql basics and DDL statements
Sql basics and DDL statementsSql basics and DDL statements
Sql basics and DDL statements
 
SQL: Creating and Altering Tables
SQL: Creating and Altering TablesSQL: Creating and Altering Tables
SQL: Creating and Altering Tables
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with ExamplesDML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
 

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
 
012. SQL.pdf
012. SQL.pdf012. SQL.pdf
012. SQL.pdfShyam613828
 

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
 
Nutrition a small tour
Nutrition a small tourNutrition a small tour
Nutrition a small tourChandan 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

FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
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
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
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
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 

Recently uploaded (20)

FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
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 ...
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
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
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 

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