What is your Character Data Type?

Slides:



Advertisements
Similar presentations
Project Management Database and SQL Server Katmai New Features Qingsong Yao
Advertisements

Module 4: Creating Data Types and Tables. Overview Creating Data Types Creating Tables Generating Column Values Generating Scripts.
Representing Data Elements Gayatri Gopalakrishnan.
Basic SQL types String –Char(n): fixed length. Padded –Varchar(n): variable length Number –Integer: 32 bit –Decimal(5,2): –Real, Double: 32 bit,
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
Copyright ©2014 Pearson Education, Inc. Chapter 6 Physical Design Chapter6.1.
Database Fundamentals
Working with Data Types February 7, 2015 John Deardurff Website:
Module 2 Working with Data Types. Module Overview Using Data Types Working with Character Data Converting Data Types Working with Specialized Data Types.
Overview of SQL Server Alka Arora.
Basis Data Terapan Yoannita. SQL Server Data Types Character strings: Data typeDescriptionStorage char(n)Fixed-length character string. Maximum 8,000.
Module 4: Data Objects. Overview Tables are the main objects that store data Indexes, views, stored programs and other objects are the support structures.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Chapter 7 SQL HUANG XUEHUA. SQL SQL server2005 introduction Install components  management studio.
Using New Data Types in 2008 Andrew Couch UK Access User Group ASC associates
SQL Data Definition Language (DDL) Using Microsoft SQL Server 1SDL Data Definition Language (DDL)
11 3 / 12 CHAPTER Databases MIS105 Lec15 Irfan Ahmed Ilyas.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
MySQL More… 1. More on SQL In MySQL, the Information Schema is the “Catalog” in the SQL standard SQL has three components: Data definition Data manipulation.
Data Types Lesson 4. Skills Matrix Table A table stores your data. Tables are relational in that they are organized as rows and columns (a matrix). Each.
SQL Server 2005 Implementation and Maintenance Chapter 3: Tables and Views.
Session 11 Creating Tables and Using Data Types. RDBMS and Data Management/Session 11/2 of 40 Session Objectives Define the data types and list the categories.
03 | SQL Server Data Types Brian Alderman | MCT, CEO / Founder of MicroTechPoint Tobias Ternstrom | Microsoft SQL Server Program Manager.
Data types  CHAR (size): This data type is used to store character strings values of fixed length. The size in brackets determines the number of characters.
Sql DDL queries CS 260 Database Systems.
IMS 4212: Data Modeling—Attributes and Domains 1 Dr. Lawrence West, Management Dept., University of Central Florida Attributes and Domains.
Best Practices in SQL Programming. Do not use irrelevant datatype  VARCHAR instead of DATETIME  CHAR(N) instead of VARCHAR(N)  etc.
Academic Year 2015 Autumn. MODULE CC2006NI: Data Modelling and Database Systems Academic Year 2015 Autumn.
SQL server Section 2&3. What are Data Types Character Data Types Number Data Types Date and Time Data Types CAST and CONVERT functions TRY_PARSE and TRY_CONVERT.
Creating E/R Diagrams with SQL Server Management Studio, Writing SQL Queries D0ncho Minkov Telerik School Academy schoolacademy.telerik.com Technical Trainer.
What is your Character Data Type? March 5, 2016 John Deardurff Website:
14 New T-SQL Functions By Sam Nasr, MCAD, MCT, MCTS NIS
Querying with Transact-SQL
Creating Database Objects
Databases and SQL Designing a database with tables and primary keys
Managing Tables, Data Integrity, Constraints by Adrienne Watt
Data Definition and Data Types
Database Management System
The Basics of Data Manipulation
Module 2: Creating Data Types and Tables
Lecture 6 Data Model Design (continued)
Data Definition and Data Types
Lesson 7 Managing Data Creating a database with Web Matrix.
Attributes and Domains
Ouch! Our Data Type Choices Did THAT?
SQL Server 2016 JSON Support FOR Data Warehousing
SQL Implementation & Administration
Working with SQL Server 2016 Data Types
What is Database Administration
14 T-SQL Functions You May Not Know
Migrating a Disk-based Table to a Memory-optimized one in SQL Server
Proper DataType Usage = Guaranteed Better Performance and Accuracy
SQL Server TVP Performance Gotcha
Working with Data Types
The Basics of Data Manipulation
Database systems Lecture 2 – Data Types
CIS 136 Building Mobile Apps
A JSON’s Journey through SQL Server
CIS16 Application Programming with Visual Basic
PT2520 Unit 5: Physical Design
Data Types Do Matter Start local instance of SQL Start ZoomIt
14 T-SQL Functions You May Not Know
Attributes and Domains
Chapter 2: Creating And Modifying Database Tables
Creating Database Objects
SQL (Structured Query Language)
Introduction to SQL Server and the Structure Query Language
Working with SQL Server 2016 Data Types
Presentation transcript:

What is your Character Data Type? John Deardurff Website: http://john.deardurff.com Twitter: @John_Deardurff Email: John@Deardurff.com March 5, 2016

Presentation Topics We will learn about the basic SQL Server Data Types Used for Columns, Variables, Expressions, & Parameters Fundamental to writing queries in T-SQL Fundamental to designing tables. Choosing the right data type ensures data integrity and accuracy by creating a constraint on data input Choosing the right data type can save hard drive space, space in memory, and bandwidth on your network

Presentation Topics What are Data Types Character Data Types Number Data Types Date and Time Data Types LEN and DATALENGTH functions CAST and CONVERT functions TRY_PARSE and TRY_CONVERT functions. Other Data Types

SQL Server Data Types Data types determine what kind of data can be held: Integers, characters, dates, money, decimals, etc.

Data Types Associations Columns Expressions Variables Parameters

Data Types with Columns

A Byte saved is a Byte earned. ~ Benjamin Franklin The problem with quotes from the internet is it is hard to verify their authenticity. ~ Abraham Lincoln

VARCHAR(n), NVARCHAR(n) VARCHAR(MAX), NVARCHAR(MAX) Character Data Types Data Type Range Storage CHAR(n), NCHAR(n) 1-8000 characters 1-4000 characters bytes 2*n bytes VARCHAR(n), NVARCHAR(n) n+2 bytes (2*n) +2 bytes VARCHAR(MAX), NVARCHAR(MAX) 1-2^31-1 characters Actual length + 2

Character Data Types Fixed Variable Regular char varchar Unicode nchar 1 byte per char Unicode nchar nvarchar 2 bytes per char

Character Data Types Coding Example

Character Data Types

Data Pages Free Space Page Header (96 bytes) Data Row 1 Data Row 2 Header contains Page Information such a Page Number and Page Type Data Row 1 Data Row 2 Data Row 3 Data Rows or Free Space Free Space Row Offest Array Displays how far from beginning of page each row is located.

FIXVAR Format Length of Fixed Width Columns 2 bytes Header Byte 1 Null Variable Variable Width Variable Column Offset Array 2 bytes per Length of Fixed Width Columns 2 bytes 8 Null Columns NULL Bitmap 1 Byte per Number of Variable Width Columns (2 Bytes) Number of Total Columns (2 Bytes) Header Byte 1 Header Byte 2 Fixed Width Data Variable Width Data This is the FixVar format for a column for IN ROW Data Storage.

-2^63 - 2^63-1 (+/- 9 quintillion) Integer Data Types Data type Range Storage (bytes) tinyint 0 to 255 1 smallint -32,768 to 32,767 2 int 2^31 (-2,147,483,648) to 2^31-1 (2,147,483,647) 4 Bigint -2^63 - 2^63-1 (+/- 9 quintillion) 8 bit 1, 0 or NULL

Integer Data Types Coding Example

Other Numeric Data Types Range Storage (bytes) decimal/numeric 10^38 +1 through 10^38 – 1 when maximum precision is used 5-17 money -922,337,203,685,477.5808 to 922,337,203,685,477.5807 8 smallmoney - 214,748.3648 to 214,748.3647 4 float /real Approximate data type for floating point numeric data 4-8

Date and Time Data Types Storage (bytes) Date Range Accuracy DATETIME 8 January 1, 1753 to December 31, 9999 3-1/3 milliseconds SMALLDATETIME 4 January 1, 1900 to June 6, 2079 1 minute DATETIME2 6 to 8 January 1, 0001 to December 31, 9999 100 nanoseconds DATE 3 1 day TIME 3 to 5 DATETIMEOFFSET 8 to 10

Date and Time Data Types Older versions of SQL Server supported only DATETIME and SMALLDATETIME DATE, TIME, DATETIME2, and DATETIMEOFFSET introduced in SQL Server 2008 SQL Server doesn't offer an option for entering a date or time value explicitly Dates and times are entered as character literals and converted explicitly or implicitly For example, CHAR converted to DATETIME due to precedence

Working with Date and Time Separately DATETIME, SMALLDATETIME, DATETIME2, and DATETIMEOFFSET include both date and time data If only date is specified, time set to midnight (all zeroes) If only time is specified, date set to base date (January 1, 1900) DECLARE @DateOnly DATETIME = '20120212'; SELECT @DateOnly; RESULT ----------------------- 2012-02-12 00:00:00.000

Data Type Precedence Data type precedence determines which data type will be chosen when expressions of different types are combined Data type with the lower precedence is implicitly converted to the data type with the higher precedence Conversion to type of lower precedence must be made explicitly (with CAST or CONVERT function) CHAR -> VARCHAR -> NCHAR -> NVARCHAR -> BIT -> TINYINT -> SMALLINT -> INT -> BIGINT -> MONEY -> DECIMAL -> TIME -> DATE -> DATETIME2 -> XML https://msdn.microsoft.com/en-us/library/ms190309.aspx

Data Type Conversion

New Data Type Conversion Functions

Other Data Types Data type Range Storage (bytes) rowversion Auto-Generated 8 uniqueidentifier 16 xml 0-2 GB cursor NA hierarchyid Depends on content sql_variant 0-8000 bytes table