Silent Killers Lurking in Your Schema Mickey Stuewe

Slides:



Advertisements
Similar presentations
Bordoloi and Bock Chapter 2 :TABLES AND INDEXES. Bordoloi and Bock One of the first steps in creating a database is to create the tables that will store.
Advertisements

Designing Tables in Microsoft Access By Ed Lance.
SQL’s Data Definition Language (DDL) n DDL statements define, modify and remove objects from data dictionary tables maintained by the DBMS n Whenever you.
Physical Database Design Chapter 5 G. Green 1. Agenda Purpose Activities Fields Records Files 2.
Project Management Database and SQL Server Katmai New Features Qingsong Yao
Action Queries CS 320. Review: SQL Command Types  Data Definition Language (DDL)  Used to create and modify database objects  Data Manipulation Language.
 Microsoft Access is one of two primary database offering from Microsoft.  Access is a network/desktop-based database.  Advantage: It is easy to use.
IS 4420 Database Fundamentals Chapter 6: Physical Database Design and Performance Leon Chen.
SQL Table Basics. Database Objects Tables Temporary tables (begin with #) Views Keys Indexes.
SQL Keys and Constraints Justin Maksim. Key Declaration Key constraint defined within the CREATE TABLE command Key can be declared using either the PRIMARY.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
Copyright ©2014 Pearson Education, Inc. Chapter 6 Physical Design Chapter6.1.
DATABASES AND SQL. Introduction Relation: Relation means table(data is arranged in rows and columns) Domain : A domain is a pool of values appearing in.
Introduction to SQL  SQL or sequel  It is a standardised language with thousands of pages in the standard  It can be in database system through GUI,
Irwin/McGraw-Hill Copyright © 2000 The McGraw-Hill Companies. All Rights reserved Whitten Bentley DittmanSYSTEMS ANALYSIS AND DESIGN METHODS5th Edition.
Using XML in SQL Server 2005 NameTitleCompany. XML Overview Business Opportunity The majority of all data transmitted electronically between organizations.
Irwin/McGraw-Hill Copyright © 2000 The McGraw-Hill Companies. All Rights reserved Whitten Bentley DittmanSYSTEMS ANALYSIS AND DESIGN METHODS5th Edition.
CODD’s 12 RULES OF RELATIONAL DATABASE
CSC 2720 Building Web Applications Database and SQL.
Common Field Types Primary Key Descriptive Fields Foreign Key.
SQL Data Definition Language (DDL) Using Microsoft SQL Server 1SDL Data Definition Language (DDL)
11 3 / 12 CHAPTER Databases MIS105 Lec15 Irfan Ahmed Ilyas.
M1G Introduction to Database Development 2. Creating a Database.
D R. E.F.C ODD ’ S R ULES FOR RDBMS Dr. E.F.Codd is an IBM researcher who first developed the relational data model in 1970.Dr. Codd published a list.
SQL Server 2005 Implementation and Maintenance Chapter 3: Tables and Views.
Visual Programing SQL Overview Section 1.
GLOBEX INFOTEK Copyright © 2013 Dr. Emelda Ntinglet-DavisSYSTEMS ANALYSIS AND DESIGN METHODSINTRODUCTORY SESSION EFFECTIVE DATABASE DESIGN for BEGINNERS.
Sql DDL queries CS 260 Database Systems.
DBMS 3. course. Reminder Data independence: logical and physical Concurrent processing – Transaction – Deadlock – Rollback – Logging ER Diagrams.
Chapter 3: Relational Databases
Database Design: Solving Problems Before they Start! Ed Pollack Database Administrator CommerceHub.
Fundamentals of DBMS Notes-1.
Databases Chapter 9 Asfia Rahman.
DB storage architectures: Rows, Columns, LSM trees
Managing Tables, Data Integrity, Constraints by Adrienne Watt
Data Definition and Data Types
Lecture 05: SQL Wednesday, January 12, 2005.
Relational Database Management System
Module 2: Creating Data Types and Tables
Physical Database Design
Accidental DBA Developer Edition
Lecture 6 Data Model Design (continued)
Data Definition and Data Types
CSIS 115 Database Design and Applications for Business
Attributes and Domains
Chapter 4 Relational Databases
Designing Tables for a Database System
What is Database Administration
Introduction to Database Systems CSE 444 Lecture 04: SQL
DATABASE MANAGEMENT SYSTEM
STRUCTURED QUERY LANGUAGE
Lecturer: Mukhtar Mohamed Ali “Hakaale”
What is your Character Data Type?
The Relational Model Relational Data Model
Relational Database Model
Microsoft SQL Server 2014 for Oracle DBAs Module 7
PT2520 Unit 5: Physical Design
CMPT 354: Database System I
Data Types Do Matter Start local instance of SQL Start ZoomIt
Oracle Data Definition Language (DDL)
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Attributes and Domains
Chapter 2: Creating And Modifying Database Tables
The Curious case of the foreign key
Database Design: Relational Model
Instructor: Mohamed Eltabakh
Indexes and more Table Creation
Relational data model. Codd's Rule E.F Codd was a Computer Scientist who invented Relational model for Database management. Based on relational model,
Presentation transcript:

Silent Killers Lurking in Your Schema Mickey Stuewe Sr. Database Developer Microsoft Geek Red Gate Nerd

Your Background DBA Database Developer Programmer Manager Just Checking Things Out

Objectives Data Types Smart Keys Naming Named Value Pairs Nullability Constraints Indexes Hard Coded Lists Minimal Auditing

Data types can be data hogs Data Types Affects range of possible values Affects storage Affects behavior of functions Affects choices of indexes Affects quality of your data Data types can be data hogs

Data Types TINYINT SMALLINT INT BIGINT Size 1 Byte 2 Bytes 4 Bytes Range 0 to 255 -32,768 to 32,768 -2,147,483,648 to 2,147,483,648 -2^63 to 2^63

Data Types TINYINT SMALLINT INT BIGINT Size 1 Byte 2 Bytes 4 Bytes Range 0 to 255 -32,768 to 32,768 -2,147,483,648 to 2,147,483,648 -2^63 to 2^63 Bad Use Year PK of trans data Age Number of dependents PK of “click data” Birth month PK for a lookup table

Data Types TINYINT SMALLINT INT BIGINT Size 1 Byte 2 Bytes 4 Bytes Range 0 to 255 -32,768 to 32,768 -2,147,483,648 to 2,147,483,648 -2^63 to 2^63 Bad Use Year PK of trans data Age Number of dependents PK of “click data” Birth month PK for a lookup table Good Use

Data Types CHAR VARCHAR NVARCHAR NVARCHAR (MAX) Size 1 byte per char. (fixed length) 2 bytes + 1 byte per char. 2 bytes + 2 bytes per char. Up to 2 GB Range 1 to 8000 char. 1 to 4000 char. 1 char to 2GB

Data Types CHAR VARCHAR NVARCHAR NVARCHAR (MAX) Size 1 byte per char. (fixed length) 2 b + 1 byte per char. 2 bytes + 2 byte per char. Up to 2 GB Range 1 to 8000 char. 1 to 4000 char. 1 char to 2GB Bad Use Order Notes Middle Name Gender (F/M) Middle Initial State Capitals Lookup Values Almost Everything

Data Types CHAR VARCHAR NVARCHAR NVARCHAR (MAX) Size 1 byte per char. (fixed length) 2 b + 1 byte per char. 2 bytes + 2 byte per char. Up to 2 GB Range 1 to 8000 char. 1 to 4000 char. 1 char to 2GB Bad Use Order Notes Middle Name Gender (F/M) Middle Initial State Capitals Lookup Values Almost Everything Good Use Capitals of the world suser_name() Notes that can go over 4000 characters

Data Types No Indexes on NVARCHAR (MAX)…EVER CHAR VARCHAR NVARCHAR Size 1 byte per char. (fixed length) 2 b + 1 byte per char. 2 bytes + 2 byte per char. Up to 2 GB Range 1 to 8000 char. 1 to 4000 char. 1 char to 2GB Bad Use Order Notes Middle Name Gender (F/M) Middle Initial State Capitals Lookup Values Almost Everything Good Use Capitals of the world suser_name() Notes that can go over 4000 characters Max str. fields in index <= 900 Char <= (900) – (2 x no.fields) <= (450) – (2 x no.fields) Can’t touch this.

Data Types Hint: DateTime2 is the best thing since sliced bread Homework: Compare date data types

Smart Keys MED15 – 000456 - F Smart Keys Are Not So Smart Pro Easy to decipher Multiple pieces of information in one column Con Fragmented indexes Can get out of hand Breaks Codd’s rules MED15 – 000456 - F

Bad Naming AEC AER IOU FICO Return Review Split Id Field1 Sheet!1 It Shouldn’t Be Aa Box Of Chocolates Generic columns named Column1…n Abbreviations Reserved Words Default Names Bit columns: Active vs isActive Spelling AEC AER IOU FICO Return Review Split Id Field1 Sheet!1 Sheet1$ YourNameHere From User Create UserColumn01 UserColumn02 … UserColumn08 AEC Average Efficiency Cost AER Annual Equivalent Return AER Annual Equivalent Rate Return Review

Named Value Pairs Long Distance Dating Pro Easy to insert Easier for applications Con VARCHAR/NVARCHAR only Hard for reporting Lack of Foreign Keys Breaks Codd’s rules Maintenance Lack of Constraints Possible Dirty Data Rule 1: The information rule: All information in a relational database (including table and column names) is represented in only one way, namely as a value in a table.

Nullability To NULL Or Not To NULL, That Is The Question Has a purpose – represents “no data” Column of type BIT should not be nullable Be careful with ISNULL function Rule 3: Systematic treatment of null values: The DBMS must allow each field to remain null (or empty). Specifically, it must support a representation of "missing information and inapplicable information" that is systematic, distinct from all regular values (for example, "distinct from zero or any other number", in the case of numeric values), and independent of data type. It is also implied that such representations must be manipulated by the DBMS in a systematic way. Rule 3: Systematic treatment of null values: The DBMS must allow each field to remain null (or empty). Specifically, it must support a representation of "missing information and inapplicable information" that issystematic, distinct from all regular values (for example, "distinct from zero or any other number", in the case of numeric values), and independent of data type. It is also implied that such representations must be manipulated by the DBMS in a systematic way.

Constraints Constrain the data, she’s goanna blow! Protect against bad data Check Constraints Foreign Key Constraints Unique Constraints Check end date is after begin date Check a month is a month Check birthdate is not in the future

Indexes Resource: JasonStrate.com She can’t take any more. She’s maxed at 900 bytes! Not all Primary Keys should be clustered Indexes Add Indexes to heavily used columns Have a good balance of indexes Resource: JasonStrate.com Surrogate primary keys vs natural keys How is the table used? Does it have more reads than writes? Is it meant for reporting? Is the data retrieved in large ranges or one row at a time?

Hard Coded Lists Danger Will Robinson! Unable to change them efficiently Unable to validate against them outside of application or query Hard to maintain over time No referential integrity Dirty data will happen

Minimal Auditing CreatedBy CreatedOn UpdatedBy UpdatedOn Who’s on first. When’s on second. Can provide quick insight as to when data was changed Can provide quick insight as to who changed the data Can provide insight to bugs Can be used by ETL processes Can be used for partitioning CreatedBy CreatedOn UpdatedBy UpdatedOn

Show Me The Demo

Objectives Data Types Smart Keys Naming Named Value Pairs Nullability Constraints Indexes Hard Coded Lists Minimal Auditing

Questions?

Presentation Contact Online www.MickeyStuewe.com/Resources Mickey@MickeyStuewe.com Twitter: @SQLMickey Online MickeyStuewe.com Bigpass.sqlpass.org YouTube.com: Mickey Stuewe