Problems displaying this newsletter? View online.
Database Weekly
The Complete Weekly Roundup of SQL Server News
Hand-picked content to sharpen your professional edge
Editorial
 

In Praise of User-Defined Datatypes

User-defined datatype aliases assist in allowing clear readable code. Without them, you can still be consistent in your naming of a column, parameter or variable as 'price', but if you use, for example, a datatype called 'price', then your naming can be used to explain more about the way the column, parameter or variable is being used.

When used consistently, they help you to follow the lineage and flow of data through that rats-nest of procedures, functions and tables. You can categorise data. You can, if so requested, provide information about where sensitive information is being processed or stored and whether it is being properly curated. You can attach extended properties to them to further document their use.

They can also provide the means to discourage bad data, because you can use them to create data 'domains' that tie down specific application data, such as a postal code, as closely as possible to a definition. A date, for example, can be a wide range of values, whereas a date of birth has certain restrictions on it unless you are Methuselah or Count Dracula. An account code, an order code or a part number may all be stored as varchars but will have their own divergent rules and defaults.

We used to create data domains in Transact-SQL by binding types to Rules and Defaults (the similarly named 'default constraint' is restricted to columns). From 2005 onwards, both rules and defaults have been threatened with removal from SQL Server. Many of us still look at them longingly, as they languish with rather severe notices warning you not to use them. They are unloved because they are not in the SQL Standard, but part of Transact SQL as devised by Sybase before the ANSI SQL Standard came into being. However, if you're a SQL Purist, there are several other useful features that you'd have to jettison too.

You can argue that no domain datatype, such as 'product cost', will be in more than one table, so that it is enough to use table based NOT NULL constraints, CHECK constraints and DEFAULT constraints. The table, you could argue, defines the data domain. Well, no, not just because these are attributes, not entities, but because we also use temporary tables and table variables that need to be consistent. We have functions, batches and procedures that require parameters and that produce results that must be consistent too.

Of course, Rules have limitations. Since they aren't table-scoped, you can't use them to compare columns on a table, like you can with a CHECK constraint. Also, a rule is only checked when data is inserted or updated and can't check on existing data in a table. You can't bind a rule to a textntextimagevarchar(max)nvarchar(max)varbinary(max)xmlCLR user-defined type, or timestamp column. However, you still have constraints for doing this sort of task.

User-defined datatypes are still smiled-upon by Microsoft and while they deliver a great deal of value even without the use of Rules and Defaults, perhaps a reprieve for these two bad-boys wouldn't hurt, after 15 years on deprecation-row.

Phil Factor

Join the debate, and respond to the editorial on the forums

 
Redgate SQL Compare
The Weekly News
All the headlines and interesting SQL Server information that we've collected over the past week, and sometimes even a few repeats if we think they fit.
Vendors/3rd Party Products

Deployment Suite for Oracle: What’s New?

Stephanie Herr describes the new features in the Deployment Suite for Oracle that will help you automate your database releases safely, on Linux or Windows.

The Dangers of using Float or Real Datatypes

Floating point datatypes accommodate very big numbers but sacrifice precision. They are handy for some types of scientific calculations, but are dangerous when used more widely, because they can introduce big rounding errors.

Changing SET options in a Procedure or Trigger leads to Recompilation (PE012)

Phil Factor delves into SQL Prompt's performance rule, PE012, which will advise you if it detects the use of the SET statements within a stored procedure or trigger, which might cause unnecessary recompilations, though the issue extends to other types of batches.

AI/Machine Learning/Cognitive Services

Comparing Azure Machine Learning and Azure Databricks

In this post, we will discuss the strengths and capabilities of each service and why you might choose one over the other for all or part of your machine learning workflow.

SQL Server Machine Learning 2019: Working with Security Changes

SQL Server Machine Learning allows you to run R and Python scripts from SQL Server. When SQL Server 2019 was released, Microsoft enhanced the security for this functionality, but it caused some existing code writing to the file system to to break. In this article, Dennes Torres explains the security enhancement and describes three ways to work with it.

Azure DevOps

Use PowerShell to consume your Azure CLI DevOps result set

Having used Azure CLI to query Azure DevOps to obtain a resultset containing useful information on builds, releases, and so on, it is likely that you will want to consume these results in PowerShell so that you can build upon them. I thought this would be an easy thing to do, but..no.

Conferences, Classes, Events, and Webinars

The evolution of database development and administration

Join Kendra Little to discuss the key findings from Redgate’s 2020 State of Database DevOps Report. The survey received input from more than two thousand database professionals worldwide, providing insights from changing trends and shifting perceptions to deployment patterns.

