SlideShare a Scribd company logo
1 of 36
THE GOLDEN
HAMMERConfessions of a Recovering Database Abuser
"I suppose it is tempting, if the only tool you have is a hammer, to treat
everything as if it were a nail." - Abraham Maslow (1966)
Who am I?
Shawn Oden
I started life as a pilot who became a flight instructor who was briefly an airline pilot before I
accidentally switched into a ColdFusion developer who, by some fluke, morphed into a
database developer who adventurously (and somewhat masochistically) decided to be a
DBA. And that’s who I am today. Who knows what tomorrow may bring.
• Microsoft Certified Professional: SQL Server
• CompTIA Security+
• Adobe Certified ColdFusion Specialist
• Adobe Certified ColdFusion MX 7 Developer
• Macromedia Certified ColdFusion MX Developer
@CodeFuMonkey
codefumonkey@gmail.com
https://www.codefumonkey.com
Note: I am CodeFuMonkey, NOT ColdFuMonkeh, nor am I affiliated with monkehworks.com. I know
that Mr. Gifford and I are easy to get mixed up, but the similarity of our noms de plume occurred many
moons ago and was completely unintentional on my part. Sorry, Matt.
First things first…
■ Rule #1:
 DO NOT TEST THINGS IN A PRODUCTION DATABASE!
• Trust me. Murphy’s Law is a real thing.
■ Rule #2:
– DO NOT REPORT FROM A PRODUCTION DATABASE.
• Set up a Reporting instance of your database. Your users will appreciate it.
■ Rule #3:
– BACKUPS ARE WORTHLESS IF THEY AREN’T TESTED.
• If you have a need to RESTORE a BACKUP, chances are it’s a bad day.
• Test them before you need them.
• Script the RESTOREs so you don’t have to dig into StackOverflow.
■ Rule #4:
– WHEN IT COMES TO DATABASES, AS WITH MOST PROGRAMMING THINGS,
THERE REALLY ARE FEW HARD AND FAST RULES.
• It nearly always Depends.
■ Rule #5:
– EXCEPT WHEN IT COMES TO TESTING THINGS IN PRODUCTION
 DO NOT DO IT!
