NULLs and Other SQL Gotchas

Slides:



Advertisements
Similar presentations
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Advertisements

Characteristic Functions. Want: YearCodeQ1AmtQ2AmtQ3AmtQ4Amt 2001e (from fin_data table in Sybase Sample Database) Have: Yearquartercodeamount.
Database Systems: Design, Implementation, and Management Tenth Edition
Chapter 11 Group Functions
Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
MUCH ADO ABOUT NOTHING Walter Schenk SoluTech Consulting Services Inc.
Maintaining Referential Integrity Pertemuan 2 Matakuliah: T0413/Current Popular IT II Tahun: 2007.
5 Chapter 5 Structured Query Language (SQL2) Revision.
SQL Review (con’d) INLS 258 Fall Select Example SELECT teacher.name FROM teacher WHERE teacher.PID in (SELECT teachID FROM teaches WHERE teaches.coursenum.
Nov 24, 2003Murali Mani SQL B term 2004: lecture 12.
Introduction to Oracle9i: SQL1 SQL Group Functions.
SQL Table Basics. Database Objects Tables Temporary tables (begin with #) Views Keys Indexes.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 7 Introduction to Structured Query Language (SQL)
Copyright ©2014 Pearson Education, Inc. Chapter 6 Physical Design Chapter6.1.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
 Agenda 2/20/13 o Review quiz, answer questions o Review database design exercises from 2/13 o Create relationships through “Lookup tables” o Discuss.
BY SATHISH SQL Basic. Introduction The language Structured English Query Language (SEQUEL) was developed by IBM Corporation, Inc., to use Codd's model.
Views Lesson 7.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 7 Introduction to Structured.
Using the Table API. Standard Uses of API Populate Columns via Sequences Insert Default Values instead of nulls Populate Autogen Columns –Date Created,
EXPRESSION Transformation. Introduction ►Transformations help to transform the source data according to the requirements of target system and it ensures.
Advanced SELECT Queries CS 146. Review: Retrieving Data From a Single Table Syntax: Limitation: Retrieves "raw" data Note the default formats… SELECT.
IFS Intro to Data Management Chapter 5 Getting More Than Simple Columns.
SQL Server 2005 Implementation and Maintenance Chapter 3: Tables and Views.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
Database Terms Hernandez, Chapter 3. Data/Information The values you store in the database are data. Pieces of Data in and of themselves is not particularly.
Access Queries Agenda 6/16/14 Review Access Project Part 1, answer questions Discuss queries: Turning data stored in a database into information for decision.
Chapter 8 Arrays. A First Book of ANSI C, Fourth Edition2 Introduction Atomic variable: variable whose value cannot be further subdivided into a built-in.
SQL. Originally developed by IBM Standardized in 80’s by ANSI and ISO Language to access relational database and English-like non-procedural Predominant.
IMS 4212: Constraints & Triggers 1 Dr. Lawrence West, Management Dept., University of Central Florida Stored Procedures in SQL Server.
1 DBS201: More on SQL Lecture 2. 2 Agenda Select command review How to create a table How to insert data into a table.
Sorting data and Other selection Techniques Ordering data results Allows us to view our data in a more meaningful way. Rather than just a list of raw.
Thinking in Sets and SQL Query Logical Processing.
SQL: Structured Query Language Instructor: Mohamed Eltabakh 1 Part II.
There’s a particular style to it… Rob Hatton
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
Retrieving Information Pertemuan 3 Matakuliah: T0413/Current Popular IT II Tahun: 2007.
Relational Databases Today we will look at: Different ways of searching a database Creating queries Aggregate Queries More complex queries involving different.
Standards and Conventions
Web Database Programming Using PHP
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Y.-H. Chen International College Ming-Chuan University Fall, 2004
SQL Query Getting to the data ……..
SQL – Python and Databases
Relational Database Design
Web Database Programming Using PHP
Dirt, Spit, and Happy FLWOR
Parameter Sniffing in SQL Server Stored Procedures
COP5725 DATABASE MANAGEMENT POSTGRESQL TUTORIAL
The Relational Model Relational Data Model
NULLs and Other SQL Gotchas
PHPMyAdmin.
Chapter # 7 Introduction to Structured Query Language (SQL) Part II.
TEMPDB – INTERNALS AND USAGE
Chapter 4 Summary Query.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Creating Tables & Inserting Values Using SQL
Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall
Database systems Lecture 3 – SQL + CRUD
Chapter 7 Introduction to Structured Query Language (SQL)
PT2520 Unit 5: Physical Design
Lesson Plan Instructional Objective Learning Objective
Contents Preface I Introduction Lesson Objectives I-2
SQL: Structured Query Language
Section 4 - Sorting/Functions
Aggregate Functions.
Trainer: Bach Ngoc Toan– TEDU Website:
Presentation transcript:

NULLs and Other SQL Gotchas Wendy Pastrick

About DBA since 2000 Salesforce Performance DBA Data Platform MVP since 2013 PASS Board of Directors – Virtual Chapters

Data Data Data Null ANSI settings Unknown NULL = NULL Validation ISNULL = NULL

No Data? Empty vs Null Datatype matters! Integer – converts to 0 String – Empty (‘’) Date -- 1900-01-01 00:00:00.000

Fallout Your SQL code that would otherwise expect to work like the IS NULL or IS NOT NULL checks won’t work anymore In case you were doing this for a number column, the aggregate functions like AVG() which otherwise would be ignoring the Null value will now count the record https://decipherinfosys.wordpress.com/2009/03/27/null-vs-empty-zero-length-string/

Fallout…more The SQL code which uses functions like ISNULL(), COALESCE() etc. will not function as expected since these fields will not have a Null value. The sorts won’t work as expected since Null and the empty string (and the subsequent default value that actually gets inserted) are not the same thing.

….and even More If you have this column as part of the foreign key, you will get an error at the time of the insert itself since instead of a Null value, the code will try to insert another default value in and it will violate the FK constraint. Any concatenation operations or MAX(), MIN() functions can lead to un-desired results.

Scalar Functions Performance killer RBAR Only returns a single value per input Table Valued Functions preferable, but still not awesome.

Thank You! Wendy.Pastrick@gmail.com Resources https://sqlstudies.com/2014/07/14/what-does-it-mean-that-a-value-is-null/ http://www.sqlservercentral.com/blogs/sqlstudies/2014/07/28/what-is-ansi_nulls-and- why-will-i-be-glad-when-it-finally-goes-away/ http://thomaslarock.com/2009/03/sql-server-and-null-values/ https://decipherinfosys.wordpress.com/2007/07/18/empty-string-and-integer-data- type/ https://decipherinfosys.wordpress.com/2009/03/27/null-vs-empty-zero-length-string/ http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/12/bad-habits-to-kick- using-the-wrong-data-type.aspx