DMO/SMO/Powershell

Handling unicode in powershell

I had the need to pull specific revisions of files out of a git repository, save those files, and then execute the contents. This all worked fine until it didn't. I received some complaints that unicode characters in the files we getting mangled, and sure enough they were. But why? In this post I'll explain what happened to me, and ways you can avoid it yourself.

Data Access / ORMs

Why I Support Code Automation Tools like ORMs

Whether we’re talking nHibernate, Linq, or Entity Framework, the degree of loathing for these tools by most DBAs is really hard to measure. Yet, I’ve come to believe that code generation tools are a very important part of what we do. Further, that they are not evil, or wrong, or bad.

Data Mining / Data Analysis

The Importance of 0 in Regressions

One of the worst things we can do as data analysts is to interpret a regression line as the most important thing on a visual. The important thing here is the per-state set of data points, but our eyes are drawn to the line. The line mentally replaces the data, but in doing so, we lose the noise. And boy, is there a lot of noise.

Redgate SQL Compare
Data Visualisation

What is a bar chart?

A thorough examination of the bar chart with tips on how to design nice ones.

DevOps and Continuous Delivery (CI/CD)

How SQL Server Professionals can benefit from using version control

It's not only for DevOps-related best practices.

Build your DevOps business case with industry insights

With over 2000 participants from every industry sector across the globe, the State of Database DevOps report will help shape the business case of any team looking to implement or improve their approach to database DevOps, no matter the platform they choose to work with. Including a foreword from Kellyn Pot’Vin-Gorman, Customer Success Engineer at Microsoft, discover the landscape of database DevOps for 2020.

HA/DR/Always On/Clustering

Significant SQL Server 2019 licensing changes

In SQL Server 2019 there have been some big licensing changes about what you can and can’t do on a passive fail-over instance. Especially if you have Software Assurance.

Different Ways to Monitor SQL Server AlwaysOn Availability Groups

The various ways to do it, using either AlwaysOn Monitoring dashboard in SQL Server Management Studio or Performance Monitor counters.

Hardware

Storage 101: Understanding the Hard-Disk Drive

In this article in the series, Robert Sheldon provides a deep dive into HDDs.

Performance Tuning SQL Server

Is MAXDOP Configured Correctly?

Max degree of parallelism (MAXDOP) is a setting in SQL Server that controls how many processors may be used for parallel plan execution. Parallel plan execution is good—it lets SQL Server make the best use of all those processors in modern servers. However, MAXDOP can be configured incorrectly. Too much or too little parallelism can negatively impact server performance.

Removing ad hoc plans from Query Store

Jeff Iannucci shares a little something for those of you who don’t want Query Store drowning in all your ad hoc nonsense.

Indexed View Maintenance Is Only As Bad As Your Indexes

In some cases locks are serializable, and if you don’t maintain your indexes you may find run-of-the-mill modifications taking quite a long time.

Signs Your Execution Plan Is Lying To You

Erik Darling presents a series of videos tackling each of the signs that your execution plan isn't revealing the whole truth.

PowerPivot/PowerQuery/PowerBI

Relationships in Power BI and Tabular models

This article describes the types of relationships available in Power BI and Analysis Services, clarifying the differences in cardinality and filter propagation of physical relationships.

Power BI Query Performance & Query Diagnostics

This post demonstrates how the order of steps added to a query can make a big performance difference and drastically effect the number of steps generated by the designer. I’ll demonstrate how to use the new query Diagnostics tools to compare and understand query performance.

Make Your Power BI Report Run Faster By Showing The Same Data In Fewer Visuals

Do you have a Power BI report that has a row of card visuals on it? It’s a very common thing to do, but if your report is too slow to render you may find that a design like this is part of the problem.

Power Apps: Read-Only Data Source with Azure SQL Database

As someone who enjoys creating unique content in Power BI that’s always “one step away from useful” and not what Power BI was intended for, I now feel like I’ve missed out on a few years’ worth of opportunities. I should have started learning Power Apps long ago.

Power BI Report Books

Management has requested an easy way to view a subset of strategic reports located in different Power BI workspaces. You can ask the users to mark reports and dashboards as favorites so they can access pertinent content in the Favorites menu, but you’re looking for an easier configuration, such as to create a book of reports with a built-in navigation that organizes reports in groups.

Using Power Apps in Power BI reports: Enabling writeback

The Power Apps visual is a powerful tool for adding writeback and other functionality from Power Apps into Power BI reports. It allows users to take action directly from Power BI reports and update the data in real time.

Professional Development

What and who is IT community? What does it take to be part?