Now that we’ve reviewed some
basic rules, let’s talk about …
• What is SQL?
• Databases Are Complex.
• What Bad Habits Did I Get Into?
• SIDEBAR: JOINs
• Some SQL Gotchas.
• There’s Just So Many Things To Cover
• Wrapping Up. For Now.
Let’s jump in…
What is SQL?
According to Webster’s Dictionary:
“SQL - /S Q L/ An industry-standard language for creating, updating and,
querying relational database management systems.”
According to Wikipedia:
“SQL (/ˌɛsˌkjuːˈɛl/ S-Q-L or /ˈsiːkwəl/ "sequel“ [Structured Query Language])
is a domain-specific language used in programming and designed for
managing data held in a relational database management system (RDBMS),
or for stream processing in a relational data stream management system
(RDSMS). It is particularly useful in handling structured data, i.e. data
incorporating relations among entities and variables.”
And the most important thing to take away from that is:
“Do I pronounce it ‘ess-que-ell’ or ‘sequel’?”
– Technically, it’s ‘ess-que-ell’, but I use both, depending on the context. In my opinion
though, that’s kinda like asking a developer how to pronounce “.gif” or “JSON”.
Clear as mud. So…What Is
SQL?
■ SQL is a standard language you can use to talk to the
server were the data is stored:
■ It is a “Declarative” language instead of an
“Imperative” language.
– This is a pretty significant paradigm shift from most
programming languages. With SQL, Don’t Tell; Ask.
■ SQL is used to get information from your back-end
system to be sent to the front-end for display.
– The SQL language (and especially the proprietary
implementations) have the ability to do much of your
business logic, but that is likely better suited for your
application.
■ DBMS engines are pretty smart.
– They’re pretty good at figuring out what you want based on
what you have, but they can’t read minds. Yet.
Databases Are Complex
■ Your DBMS does a lot more than just hold data.
■ Your DBMS may have a fairly robust Security scheme
for managing users or encrypting data.
■ Your DBMS likely has the capability for backing your
data, or for providing for redundancy.
■ Your DBMS likely has its own dialect of SQL that
provides for additional functionality not included in the
SQL Standard.
■ Most SQL is simple CRUD.
– “I can make this SQL thing work.”
■ My queries worked well for a few hundred rows.
■ They didn’t work so well for a few million rows.
Next up…
doh.sql
Typing Column Names Is Hard
■ What is happening?
– We’re selecting all columns from the table.
– This usually selects more data than is needed.
■ That causes the database to work harder
■ That causes the network to work harder
■ That causes the application to work harder
– This may cause the proper index to be ignored.
– This may cause a bad query plan to be generated.
– If the underlying column name or order changes, your
application might break
■ What should we do?
– Only SELECT the columns that are needed.
SELECT col1, col2, col3 FROM myTable
SELECT * FROM …….
I Only Need The First n Rows
■ What is happening?
– When ColdFusion sends the query to the database, an
instruction from the JDBC driver tells the database to stop
processing and return records after MAXROWS records.
■ On the Application side, nothing will be noticed.
■ On the Database side, since this is an instruction from JDBC,
the query may continue to process the total number of records
from the SELECT.
– This may cause the database to ignore the MAXROWS
attribute, and process all rows.
– This may cause an incorrect plan to be used.
■ What should we do?
– This depends on the DBMS used.
■ SQL Server: SELECT TOP 42 col1 FROM myTable
■ MySQL: SELECT col1 FROM myTable LIMIT 42
<cfquery ……. maxrows=“42”>
SELECT cols FROM myTable
</cfquery>
Who Was In Last?
■ What is happening?
– This pattern has been used to get the id (autogenerated) of the
last record inserted into the table.
■ Why is this bad?
– This query seems to work fine on a single developer machine
when that developer is the only one INSERTing data. However,
this query can retrieve the wrong id if another INSERT happens
between the two queries.
■ What should we do?
– There are a number of different database-specific ways to query
this id, but ColdFusion has a very simple built-in method:
<cfquery name=“query1”>
INSERT INTO myTable (name)
VALUES (‘Bob’)
</cfquery>
<cfquery name=“LastInserted”>
SELECT TOP 1 id FROM myTable ORDER BY InsertDate DESC
</cfloop>
<cfquery name=“query1” result=“myResult”> INSERT ……<cfquery>
<cfoutput>#myResult.GENERATEDKEY#</cfoutput>
Looping Over A Query
■ What is happening?
– Every loop of the query is creating a new cfquery to get name
from myTable1.
■ What should we do?
– The same result can be accomplished with a single query and a
proper WHERE filter. Then cfloop over the output rather than the
query.
■ This would reduce expensive connections to the database and
make the application faster.
■ Looping over a query will create a new database connection on each
iteration. This can become very expensive and slow down or halt your
application.
<cfloop index=“i” from=“1” to=“42”>
<cfquery name=“query1”>
SELECT name FROM myTable1 WHERE id = #i#
</cfquery>
<cfoutput>#query1.name#</cfoutput><br>
</cfloop>
I Need To Use One Query For Data
In Another Query
■ What is happening?
– This is just another loop over a query. All negatives still apply.
– The first query gets id from myTable1.That id is used to
retrieve related records from myTable2. The records from
myTable2 are displayed as a subsection of query1’s id.
■ This might be used for a nested list or hierarchal information.
■ What should we do?
– More often than not, this can be accomplished with a proper
SQL JOIN.
<cfquery name=“query1”>
SELECT id FROM myTable1
</cfquery>
<cfoutput>#query1.id#</cfoutput><br>
<cfoutput query=“query1”>
<cfquery name=“query2”>
SELECT col1 FROM myTable2 WHERE q1ID = #id#
</cfquery>
<cfoutput>#query2.col1#</cfoutput><br>
</cfquery>
SIDEBAR: SQL JOINS
■ What is a JOIN?
– It is a way for SQL to relate one or more tables with each other.
– The type of JOIN will determine the data available in the final
product.
■ There are multiple types of SQL JOINs. A few are:
– INNER JOIN – This will return only the records that are
common between both named tables.
– OUTER JOIN – This will return all records from one table and
only those that are common from the second table.
Unmatched rows will contain NULL values.
• These can be either LEFT OUTER or RIGHT OUTER JOINs.
– FULL JOIN – This will return all records from both tables, with
matched data for matching rows and NULL data for
unmatched rows.
– CROSS JOIN – This will return all rows from one table matched
to all rows of the second table. This is a CARTESIAN PRODUCT.
NOTE: This list is not inclusive, and a ton of information is available
online.
SIDEBAR: SQL JOINS
SIDEBAR: SQL JOINS
■ My Personal View….
– The JOIN clause conditions are for linking tables together.
– The WHERE clause is for filtering results of the whole query.
SELECT table1.col1 AS t1Col1, table2.col1 AS t2Col1
FROM table1
INNER JOIN table2 ON table1.t2ID = table2.ID
AND table1.t2ProductID = table2.ProductID
AND table2.BuyerID = 42
WHERE table1.CustomerID = 4242
SELECT table1.col1 AS t1Col1, table2.col1 AS t2Col1
FROM table1, table2
WHERE table1.t2ID = table2.ID
AND table1.t2ProductID = table2.ProductID
AND table2.BuyerID = 42
AND table1.CustomerID = 4242
■ ANSI 89 JOINs
– PLEASE DON’T DO THIS. (ノಠ益ಠ)ノ彡┻━┻
– This is an older style of JOINing tables, and creates a Cartesian product
before filtering the query results.
– It has been deprecated.
Lookout Below!
SQL has some gotchas!
My Queries Keep Blocking Each
Other
■ The NOLOCK hint will fix that, right?
– Yes, but No.
– NOLOCK probably isn’t doing what you think it’s doing.
■ The NOLOCK hint functions similar to a READ UNCOMMITTED
transaction lock.
– This type of lock will allow for Dirty Reads of data.
■ This means that a record you just read under a NOLOCK hasn’t
been committed to the database yet, and it may be rolled back.
That means your data may not be accurate.
■ This could lead to Phantom Reads that give incorrect counts.
■ This should only be used on data that isn’t expected to change
much.
■ This should also only be used on a SELECT statement.
■ NOLOCK doesn’t keep your query from blocking other queries.
It just keeps other queries from blocking this one.
– Note that Microsoft SQL Server default is READ COMMITTED.
Data Type Conversion: 1 vs “1”
■ Will those convert to each other?
– For these, Yes. For others, It Depends.
■ CFML is a dynamically typed language.
– This often allows us to overlook implicit data type
conversions.
■ Implicit Conversion happens in SQL, too.
– Numbers can be converted to strings. Strings can sometimes
be converted to numbers. Dates are sort of stored in the
database as number-ish objects, but can’t be converted
directly to an integer, but they can be converted to a string.
– As with all things, there is some slight overhead, and some
things can’t be converted to other things.
– When JOINing, filtering with a WHERE, or any other type of
comparison, it’s important to factor in the data type of the
columns or variables you are trying to compare.
Data Type Conversion: Can I …?
Data Types: Character Types
■ Likely the most common types of data in your application.
■ Also the most easily abused through SQL injection, so pay attention to
these.
■ Character datatypes are either fixed-width (char,nchar) or variable-
width (varchar, nvarchar).
■ There are also text and ntext, but these have been deprecated. Use
varchar(max) or nvarchar(max) instead.
■ Don’t use the Unicode types (nchar, nvarchar) unless you need them.
If you are working with Internationalization, you’ll probably need
them.
Data Type n Actual Storage Size Maximum Value
char(n) 0-8000 n bytes Fixed-width. Will pad empty strings to the left.
nchar(n) 0-4000 n bytes
Fixed-width Unicode. A Unicode character
requires 2x storage space.
varchar(n) 0-8000 n+2 bytes
Variable-width. The value won’t pad extra
characters.
nvarchar(n) 0-4000 (n*2)+2 bytes Variable-width.
varchar(max)
Stores up to
2^31-1 bytes (~2GB)
Normal up to 8000bytes, then stored in text.
Data Types: Character Types
(caution)
■ In this situation, if you don’t specify a length of the varchar (i.e.
varchar(50)), the length will default to 1.
CREATE TABLE t1 ( col1 varchar )
CREATE PROCEDURE mySproc @myvar varchar …
DECLARE @val1 varchar …
■ These would also default to a length of 1.
SELECT CAST(col1 AS varchar) FROM….
■ In a Stored Procedure, not declaring a length on a varchar will
default it to 30 bytes.
Not specifying a length for a char or varchar may lead to
unintentional (bad) or silent (worse) truncation that can be very hard
to troubleshoot.
Data Types: Character Types
(more caution)
■ If you are trying to compare a fixed-width column, make sure that
you provide the proper width in your comparison.
■ In the above example, if x is a 5-character char data type, then it
will never be equal to the 3-character sting “foo”.
SELECT … FROM … WHERE x = ‘foo’
SELECT … FROM … WHERE x = ‘ foo’
■ The above may be what you want.
SELECT … FROM … WHERE x = ‘ foo ’
■ That would also work. Usually.
■ The SQL Standard says that when two strings are compared, their
lengths must be equal. A string with trailing empty spaces will have
those empty spaces ignored.
Data Types: Exact Numbers -
Integers
■ Exact numbers will always be represented completely.
■ 1 + 2 = 3
■ An integer datatype will be a whole number. When coercing a
decimal to an integer, watch out for rounding or truncation.
Data Type Storage Size Minimum Value Maximum Value
tinyint 1 byte 0 255
smallint 2 bytes -32,768 32,767
int 4 bytes -2,147,483,648 2,147,483,674
bigint 8 bytes -9,223,372,036,854,775,808 9,223,372,036,854,775,807
Data Types: Exact Numbers -
Decimals
■ A decimal type is still an exact representation of a number.
■ .1 + .2 = .3
■ Decimals are declared like decimal(P,S), where P is Precision and
S is Scale.
– When declaring a decimal, the default precision is 38 and
default scale is 0.
■ Numeric and Decimal datatypes are the same thing.
■ Converting from decimal/numeric to float/real can cause some
loss of precision.
Data Type Storage Size
Decimal(1-9) 5 bytes
Decimal(10-19) 9 bytes
Decimal(20-28) 13 bytes
Decimal(29-38) 17 bytes
Data Types: Approximate Numbers
■ These are a little more challenging. They aren’t always
represented completely, and some rounding issues become
apparent.
■ So .1 + .2 = .3, right? NOPE. It’s 0.30000000000000004.
■ (ノಠ益ಠ)ノ彡┻━┻
■ Floats and Reals can store extremely large or small numbers, but
don’t use them for precise calculations.
■ The real datatype is essentially a float(24).
Data Type n Storage Size Precision Minimum Value Maximum Value
Float(n)
1-24 4 bytes 7 digits -1.79E + 308 1.79E + 308
25-53 2 bytes 15 digits -1.79E + 308 1.79E + 308
real n/a 4 bytes 7 digits -3.40E + 38 3.40E + 38
Data Types: Dates. My Favorite.
■ Inside a database, a date is not what you see on your screen.
– It is usually stored as an integer or other representation of days
and/or seconds since the system’s epoch, which may be:
■ 1 JAN 1900 for SQL Server and other Microsoft products
■ 1 JAN 1970 for most Unix-ish systems
■ 31 DEC 1969 for some systems.
■ Sometimes…. (ノಠ益ಠ)ノ彡┻━┻ ┻━┻ ┻━┻
■ Dates and Date Math will drive you crazy.
– I hate dates.
■ However, PLEASE PLEASE PLEASE store a date as a date object and
not as a string.
– It is much more involved to try to add a day to a string
representation of a date.
– It is much more involved to try to find the difference of two dates
when they are strings
– It’s much more involved to do X when dates are converted to
strings.
■ This holds true for pretty much any language.
I Thought We Already Played Y2K!
■ In the lead-up to the turn of the century, some very smart people
worked very hard to ensure that the vast majority of the
population had no idea of the scope of they Y2K problem.
– We survived, but there are still systems using 2-digit years.
– We dodged one bullet, but we’ve got another one coming up.
At 03:14:07 UTC on the morning of 19 January 2038 we will
exceed the number of seconds able to be represented by a signed 32-
bit integer.
– Did you ever think that 2.1 BILLION seconds would run out
that fast?
Even More Things to Think About
■ “RBAR” (pronounced “re bar”): Row By Agonizing Row - Jeff Moden
– SQL is designed to be Set-Based.
■ The engine has to work harder when it does a large operation
involving multiple rows if it’s told to do them one at a time.
■ https://sqlstudies.com/2016/08/17/rbar-vs-batch/
– Functions in the query can also cause RBAR.
– RBAR IS SLOW
■ CTE: Common Table Expression
– Very handy for building up a data set into a temporary table
for use within the main query
– Can only be used with SELECT, INSERT, UPDATE, DELETE
– Must be the first statement in a batch. (hint: “;”)
■ Window Functions
– Very good way to aggregate data inside of a specific window
of data within your query.
Even More “More Things to Think
About”
■ BETWEEN
– If you need to find results that fall between two points, SQL
does have a BETWEEN comparison. However, it’s ambiguous.
– In SQL Server, BETWEEN is INCLUSIVE of both sides.
• ...WHERE x BETWEEN 1 AND 4 will return results that match
1,2,3 and 4.
• This can be tricky with Dates. How do you return all days in
January?
• It’s usually better to be EXPLICIT. Use y >=x AND y<=z instead.
■ The more you say, the better.
– Be explicit. Don’t use shorthand.
■ What does DATEPART(Y, getDate()) return?
– Hint: DATEPART(year, getDate()) might return something
different.
Let Me Explain…
No, There Is Too Much…
Let Me Sum Up…
■ SQL IS HARD.
■ SQL has become a lot more capable since I started using it.
– It gets more complicated every year.
■ SQL is a completely different language, and to do things well
requires some deep study of what is happening.
■ Be curious.
■ I have barely scratched the surface of the things I’ve learned.
Resources and Other Things to
Play With
■ There’s always RTFM:
– https://docs.microsoft.com/en-us/sql/?view=sql-server-ver15
– https://dev.mysql.com/doc/refman/8.0/en/
– Just about every major database system has fairly thorough documentation online.
■ If you want a way to play with different flavors of SQL without installing them:
– http://sqlfiddle.com/ < U.S.-Based
• Has engines for MySQL, Oracle, PostgreSQL, SQLite and MS SQL Server
– https://dbfiddle.uk/ < U.K.-Based
• Has engines for many more databases
• Db2, Firebird, MariaDB, MySQL, Oracle, PostgreSQL, SQLite and MS SQL Server
• Because this one is U.K.-based, default date formats are dd-mm-yyyy.
■ If you want to practice some querying:
– SQL Murder Mystery is excellent.
– https://mystery.knightlab.com/
■ Who should you follow:
– Aaron Bertrand https://sqlblog.org/bad-habits/
– Brent Ozar https://www.brentozar.com/blog/
– Kendra Little https://littlekendra.com/
– Kevin Kline https://kevinekline.com/
– #SQLFamily on Twitter https://twitter.com/search?q=%23sqlfamily&src=typed_query
– And so many others….
But If You Take Nothing Else Away
From This Talk…
DO NOT TEST THINGS IN A
PRODUCTION DATABASE!
THANK YOU FOR LISTENING
TO ME JABBER FOR A BIT
Shawn Oden
@CodeFuMonkey
codefumonkey@gmail.com
https://www.codefumonkey.com
I Would Also Like To
Extend A Big Thank You To
Ortus Solutions for Into
The Box and Everything
Else That They Do!

More Related Content

Similar to Golden Hammer - Shawn Oden

My SQL Skills Killed the Server
My SQL Skills Killed the ServerMy SQL Skills Killed the Server
My SQL Skills Killed the ServerdevObjective
 
What Your Database Query is Really Doing
What Your Database Query is Really DoingWhat Your Database Query is Really Doing
What Your Database Query is Really DoingDave Stokes
 
My Database Skills Killed the Server
My Database Skills Killed the ServerMy Database Skills Killed the Server
My Database Skills Killed the ServerColdFusionConference
 
Sql interview question part 8
Sql interview question part 8Sql interview question part 8
Sql interview question part 8kaashiv1
 
7 Database Mistakes YOU Are Making -- Linuxfest Northwest 2019
7 Database Mistakes YOU Are Making -- Linuxfest Northwest 20197 Database Mistakes YOU Are Making -- Linuxfest Northwest 2019
7 Database Mistakes YOU Are Making -- Linuxfest Northwest 2019Dave Stokes
 
High Performance Mysql
High Performance MysqlHigh Performance Mysql
High Performance Mysqlliufabin 66688
 
Conquering "big data": An introduction to shard query
Conquering "big data": An introduction to shard queryConquering "big data": An introduction to shard query
Conquering "big data": An introduction to shard queryJustin Swanhart
 
SPL_ALL_EN.pptx
SPL_ALL_EN.pptxSPL_ALL_EN.pptx
SPL_ALL_EN.pptx政宏 张
 
NoSQL for great good [hanoi.rb talk]
NoSQL for great good [hanoi.rb talk]NoSQL for great good [hanoi.rb talk]
NoSQL for great good [hanoi.rb talk]Huy Do
 
Quick & Easy SQL Tips
Quick & Easy SQL TipsQuick & Easy SQL Tips
Quick & Easy SQL TipsIke Ellis
 
White Paper for OMG! Identifying and Refactoring Common SQL...
White Paper for OMG! Identifying and Refactoring Common SQL...White Paper for OMG! Identifying and Refactoring Common SQL...
White Paper for OMG! Identifying and Refactoring Common SQL...Jeff Jacobs
 
Tech Talk Series, Part 2: Why is sharding not smart to do in MySQL?
Tech Talk Series, Part 2: Why is sharding not smart to do in MySQL?Tech Talk Series, Part 2: Why is sharding not smart to do in MySQL?
Tech Talk Series, Part 2: Why is sharding not smart to do in MySQL?Clustrix
 
Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...
Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...
Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...Dave Stokes
 

Similar to Golden Hammer - Shawn Oden (20)

My SQL Skills Killed the Server
My SQL Skills Killed the ServerMy SQL Skills Killed the Server
My SQL Skills Killed the Server
 
Sql killedserver
Sql killedserverSql killedserver
Sql killedserver
 
The tortoise and the ORM
The tortoise and the ORMThe tortoise and the ORM
The tortoise and the ORM
 
What Your Database Query is Really Doing
What Your Database Query is Really DoingWhat Your Database Query is Really Doing
What Your Database Query is Really Doing
 
My Database Skills Killed the Server
My Database Skills Killed the ServerMy Database Skills Killed the Server
My Database Skills Killed the Server
 
Sql interview question part 8
Sql interview question part 8Sql interview question part 8
Sql interview question part 8
 
Ebook8
Ebook8Ebook8
Ebook8
 
Breaking data
Breaking dataBreaking data
Breaking data
 
10 sql tips
10 sql tips10 sql tips
10 sql tips
 
7 Database Mistakes YOU Are Making -- Linuxfest Northwest 2019
7 Database Mistakes YOU Are Making -- Linuxfest Northwest 20197 Database Mistakes YOU Are Making -- Linuxfest Northwest 2019
7 Database Mistakes YOU Are Making -- Linuxfest Northwest 2019
 
High Performance Mysql
High Performance MysqlHigh Performance Mysql
High Performance Mysql
 
Conquering "big data": An introduction to shard query
Conquering "big data": An introduction to shard queryConquering "big data": An introduction to shard query
Conquering "big data": An introduction to shard query
 
SPL_ALL_EN.pptx
SPL_ALL_EN.pptxSPL_ALL_EN.pptx
SPL_ALL_EN.pptx
 
NoSQL for great good [hanoi.rb talk]
NoSQL for great good [hanoi.rb talk]NoSQL for great good [hanoi.rb talk]
NoSQL for great good [hanoi.rb talk]
 
MySQL highav Availability
MySQL highav AvailabilityMySQL highav Availability
MySQL highav Availability
 
Revision
RevisionRevision
Revision
 
Quick & Easy SQL Tips
Quick & Easy SQL TipsQuick & Easy SQL Tips
Quick & Easy SQL Tips
 
White Paper for OMG! Identifying and Refactoring Common SQL...
White Paper for OMG! Identifying and Refactoring Common SQL...White Paper for OMG! Identifying and Refactoring Common SQL...
White Paper for OMG! Identifying and Refactoring Common SQL...
 
Tech Talk Series, Part 2: Why is sharding not smart to do in MySQL?
Tech Talk Series, Part 2: Why is sharding not smart to do in MySQL?Tech Talk Series, Part 2: Why is sharding not smart to do in MySQL?
Tech Talk Series, Part 2: Why is sharding not smart to do in MySQL?
 
Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...
Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...
Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...
 

More from Ortus Solutions, Corp

BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Secure your Secrets and Settings in ColdFusion
Secure your Secrets and Settings in ColdFusionSecure your Secrets and Settings in ColdFusion
Secure your Secrets and Settings in ColdFusionOrtus Solutions, Corp
 
Daniel Garcia ContentBox: CFSummit 2023
Daniel Garcia ContentBox: CFSummit 2023Daniel Garcia ContentBox: CFSummit 2023
Daniel Garcia ContentBox: CFSummit 2023Ortus Solutions, Corp
 
ITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdf
ITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdfITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdf
ITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdfOrtus Solutions, Corp
 
ITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdf
ITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdfITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdf
ITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdfOrtus Solutions, Corp
 
ITB_2023_The_Many_Layers_of_OAuth_Keith_Casey_.pdf
ITB_2023_The_Many_Layers_of_OAuth_Keith_Casey_.pdfITB_2023_The_Many_Layers_of_OAuth_Keith_Casey_.pdf
ITB_2023_The_Many_Layers_of_OAuth_Keith_Casey_.pdfOrtus Solutions, Corp
 
ITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdf
ITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdfITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdf
ITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdfOrtus Solutions, Corp
 
ITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdf
ITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdfITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdf
ITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdfOrtus Solutions, Corp
 
ITB_2023_25_Most_Dangerous_Software_Weaknesses_Pete_Freitag.pdf
ITB_2023_25_Most_Dangerous_Software_Weaknesses_Pete_Freitag.pdfITB_2023_25_Most_Dangerous_Software_Weaknesses_Pete_Freitag.pdf
ITB_2023_25_Most_Dangerous_Software_Weaknesses_Pete_Freitag.pdfOrtus Solutions, Corp
 
ITB_2023_Practical_AI_with_OpenAI_-_Grant_Copley_.pdf
ITB_2023_Practical_AI_with_OpenAI_-_Grant_Copley_.pdfITB_2023_Practical_AI_with_OpenAI_-_Grant_Copley_.pdf
ITB_2023_Practical_AI_with_OpenAI_-_Grant_Copley_.pdfOrtus Solutions, Corp
 
ITB_2023_When_Your_Applications_Work_As_a_Team_Nathaniel_Francis.pdf
ITB_2023_When_Your_Applications_Work_As_a_Team_Nathaniel_Francis.pdfITB_2023_When_Your_Applications_Work_As_a_Team_Nathaniel_Francis.pdf
ITB_2023_When_Your_Applications_Work_As_a_Team_Nathaniel_Francis.pdfOrtus Solutions, Corp
 
ITB_2023_Faster_Apps_That_Wont_Get_Crushed_Brian_Klaas.pdf
ITB_2023_Faster_Apps_That_Wont_Get_Crushed_Brian_Klaas.pdfITB_2023_Faster_Apps_That_Wont_Get_Crushed_Brian_Klaas.pdf
ITB_2023_Faster_Apps_That_Wont_Get_Crushed_Brian_Klaas.pdfOrtus Solutions, Corp
 
ITB_2023_Chatgpt_Box_Scott_Steinbeck.pdf
ITB_2023_Chatgpt_Box_Scott_Steinbeck.pdfITB_2023_Chatgpt_Box_Scott_Steinbeck.pdf
ITB_2023_Chatgpt_Box_Scott_Steinbeck.pdfOrtus Solutions, Corp
 
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdfITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdfOrtus Solutions, Corp
 
ITB_2023_Create_as_many_web_sites_or_web_apps_as_you_want_George_Murphy.pdf
ITB_2023_Create_as_many_web_sites_or_web_apps_as_you_want_George_Murphy.pdfITB_2023_Create_as_many_web_sites_or_web_apps_as_you_want_George_Murphy.pdf
ITB_2023_Create_as_many_web_sites_or_web_apps_as_you_want_George_Murphy.pdfOrtus Solutions, Corp
 
ITB2023 Developing for Performance - Denard Springle.pdf
ITB2023 Developing for Performance - Denard Springle.pdfITB2023 Developing for Performance - Denard Springle.pdf
ITB2023 Developing for Performance - Denard Springle.pdfOrtus Solutions, Corp
 

More from Ortus Solutions, Corp (20)

BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Ortus Government.pdf
Ortus Government.pdfOrtus Government.pdf
Ortus Government.pdf
 
Luis Majano The Battlefield ORM
Luis Majano The Battlefield ORMLuis Majano The Battlefield ORM
Luis Majano The Battlefield ORM
 
Brad Wood - CommandBox CLI
Brad Wood - CommandBox CLI Brad Wood - CommandBox CLI
Brad Wood - CommandBox CLI
 
Secure your Secrets and Settings in ColdFusion
Secure your Secrets and Settings in ColdFusionSecure your Secrets and Settings in ColdFusion
Secure your Secrets and Settings in ColdFusion
 
Daniel Garcia ContentBox: CFSummit 2023
Daniel Garcia ContentBox: CFSummit 2023Daniel Garcia ContentBox: CFSummit 2023
Daniel Garcia ContentBox: CFSummit 2023
 
ITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdf
ITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdfITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdf
ITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdf
 
ITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdf
ITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdfITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdf
ITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdf
 
ITB_2023_The_Many_Layers_of_OAuth_Keith_Casey_.pdf
ITB_2023_The_Many_Layers_of_OAuth_Keith_Casey_.pdfITB_2023_The_Many_Layers_of_OAuth_Keith_Casey_.pdf
ITB_2023_The_Many_Layers_of_OAuth_Keith_Casey_.pdf
 
ITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdf
ITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdfITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdf
ITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdf
 
ITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdf
ITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdfITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdf
ITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdf
 
ITB_2023_25_Most_Dangerous_Software_Weaknesses_Pete_Freitag.pdf
ITB_2023_25_Most_Dangerous_Software_Weaknesses_Pete_Freitag.pdfITB_2023_25_Most_Dangerous_Software_Weaknesses_Pete_Freitag.pdf
ITB_2023_25_Most_Dangerous_Software_Weaknesses_Pete_Freitag.pdf
 
ITB_2023_CBWire_v3_Grant_Copley.pdf
ITB_2023_CBWire_v3_Grant_Copley.pdfITB_2023_CBWire_v3_Grant_Copley.pdf
ITB_2023_CBWire_v3_Grant_Copley.pdf
 
ITB_2023_Practical_AI_with_OpenAI_-_Grant_Copley_.pdf
ITB_2023_Practical_AI_with_OpenAI_-_Grant_Copley_.pdfITB_2023_Practical_AI_with_OpenAI_-_Grant_Copley_.pdf
ITB_2023_Practical_AI_with_OpenAI_-_Grant_Copley_.pdf
 
ITB_2023_When_Your_Applications_Work_As_a_Team_Nathaniel_Francis.pdf
ITB_2023_When_Your_Applications_Work_As_a_Team_Nathaniel_Francis.pdfITB_2023_When_Your_Applications_Work_As_a_Team_Nathaniel_Francis.pdf
ITB_2023_When_Your_Applications_Work_As_a_Team_Nathaniel_Francis.pdf
 
ITB_2023_Faster_Apps_That_Wont_Get_Crushed_Brian_Klaas.pdf
ITB_2023_Faster_Apps_That_Wont_Get_Crushed_Brian_Klaas.pdfITB_2023_Faster_Apps_That_Wont_Get_Crushed_Brian_Klaas.pdf
ITB_2023_Faster_Apps_That_Wont_Get_Crushed_Brian_Klaas.pdf
 
ITB_2023_Chatgpt_Box_Scott_Steinbeck.pdf
ITB_2023_Chatgpt_Box_Scott_Steinbeck.pdfITB_2023_Chatgpt_Box_Scott_Steinbeck.pdf
ITB_2023_Chatgpt_Box_Scott_Steinbeck.pdf
 
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdfITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
 
ITB_2023_Create_as_many_web_sites_or_web_apps_as_you_want_George_Murphy.pdf
ITB_2023_Create_as_many_web_sites_or_web_apps_as_you_want_George_Murphy.pdfITB_2023_Create_as_many_web_sites_or_web_apps_as_you_want_George_Murphy.pdf
ITB_2023_Create_as_many_web_sites_or_web_apps_as_you_want_George_Murphy.pdf
 
ITB2023 Developing for Performance - Denard Springle.pdf
ITB2023 Developing for Performance - Denard Springle.pdfITB2023 Developing for Performance - Denard Springle.pdf
ITB2023 Developing for Performance - Denard Springle.pdf
 

Recently uploaded

Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
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
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
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
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

Golden Hammer - Shawn Oden

  • 1. THE GOLDEN HAMMERConfessions of a Recovering Database Abuser "I suppose it is tempting, if the only tool you have is a hammer, to treat everything as if it were a nail." - Abraham Maslow (1966)
  • 2. Who am I? Shawn Oden I started life as a pilot who became a flight instructor who was briefly an airline pilot before I accidentally switched into a ColdFusion developer who, by some fluke, morphed into a database developer who adventurously (and somewhat masochistically) decided to be a DBA. And that’s who I am today. Who knows what tomorrow may bring. • Microsoft Certified Professional: SQL Server • CompTIA Security+ • Adobe Certified ColdFusion Specialist • Adobe Certified ColdFusion MX 7 Developer • Macromedia Certified ColdFusion MX Developer @CodeFuMonkey codefumonkey@gmail.com https://www.codefumonkey.com Note: I am CodeFuMonkey, NOT ColdFuMonkeh, nor am I affiliated with monkehworks.com. I know that Mr. Gifford and I are easy to get mixed up, but the similarity of our noms de plume occurred many moons ago and was completely unintentional on my part. Sorry, Matt.
  • 3. First things first… ■ Rule #1:  DO NOT TEST THINGS IN A PRODUCTION DATABASE! • Trust me. Murphy’s Law is a real thing. ■ Rule #2: – DO NOT REPORT FROM A PRODUCTION DATABASE. • Set up a Reporting instance of your database. Your users will appreciate it. ■ Rule #3: – BACKUPS ARE WORTHLESS IF THEY AREN’T TESTED. • If you have a need to RESTORE a BACKUP, chances are it’s a bad day. • Test them before you need them. • Script the RESTOREs so you don’t have to dig into StackOverflow. ■ Rule #4: – WHEN IT COMES TO DATABASES, AS WITH MOST PROGRAMMING THINGS, THERE REALLY ARE FEW HARD AND FAST RULES. • It nearly always Depends. ■ Rule #5: – EXCEPT WHEN IT COMES TO TESTING THINGS IN PRODUCTION  DO NOT DO IT!
  • 4. Now that we’ve reviewed some basic rules, let’s talk about … • What is SQL? • Databases Are Complex. • What Bad Habits Did I Get Into? • SIDEBAR: JOINs • Some SQL Gotchas. • There’s Just So Many Things To Cover • Wrapping Up. For Now. Let’s jump in…
  • 5. What is SQL? According to Webster’s Dictionary: “SQL - /S Q L/ An industry-standard language for creating, updating and, querying relational database management systems.” According to Wikipedia: “SQL (/ˌɛsˌkjuːˈɛl/ S-Q-L or /ˈsiːkwəl/ "sequel“ [Structured Query Language]) is a domain-specific language used in programming and designed for managing data held in a relational database management system (RDBMS), or for stream processing in a relational data stream management system (RDSMS). It is particularly useful in handling structured data, i.e. data incorporating relations among entities and variables.” And the most important thing to take away from that is: “Do I pronounce it ‘ess-que-ell’ or ‘sequel’?” – Technically, it’s ‘ess-que-ell’, but I use both, depending on the context. In my opinion though, that’s kinda like asking a developer how to pronounce “.gif” or “JSON”.
  • 6. Clear as mud. So…What Is SQL? ■ SQL is a standard language you can use to talk to the server were the data is stored: ■ It is a “Declarative” language instead of an “Imperative” language. – This is a pretty significant paradigm shift from most programming languages. With SQL, Don’t Tell; Ask. ■ SQL is used to get information from your back-end system to be sent to the front-end for display. – The SQL language (and especially the proprietary implementations) have the ability to do much of your business logic, but that is likely better suited for your application. ■ DBMS engines are pretty smart. – They’re pretty good at figuring out what you want based on what you have, but they can’t read minds. Yet.
  • 7. Databases Are Complex ■ Your DBMS does a lot more than just hold data. ■ Your DBMS may have a fairly robust Security scheme for managing users or encrypting data. ■ Your DBMS likely has the capability for backing your data, or for providing for redundancy. ■ Your DBMS likely has its own dialect of SQL that provides for additional functionality not included in the SQL Standard. ■ Most SQL is simple CRUD. – “I can make this SQL thing work.” ■ My queries worked well for a few hundred rows. ■ They didn’t work so well for a few million rows.
  • 9. Typing Column Names Is Hard ■ What is happening? – We’re selecting all columns from the table. – This usually selects more data than is needed. ■ That causes the database to work harder ■ That causes the network to work harder ■ That causes the application to work harder – This may cause the proper index to be ignored. – This may cause a bad query plan to be generated. – If the underlying column name or order changes, your application might break ■ What should we do? – Only SELECT the columns that are needed. SELECT col1, col2, col3 FROM myTable SELECT * FROM …….
  • 10. I Only Need The First n Rows ■ What is happening? – When ColdFusion sends the query to the database, an instruction from the JDBC driver tells the database to stop processing and return records after MAXROWS records. ■ On the Application side, nothing will be noticed. ■ On the Database side, since this is an instruction from JDBC, the query may continue to process the total number of records from the SELECT. – This may cause the database to ignore the MAXROWS attribute, and process all rows. – This may cause an incorrect plan to be used. ■ What should we do? – This depends on the DBMS used. ■ SQL Server: SELECT TOP 42 col1 FROM myTable ■ MySQL: SELECT col1 FROM myTable LIMIT 42 <cfquery ……. maxrows=“42”> SELECT cols FROM myTable </cfquery>
  • 11. Who Was In Last? ■ What is happening? – This pattern has been used to get the id (autogenerated) of the last record inserted into the table. ■ Why is this bad? – This query seems to work fine on a single developer machine when that developer is the only one INSERTing data. However, this query can retrieve the wrong id if another INSERT happens between the two queries. ■ What should we do? – There are a number of different database-specific ways to query this id, but ColdFusion has a very simple built-in method: <cfquery name=“query1”> INSERT INTO myTable (name) VALUES (‘Bob’) </cfquery> <cfquery name=“LastInserted”> SELECT TOP 1 id FROM myTable ORDER BY InsertDate DESC </cfloop> <cfquery name=“query1” result=“myResult”> INSERT ……<cfquery> <cfoutput>#myResult.GENERATEDKEY#</cfoutput>
  • 12. Looping Over A Query ■ What is happening? – Every loop of the query is creating a new cfquery to get name from myTable1. ■ What should we do? – The same result can be accomplished with a single query and a proper WHERE filter. Then cfloop over the output rather than the query. ■ This would reduce expensive connections to the database and make the application faster. ■ Looping over a query will create a new database connection on each iteration. This can become very expensive and slow down or halt your application. <cfloop index=“i” from=“1” to=“42”> <cfquery name=“query1”> SELECT name FROM myTable1 WHERE id = #i# </cfquery> <cfoutput>#query1.name#</cfoutput><br> </cfloop>
  • 13. I Need To Use One Query For Data In Another Query ■ What is happening? – This is just another loop over a query. All negatives still apply. – The first query gets id from myTable1.That id is used to retrieve related records from myTable2. The records from myTable2 are displayed as a subsection of query1’s id. ■ This might be used for a nested list or hierarchal information. ■ What should we do? – More often than not, this can be accomplished with a proper SQL JOIN. <cfquery name=“query1”> SELECT id FROM myTable1 </cfquery> <cfoutput>#query1.id#</cfoutput><br> <cfoutput query=“query1”> <cfquery name=“query2”> SELECT col1 FROM myTable2 WHERE q1ID = #id# </cfquery> <cfoutput>#query2.col1#</cfoutput><br> </cfquery>
  • 14. SIDEBAR: SQL JOINS ■ What is a JOIN? – It is a way for SQL to relate one or more tables with each other. – The type of JOIN will determine the data available in the final product. ■ There are multiple types of SQL JOINs. A few are: – INNER JOIN – This will return only the records that are common between both named tables. – OUTER JOIN – This will return all records from one table and only those that are common from the second table. Unmatched rows will contain NULL values. • These can be either LEFT OUTER or RIGHT OUTER JOINs. – FULL JOIN – This will return all records from both tables, with matched data for matching rows and NULL data for unmatched rows. – CROSS JOIN – This will return all rows from one table matched to all rows of the second table. This is a CARTESIAN PRODUCT. NOTE: This list is not inclusive, and a ton of information is available online.
  • 16. SIDEBAR: SQL JOINS ■ My Personal View…. – The JOIN clause conditions are for linking tables together. – The WHERE clause is for filtering results of the whole query. SELECT table1.col1 AS t1Col1, table2.col1 AS t2Col1 FROM table1 INNER JOIN table2 ON table1.t2ID = table2.ID AND table1.t2ProductID = table2.ProductID AND table2.BuyerID = 42 WHERE table1.CustomerID = 4242 SELECT table1.col1 AS t1Col1, table2.col1 AS t2Col1 FROM table1, table2 WHERE table1.t2ID = table2.ID AND table1.t2ProductID = table2.ProductID AND table2.BuyerID = 42 AND table1.CustomerID = 4242 ■ ANSI 89 JOINs – PLEASE DON’T DO THIS. (ノಠ益ಠ)ノ彡┻━┻ – This is an older style of JOINing tables, and creates a Cartesian product before filtering the query results. – It has been deprecated.
  • 17. Lookout Below! SQL has some gotchas!
  • 18. My Queries Keep Blocking Each Other ■ The NOLOCK hint will fix that, right? – Yes, but No. – NOLOCK probably isn’t doing what you think it’s doing. ■ The NOLOCK hint functions similar to a READ UNCOMMITTED transaction lock. – This type of lock will allow for Dirty Reads of data. ■ This means that a record you just read under a NOLOCK hasn’t been committed to the database yet, and it may be rolled back. That means your data may not be accurate. ■ This could lead to Phantom Reads that give incorrect counts. ■ This should only be used on data that isn’t expected to change much. ■ This should also only be used on a SELECT statement. ■ NOLOCK doesn’t keep your query from blocking other queries. It just keeps other queries from blocking this one. – Note that Microsoft SQL Server default is READ COMMITTED.
  • 19. Data Type Conversion: 1 vs “1” ■ Will those convert to each other? – For these, Yes. For others, It Depends. ■ CFML is a dynamically typed language. – This often allows us to overlook implicit data type conversions. ■ Implicit Conversion happens in SQL, too. – Numbers can be converted to strings. Strings can sometimes be converted to numbers. Dates are sort of stored in the database as number-ish objects, but can’t be converted directly to an integer, but they can be converted to a string. – As with all things, there is some slight overhead, and some things can’t be converted to other things. – When JOINing, filtering with a WHERE, or any other type of comparison, it’s important to factor in the data type of the columns or variables you are trying to compare.
  • 20. Data Type Conversion: Can I …?
  • 21. Data Types: Character Types ■ Likely the most common types of data in your application. ■ Also the most easily abused through SQL injection, so pay attention to these. ■ Character datatypes are either fixed-width (char,nchar) or variable- width (varchar, nvarchar). ■ There are also text and ntext, but these have been deprecated. Use varchar(max) or nvarchar(max) instead. ■ Don’t use the Unicode types (nchar, nvarchar) unless you need them. If you are working with Internationalization, you’ll probably need them. Data Type n Actual Storage Size Maximum Value char(n) 0-8000 n bytes Fixed-width. Will pad empty strings to the left. nchar(n) 0-4000 n bytes Fixed-width Unicode. A Unicode character requires 2x storage space. varchar(n) 0-8000 n+2 bytes Variable-width. The value won’t pad extra characters. nvarchar(n) 0-4000 (n*2)+2 bytes Variable-width. varchar(max) Stores up to 2^31-1 bytes (~2GB) Normal up to 8000bytes, then stored in text.
  • 22. Data Types: Character Types (caution) ■ In this situation, if you don’t specify a length of the varchar (i.e. varchar(50)), the length will default to 1. CREATE TABLE t1 ( col1 varchar ) CREATE PROCEDURE mySproc @myvar varchar … DECLARE @val1 varchar … ■ These would also default to a length of 1. SELECT CAST(col1 AS varchar) FROM…. ■ In a Stored Procedure, not declaring a length on a varchar will default it to 30 bytes. Not specifying a length for a char or varchar may lead to unintentional (bad) or silent (worse) truncation that can be very hard to troubleshoot.
  • 23. Data Types: Character Types (more caution) ■ If you are trying to compare a fixed-width column, make sure that you provide the proper width in your comparison. ■ In the above example, if x is a 5-character char data type, then it will never be equal to the 3-character sting “foo”. SELECT … FROM … WHERE x = ‘foo’ SELECT … FROM … WHERE x = ‘ foo’ ■ The above may be what you want. SELECT … FROM … WHERE x = ‘ foo ’ ■ That would also work. Usually. ■ The SQL Standard says that when two strings are compared, their lengths must be equal. A string with trailing empty spaces will have those empty spaces ignored.
  • 24. Data Types: Exact Numbers - Integers ■ Exact numbers will always be represented completely. ■ 1 + 2 = 3 ■ An integer datatype will be a whole number. When coercing a decimal to an integer, watch out for rounding or truncation. Data Type Storage Size Minimum Value Maximum Value tinyint 1 byte 0 255 smallint 2 bytes -32,768 32,767 int 4 bytes -2,147,483,648 2,147,483,674 bigint 8 bytes -9,223,372,036,854,775,808 9,223,372,036,854,775,807
  • 25. Data Types: Exact Numbers - Decimals ■ A decimal type is still an exact representation of a number. ■ .1 + .2 = .3 ■ Decimals are declared like decimal(P,S), where P is Precision and S is Scale. – When declaring a decimal, the default precision is 38 and default scale is 0. ■ Numeric and Decimal datatypes are the same thing. ■ Converting from decimal/numeric to float/real can cause some loss of precision. Data Type Storage Size Decimal(1-9) 5 bytes Decimal(10-19) 9 bytes Decimal(20-28) 13 bytes Decimal(29-38) 17 bytes
  • 26. Data Types: Approximate Numbers ■ These are a little more challenging. They aren’t always represented completely, and some rounding issues become apparent. ■ So .1 + .2 = .3, right? NOPE. It’s 0.30000000000000004. ■ (ノಠ益ಠ)ノ彡┻━┻ ■ Floats and Reals can store extremely large or small numbers, but don’t use them for precise calculations. ■ The real datatype is essentially a float(24). Data Type n Storage Size Precision Minimum Value Maximum Value Float(n) 1-24 4 bytes 7 digits -1.79E + 308 1.79E + 308 25-53 2 bytes 15 digits -1.79E + 308 1.79E + 308 real n/a 4 bytes 7 digits -3.40E + 38 3.40E + 38
  • 27. Data Types: Dates. My Favorite. ■ Inside a database, a date is not what you see on your screen. – It is usually stored as an integer or other representation of days and/or seconds since the system’s epoch, which may be: ■ 1 JAN 1900 for SQL Server and other Microsoft products ■ 1 JAN 1970 for most Unix-ish systems ■ 31 DEC 1969 for some systems. ■ Sometimes…. (ノಠ益ಠ)ノ彡┻━┻ ┻━┻ ┻━┻ ■ Dates and Date Math will drive you crazy. – I hate dates. ■ However, PLEASE PLEASE PLEASE store a date as a date object and not as a string. – It is much more involved to try to add a day to a string representation of a date. – It is much more involved to try to find the difference of two dates when they are strings – It’s much more involved to do X when dates are converted to strings. ■ This holds true for pretty much any language.
  • 28. I Thought We Already Played Y2K! ■ In the lead-up to the turn of the century, some very smart people worked very hard to ensure that the vast majority of the population had no idea of the scope of they Y2K problem. – We survived, but there are still systems using 2-digit years. – We dodged one bullet, but we’ve got another one coming up. At 03:14:07 UTC on the morning of 19 January 2038 we will exceed the number of seconds able to be represented by a signed 32- bit integer. – Did you ever think that 2.1 BILLION seconds would run out that fast?
  • 29. Even More Things to Think About ■ “RBAR” (pronounced “re bar”): Row By Agonizing Row - Jeff Moden – SQL is designed to be Set-Based. ■ The engine has to work harder when it does a large operation involving multiple rows if it’s told to do them one at a time. ■ https://sqlstudies.com/2016/08/17/rbar-vs-batch/ – Functions in the query can also cause RBAR. – RBAR IS SLOW ■ CTE: Common Table Expression – Very handy for building up a data set into a temporary table for use within the main query – Can only be used with SELECT, INSERT, UPDATE, DELETE – Must be the first statement in a batch. (hint: “;”) ■ Window Functions – Very good way to aggregate data inside of a specific window of data within your query.
  • 30. Even More “More Things to Think About” ■ BETWEEN – If you need to find results that fall between two points, SQL does have a BETWEEN comparison. However, it’s ambiguous. – In SQL Server, BETWEEN is INCLUSIVE of both sides. • ...WHERE x BETWEEN 1 AND 4 will return results that match 1,2,3 and 4. • This can be tricky with Dates. How do you return all days in January? • It’s usually better to be EXPLICIT. Use y >=x AND y<=z instead. ■ The more you say, the better. – Be explicit. Don’t use shorthand. ■ What does DATEPART(Y, getDate()) return? – Hint: DATEPART(year, getDate()) might return something different.
  • 31. Let Me Explain… No, There Is Too Much… Let Me Sum Up…
  • 32. ■ SQL IS HARD. ■ SQL has become a lot more capable since I started using it. – It gets more complicated every year. ■ SQL is a completely different language, and to do things well requires some deep study of what is happening. ■ Be curious. ■ I have barely scratched the surface of the things I’ve learned.
  • 33. Resources and Other Things to Play With ■ There’s always RTFM: – https://docs.microsoft.com/en-us/sql/?view=sql-server-ver15 – https://dev.mysql.com/doc/refman/8.0/en/ – Just about every major database system has fairly thorough documentation online. ■ If you want a way to play with different flavors of SQL without installing them: – http://sqlfiddle.com/ < U.S.-Based • Has engines for MySQL, Oracle, PostgreSQL, SQLite and MS SQL Server – https://dbfiddle.uk/ < U.K.-Based • Has engines for many more databases • Db2, Firebird, MariaDB, MySQL, Oracle, PostgreSQL, SQLite and MS SQL Server • Because this one is U.K.-based, default date formats are dd-mm-yyyy. ■ If you want to practice some querying: – SQL Murder Mystery is excellent. – https://mystery.knightlab.com/ ■ Who should you follow: – Aaron Bertrand https://sqlblog.org/bad-habits/ – Brent Ozar https://www.brentozar.com/blog/ – Kendra Little https://littlekendra.com/ – Kevin Kline https://kevinekline.com/ – #SQLFamily on Twitter https://twitter.com/search?q=%23sqlfamily&src=typed_query – And so many others….
  • 34. But If You Take Nothing Else Away From This Talk… DO NOT TEST THINGS IN A PRODUCTION DATABASE!
  • 35. THANK YOU FOR LISTENING TO ME JABBER FOR A BIT Shawn Oden @CodeFuMonkey codefumonkey@gmail.com https://www.codefumonkey.com
  • 36. I Would Also Like To Extend A Big Thank You To Ortus Solutions for Into The Box and Everything Else That They Do!

Editor's Notes

  1. The Golden Hammer All I knew was a how to use a hammer. And there were a lot of nails. Maybe some screws, too.
  2. My story is a bit long and not very well suited for this platform. I am self-taught, which is how I learned these bad habits and how I later learned to fix them.
  3. It needs to be said again: DO NOT TEST THINGS IN PRODUCTION!
  4. What is SQL? Working with Databases is a very large topic. What sort of bad habits did I need to unlearn. My world changed when I learned how to work with JOINs.
  5. SQL: What is it? https://i.imgur.com/NtGaNA8.png https://medium.com/tableplus/how-to-pronounce-sql-properly-s-q-l-or-sequel-7203a5185676
  6. By itself, SQL isn’t necessarily a programming language, but it does have many capabilities of a programming language. SQL isn’t Turing Complete (can compute the answer to a logical problem), but Microsoft’s T-SQL and Oracle’s PL-SQL may be. Declarative vs Imperative: This is one of the biggest mind leaps I had to make. With most programming languages, you tell the computer specifically how to do something. With SQL, you tell it what you want it to do and it figures out how to do it. You learn how to ask it for the information you want. The DBMS will figure out the best way to get it to you. “I want a PB&J.” vs “First you take the bread out of the cabinet……” Back End The SQL language (and especially the proprietary implementations) have the ability to do much of your business logic, but that is likely better suited for your application. It’s very good for data aggregation, but not so much for text manipulation. Smart Databases You ask the database for what you want, and it figures out how to get it. Indexes, Statistics, Etc. A database can only give you the best information it knows how to give you. If you ask it for garbage, or let it hold onto bad information, it may not give you exactly what you want, or it may do so inefficiently.
  7. A database is not just a data storage space I work in a secure environment, and data protection is taken very seriously. My database provides additional layers for me to protect that data. If you care about losing your data, a good backup plan (including test restores) is essential. Most of the larger database manufacturers have their own dialect of the SQL Standard. Oracle, MySQL, PostgreS, and Microsoft T-SQL are all slightly different. My experience is primarily in Microsoft SQL Server, and that’s what I’ll focus on, but much of the concepts transfer across the different brands. Most SQL is simple CRUD Most applications don’t need much more than CRUD(CREATE, READ, UPDATE, DELETE). It’s common to just think, it’ll be simple to implement this. - This is where I really started to get myself into trouble. - I’m a self-taught developer. I never had a problem picking up a book and figuring something out. So I spent years working with bad habits I picked up because “they just worked”. - Once I started using larger databases, my bad habits became more apparent. A few ms here and there adds up.
  8. I made some mistakes. But I didn’t know better. I learned.
  9. Typing out Column Names is so much extra typing.
  10. Sometimes you only want to SELECT a certain number of rows. ColdFusion’s cfquery has a maxrows attribute to limit the rows returned to the query. What’s happening? When ColdFusion sends the query to the database, an instruction from the JDBC driver tells the database to stop processing and return records after MAXROWS records. On the Application side, nothing will be noticed. On the Database side, since this is an instruction from JDBC, the query may continue to process the total number of records from the SELECT. This may cause the database to ignore the MAXROWS attribute, and process all rows. This may cause an incorrect plan to be used. What should we do? This depends on the DBMS used. SQL Server: SELECT TOP 42 col1 FROM myTable MySQL: SELECT col1 FROM myTable LIMIT 42 Also, retrieving any specific first rows relies on some sort of ORDER BY. If there’s no ORDER, there is no guarantee which rows will be returned. NOTE: For a long time, I’ve had the belief that the database server will continue to process rows without paying attention to the cfquery MAXROWS attribute. I don’t know if this has been changed in more recent versions, but my preliminary testing seems to indicate that the behavior is the same. This belief was long ago confirmed by an old blogs from Ray Camden (https://web.archive.org/web/20090815105006/http://www.coldfusionjedi.com/index.cfm/2009/8/12/MAXROWS-Attribute--Not-as-good-as-I-thought) and Jochem van Dieten (https://web.archive.org/web/20160529115330/http://jochem.vandieten.net/2008/12/17/does-cfquerys-maxrows-work-on-the-coldfusion-side-or-the-database-side/). I need to do further verification to make sure my assumption still holds true.
  11. It’s very common to need to find the Last Inserted Record. If your database is used by more than one user at a time, it is very possible to get the incorrect Last Record. Rather than trying to SELECT it back from the database, just use the data the INSERT query provided you, or use a cfquery result attribute and the GENERATEDKEY metadata.
  12. Any time I see a loop around a query, I look for a way to optimize that code to minimize database connections.
  13. This sort of pattern is often used to create a hierarchal layout. This also results in multiple trips to the database, and can cause a significant impact on application performance and reliability. A SQL JOIN is usually a much better option.
  14. Learning proper JOINs is probably one of the most important skills anyone working with a database can learn.
  15. Learning proper JOINs is probably one of the most important skills anyone working with a database can learn.
  16. It is just my personal view of where to set up joins. For most JOIN types, there’s only the requirement to have 1 condition in the ON statement. I prefer to put any conditions that the table will JOIN on into the ON clause. In my conception, it creates smaller JOIN sets before it continues to the next JOIN or operation. Usually the SQL Optimizer is smart enough to figure out the best way to put the tables together. Regarding ANSI 89 or comma-delimited JOINs, these are an old style. For now, they do still work, but they will probably annoy most SQL developers. The initial datasets are conceptually large (but the Optimizer may again fix it). There’s just no reason to continue to use that style. And since it has been deprecated, it would probably be worth refactoring to proper JOIN syntax if they are encountered in legacy code.
  17. Also note that while the WITH part of the WITH (NOLOCK) hint can be excluded now. But it has been deprecated by Microsoft and can be removed from the language. https://www.sqlshack.com/understanding-impact-clr-strict-security-configuration-setting-sql-server-2017/
  18. Pay attention to data types. Some don’t play nicely together.
  19. This is T-SQL. Other flavors of SQL (like MySQL, PostgreSQL or Oracle PL-SQL) may have different conversions. T-SQL Data type Precedence https://docs.microsoft.com/en-us/sql/t-sql/data-types/data-type-precedence-transact-sql?view=sql-server-ver15
  20. https://docs.microsoft.com/en-us/sql/t-sql/data-types/data-types-transact-sql?view=sql-server-ver15 https://www.techrepublic.com/blog/10-things/10-plus-common-questions-about-sql-server-data-types/ Only use varchar(max) if necessary. It requires a lot of storage space, even if it isn’t used. One of the best uses of char data type I’ve come across is when I’ve exported a column to a fixed-width delimited flat file. I could always be assured that the data for a specific column began and ended in the right position. Also note that, when defining the size of char(n) and varchar(n), the n isn’t the number of characters that will fit in the data type. It is the number of bytes. https://docs.microsoft.com/en-us/sql/t-sql/data-types/char-and-varchar-transact-sql?view=sql-server-ver15 If you use char or varchar, we recommend to: Use char when the sizes of the column data entries are consistent. Use varchar when the sizes of the column data entries vary considerably. Use varchar(max) when the sizes of the column data entries vary considerably, and the string length might exceed 8,000 bytes. Warning Each non-null varchar(max) or nvarchar(max) column requires 24 bytes of additional fixed allocation which counts against the 8,060 byte row limit during a sort operation. This can create an implicit limit to the number of non-null varchar(max) or nvarchar(max) columns that can be created in a table. No special error is provided when the table is created (beyond the usual warning that the maximum row size exceeds the allowed maximum of 8,060 bytes) or at the time of data insertion. This large row size can cause errors (such as error 512) during some normal operations, such as a clustered index key update, or sorts of the full column set, which will only occur while performing an operation.
  21. Always declare a length when declaring a varchar. https://docs.microsoft.com/en-us/sql/t-sql/data-types/char-and-varchar-transact-sql?redirectedfrom=MSDN&view=sql-server-ver15
  22. https://support.microsoft.com/en-us/help/316626/inf-how-sql-server-compares-strings-with-trailing-spaces SQL Server follows the ANSI/ISO SQL-92 specification (Section 8.2, <Comparison Predicate>, General rules #3) on how to compare strings with spaces. The ANSI standard requires padding for the character strings used in comparisons so that their lengths match before comparing them. The padding directly affects the semantics of WHERE and HAVING clause predicates and other Transact-SQL string comparisons. For example, Transact-SQL considers the strings 'abc' and 'abc ' to be equivalent for most comparison operations. The only exception to this rule is the LIKE predicate. When the right side of a LIKE predicate expression features a value with a trailing space, SQL Server does not pad the two values to the same length before the comparison occurs. Because the purpose of the LIKE predicate, by definition, is to facilitate pattern searches rather than simple string equality tests, this does not violate the section of the ANSI SQL-92 specification mentioned earlier.
  23. https://docs.microsoft.com/en-us/sql/t-sql/data-types/data-types-transact-sql?view=sql-server-ver15 https://www.techrepublic.com/blog/10-things/10-plus-common-questions-about-sql-server-data-types/ Make sure you use the right type.
  24. https://docs.microsoft.com/en-us/sql/t-sql/data-types/data-types-transact-sql?view=sql-server-ver15 https://www.techrepublic.com/blog/10-things/10-plus-common-questions-about-sql-server-data-types/ Precision, Scale and Length https://docs.microsoft.com/en-us/sql/t-sql/data-types/precision-scale-and-length-transact-sql?view=sql-server-ver15 Precision = number of digits Scale = number of digits to the right of the decimal point Note: Precision includes the Scale. 123.45 has a Precision of 5 with a Scale of 2 SQL Server >> default max Precision is 38. Default Scale is 0. MySQL >> default max Precision is 65, default 10. Max Scale is 30, default 0.
  25. Basically Floating Point numbers are related to the way computer memory is used. They can represent pretty massive numbers, and as such, exact precision becomes less important. Any time a float is converted to an integer, the value will be truncated. https://floating-point-gui.de/formats/fp/ https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html https://docs.microsoft.com/en-us/sql/t-sql/data-types/float-and-real-transact-sql?view=sql-server-ver15
  26. Pay attention to data types. Some don’t play nicely together. The default TIME for a date object with no time is 00:00:00. The default DATE for a date object with no date is 1 JAN 1900. ISO 8601 Date Formatting - Unambiguous https://www.iso.org/iso-8601-date-and-time-format.html Is 1/2/2020 January 2 or is it February 1. It Depends. With ISO 8601, all ambiguity is taken out of the picture by specifying format as yyyy-mm-dd or 2020-01-02 is January 2nd.
  27. Computers around the world were going to be very unhappy. Not to be Doom and Gloom, but we’re closer to January 2038 than we are to January 2000.
  28. RBAR vs BATCH https://sqlstudies.com/2016/08/17/rbar-vs-batch/ CTE https://docs.microsoft.com/en-us/sql/t-sql/queries/with-common-table-expression-transact-sql?view=sql-server-ver15 Not available in MySQL until Version 8. Window Functions: https://www.red-gate.com/simple-talk/sql/t-sql-programming/introduction-to-t-sql-window-functions/ Not available in MySQL until Version 8.
  29. BETWEEN When trying to find all dates in a month, it’s better to use an explicit range than it is to use BETWEEN. It gives the developer a better sense of what is being accomplished . SHORTHAND “Y” isn’t “YEAR”. It’s “DAYOFYEAR”, which is completely different. And it doesn’t really save that much typing. Again, as with most code, it’s better to be explicit. Write code for future developers. That may also be you in 6 months trying to figure out what you meant.
  30. SQL is hard. So many new features have been added since SQL 2000. CTEs and Window Functions are two of my favorites. The servers are just so much more efficient. Storage has become cheap. This allows for more data. Which requires different ways of thinking about your data. SQL is a common language that developers need to know. The need to know SQL is kind of like the need to know CSS or Javascript It’s not difficult to know enough to get the job done But knowing a lot can let you do things that you didn’t know were possible. Knowing a lot about SQL can let you see things that you didn’t know were wrong. The database might be slow because it’s being told to run that way. Be curious. - You learn best when you learn about things you WANT to know. But be prepared for the outcome if you let other people know about your curiosity. Sometimes if your boss learns that you have been talking with your VB6 developer about a business-critical application, you find yourself being the person who knows the most about that application when said VB6 dev leaves. Welcome to your new job as a VB6 Developer. Or, one day you wake up and find our you’re the new DBA. There is so much more to learn.
  31. Microsoft itself has good documentation on SQL Server – Books Online (BOL). Other systems do, too. There are tons of tools to play with SQL. SQL Murder Mystery is a lot of fun, while teaching some good techniques for getting at data. Aaron Bertrand’s “Bad Habits” series of blog posts should be required reading for anyone who touches a database. He also has some excellent articles about the usefulness of Date Dimensions / Calendar Tables. Brent Ozar has some fantastic tools for anyone who finds themselves in the position of DBAing. Kendra Little has an older, but still very useful podcast – “Ask The DBA” The SQL Family (or the community of SQL Server DBAs/Developers) is more geared to Microsoft SQL Server, but is an extremely helpful and friendly community. As far as development communities go, I’ve found this one to be similar to the reception from the ColdFusion community. Yesterday, Charlie Arehart mentioned several really good tools to check out.
  32. It needs to be said again: DO NOT TEST THINGS IN PRODUCTION!
  33. Thank you, participants.
  34. Thank you, Ortus!