Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 Data Types Lesson 4

2 Skills Matrix

3 Table A table stores your data. Tables are relational in that they are organized as rows and columns (a matrix). Each intersection of a row and column provides a storage location. Each storage field must be defined with a data type.

4

5 Data Type Specifies the kind of information that can be stored in a column, parameter, or variable. System-supplied data types are provided by SQL Server. Alias data types (formerly known as user- defined data types) can be created by any database user.

6 Built-in Data Types Each field, or column, in a table has a specific data type, which causes the RDBMS to restrict the type of data that can be inserted.

7

8 SQL Server Built-in Data Types biging binary bit char date datetime datetime2 datetimeoffset decimal float geography geometry hierarchyid image int money nchar ntext numeric nvarchar

9 SQL Server Built-in Data Types nvarchar(max) real smalldatetime smallint smallmoney sql_variant text time timestamp tinyint uniqueidentifier varbinary varbinary (max) varchar varchar(max) vardecimal xml

10 Data Type Precedence Data types have a certain order, or precedence. This means when combining data types, implicit data conversion occurs, and the data type with the highest rank will be given priority.

11 Data Type Precedence 1.User-defined data types (highest) 2.Sql_Variant 3.Xml 4.DateTimeOffset 5.DateTime2 6.DateTime 7.SmallDateTime 8.Date 9.Time 10.Float 11.Real 12.Decimal 13.Money 14.SmallMoney 15.BigInt 16.Int 17.SmallInt 18.TinyInt 19.Bit 20.NText

12 Data Type Precedence 21.Text 22.Image 23.Timestamp 24.Uniqueidentifier 25.Nvarchar/Nvarchar(Max) 26.Nchar 27.Varchar/Varchar(Max) 28.Char 29.VarBinary/VarBinary(Max) 30.Binary (lowest)

13 Formatting and Converting Data You’ll often need to convert and modify data. SQL Server offers an extensive set of functions you can use to perform conversions and formatting. You can categorize these functions into groups, as delineated in the following sections.

14 Introducing Alias Data Types Sometimes it’s useful to create your own data types in order to streamline your business environment and use a common method for referring to specific data. You gain a major benefit when using managed code, CLR (common language runtime), because it also gives you the ability to create a complex data type and define its methods and properties. You define an alias data type in SQL Server by using either the CREATE TYPE or the sp_addtype syntax.

15 Creating CLR User-Defined Types Working with managed code data types or CLR alias types adds an additional dimension to how you work with SQL Server. –A user-defined type can be a CLR class that has reference types and value types. Alias types contain multiple elements and are useful in environments to indicate geospatial data, to indicate date and time functionality, or even to perform data encryption or object-oriented storage.

16 Creating CLR User-Defined Types Catalog the assembly (CREATE ASSEMBLY). Create the data type by using a CREATE TYPE statement, in which you reference the assembly.

17 Data Row A data row consists of a row header (4 bytes) followed by a data portion. The data portion can contain: –Fixed-length data –Null block –Variable block –Variable-length data

18 Page SQL Server enters fixed-length data into a slot on a page before variable-length data. An empty fixed-length data entry takes as much space as a populated entry. A table with only fixed-length columns always stores the same number of rows on a page.

19 Estimating Table Storage Requirements Tables provide templates specifying data storage. All data stored in a table must adhere to a data type.

20 Estimating Table Storage Requirements You can follow a specific process to estimate the space required by a table: –1.Calculate the space used by a single row of the table. –2.Calculate the number of rows that fit on one page. –3.Estimate the number of rows the table will hold. –4.Calculate the total number of pages that might be required to hold these rows.

21 Data Types and Sizes

22 Calculating Rows Per Page Once you have a number indicating the total bytes used per row, you can easily calculate the number of rows that fit on a single page. Because every page equals 8 KB in size and has a header, about 8,096 bytes are free for storing data. You can calculate the total number of rows per page as follows: 8096 ÷ (RowSize + 2)

23 Estimating Table Storage Requirements Estimating the Number of Rows for the Table Calculating the Number of Pages Needed Estimating Index Storage Requirements

24 Summary You learned that tables consist of columns and rows (entities and instances) and that each of the fields (the intersections) in the table has a specific data type that restricts the form of data it can hold and return.

25 Summary Then you learned you can create your own data types both with Transact-SQL and with several procedural languages. –Transact-SQL data types use system data types with all the required parameters presupplied and labeled in a more obvious way; for example, zip instead of char(5).

26 Summary You learned that each of these data types has a storage requirement. –Based on your choices your database can be larger than optimum to meet your business needs. –Consider sitting down with subject matter experts and plan data requirements prior to creating database objects.

27 Summary –Consider using the techniques espoused by Business Process Reengineering, Joint Application Design, or Service-Oriented Architecture techniques to help you. –You need to decide what tables will contain and make the tables as specific and efficient as possible.

28 Summary Consider using automated tools such as ER/Studio (Embarcadaro Systems) or ERWIN (Computer Associates) to help you with such tasks as affinity analysis (the grouping of related items appropriate to a single table).

29 Summary for Certification Examination Know your data types. Be familiar with the built-in data types and know when to use each one. For example, it might be obvious to you when you should use varchar instead of float, but it might not be as obvious when you need to use smallmoney versus money. Designing databases considers trade-offs and balances. The certification examination poses questions requiring the best solution.

30 Summary for Certification Examination Know the basics of how to retrieve and format data into information. In conjunction with the SELECT statement, know the difference between CAST and CONVERT. Both can do most functions. CONVERT adds style formatting capabilities.


Download ppt "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."

Similar presentations


Ads by Google