Tomaz Kastrun reports on a worrying trends in the IT community, including a decline in awareness of how much community is worth, and a decline in respect for community contributions.

Reporting Services

Using Google Chrome with SSRS

Wayne Sheffield explains a couple of potential issues when using Google Chrome with SSRS reports: constant log in prompts to the SSRS server, and the infamous Kerberos Double-Hop.

SQL Server Security and Auditing

How to connect a Database User to a Login

You are asked to provide information about logins and database users, but the login name does not match the name of the database user account.

Extended Events: Database Auditing

Extended Events can do things that simply are not possible with Profiler and another example comes from the stack of audit events that exist only in Extended Events. One...

Software Development

3 things that will make or break your project

YAGNI, KISS, DDD and unit testing. Wait, that's four!

Making your monolith more reliable

When and why to choose monolithic architecture is usually a matter of what works best for each business. Whatever the reason for using monolithic services, you still have to support them. They do, however, bring their own reliability and scaling challenges, and that’s what we’ll tackle in this post.

T-SQL

Set a variable and update a column at the same time

Kenneth Fisher discovers a weird option for the UPDATE command in a stack overflow answer

Case Study: Slow Garbage Collection

A procedure populates a temp table with the key values, which are then used to delete from the related tables, then delete from the primary table. However, the query populating our temp table was taking far too long, 84 seconds.

T-SQL Tuesday #123: Summary of Life Hacks

Jess Pomfret rounds up all the suggested SSMS hacks, time management skills, useful tools and more.

Modernizing Your T-SQL: String Aggregation

SQL Server 2016 gave us the STRING_SPLIT() function, but what about the reverse – compiling a set of values into one delimited string? We only had to wait 15 months for the release of SQL Server 2017, and the STRING_AGG() function.

Recommended SQL Server Books, 2020 Edition

If you’re the kind of person who likes to read books, Brent suggests a few that he thinks would expand your SQL horizons.

WHERE GETDATE() BETWEEN StartDate AND EndDate Is Hard to Tune.

If you frequently need to pull all of the memberships that were active on a specific date, that’s where performance tuning gets hard. You don’t know the UserId, and even worse, you can’t predict the date/time you’re looking up, or if it’s always Right Now.

Identifying the Physical Location of a Row

Occasionally you might need to know the physical location of a row stored in SQL Server. The code in this post uses the undocumented feature, %%PHYSLOC%%, which returns a binary representation in hexadecimal of the location of each row returned in a SELECT statement.

Columns That Share Ordering

Sorting data requires memory, and Sort operators particularly may ask for quite a bit of memory. Why? Because all the columns you’re selecting, need to to be sorted by the column in the ORDER BY.

A gotcha when upgrading to SQL Server 2019

In SQL Server 2017, there is still a value for password in sys.syslogins, but in SQL Server 2019 it is now null. Taryn Pratt explains how this 'gotcha' caused problems during a SQL Server 2019 upgrade.

Using sys.dm_exec_describe_first_result_set_for_object. The Hows, Whys and Wherefores

The sys.dm_exec_describe_first_result_set_for_object() DMF takes as its parameter the object_id of a procedure or trigger and describes the first result metadata for the module with that ID. Phil Factor explains why a developer might find this handy.

Grappling with sp_describe_undeclared_parameters(). The Hows, Whys and Wherefores

sp_describe_undeclared_parameters() promises a great deal, but delivers less. It was added mostly for executing application queries via sp_prepare using a TDS link, but has several quirks and restrictions that rather spoils its more general use.

Avoid using constants in an ORDER BY clause

Phil Factor explains why an ORDER BY clause should always specify the sort columns using their names, or aliases, rather than using an integer to specify the position of a column in the SELECT list.

Virtualization and Containers/Kubernetes

Understanding the Kubernetes Deployment of a SQL Server Big Data Cluster

Azure Kubernetes Services makes Deploying a SQL Server Big Data Cluster is a very simple process but you need some understanding of the the various Kubernetes Pods and Docker Containers created as a result.

 
RSS FeedTwitter
This email has been sent to {email}. To be removed from this list, please click here. If you have any problems leaving the list, please contact the webmaster@sqlservercentral.com. This newsletter was sent to you because you signed up at SQLServerCentral.com. Note: This is not the SQLServerCentral.com daily newsletter list, and unsubscribing to this newsletter will not stop you receiving the SQL Server Central daily newsletters. If you want to be removed from that list, you can follow the instructions on the daily newsletter.
©2019 Redgate Software Ltd, Newnham House, Cambridge Business Park, Cambridge, CB4 0WZ, United Kingdom. All rights reserved.
webmaster@sqlservercentral.com

 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -