SQLServerCentral - www.sqlservercentral.com

A community of more than 1,600,000 database professionals and growing

Featured Contents

Featured Script

The Voice of the DBA

Give Up on Natural Primary Keys

There is plenty of debate over how to design your database. At SQLServerCentral we have a Stairway Series as well as a few articles that cover design topics. I think it's important for anyone that builds tables to spend some time learning what others have done and understand the pros and cons of making different choices. It does often become hard to change designs once they are in use, so trying to choose a good entity design early is important.

One of the things I think is important in modeling your particular entity is including a primary key (PK). In my DevOps talk I stress this, as I'd rather most attendees come away thinking a PK is important as their first takeaway from the session. There are exceptions, but they are rare, and I would prefer that most tables just have some PK included from the beginning.

A PK ought to be stable as well, and there are plenty of written words about how to pick the PK for your particular problem domain. Often I have received the advice that natural keys are preferred over surrogate keys, and it is worth the effort to try and identify a suitable column (or set of columns) that will guarantee uniqueness. I think that's good advice, and it's also advice I tend to ignore.

There's an interesting article about keys and the GDPR. The first part is a rather basic description of what PKs are, but the second part talks about keys and some of the rights that data subjects have under the GDPR. I think these are worth considering, especially as it's likely similar legislation will make its way into other jurisdictions, as already seen in California. The short part of the argument is that the right to be forgotten or to have your data deleted is incompatible with the use of natural keys.

It's an argument, though I'm not completely sure if I think it would be solid. There are valid reasons to keep some information about a user, and I suspect keeping a list of emails to delete from a database restore as a separate list would be a valid use. Even if the user asked that their information was removed. It would be, but there would also be a need to ensure that the correct data was removed,  hence a list of emails.

The bigger problem for me is that if I needed to redact or alter this key data, which I would likely do in order to keep some integrity in my database, I'd need to alter this data in lots of tables. That makes for a much more complex set of scripts, including ensuring that I am correctly building a map of the new values I would use for a key. It's much easier to have a surrogate key that doesn't change and just redact the other information.

I'm sure there are arguments both ways, but as we move towards the era of not only seeing data as valuable, but also as an asset we can't completely control, I think surrogate keys make more sense now than ever. Let me know if you agree.

Steve Jones from SQLServerCentral.com

Join the debate, and respond to today's editorial on the forums


The Voice of the DBA Podcast

Listen to the MP3 Audio ( 4.2MB) podcast or subscribe to the feed at iTunes and Libsyn. feed

The Voice of the DBA podcast features music by Everyday Jones. No relation, but I stumbled on to them and really like the music.

ADVERTISEMENT
Database DevOps

Continuous Delivery for SQL Server Databases

Spend less time managing deployment pain and more time adding value. Find out how with database DevOps

SQL Monitor

What’s the top challenge faced by SQL Server professionals in 2018?

Learn how 626 SQL Server professionals monitor their estates in our new report on the State of SQL Server Monitoring. Discover the challenges currently facing the industry, and what is coming next.  Download your free copy of the report

Featured Contents

 

Compress and Decompress in SQL Server 2016

David Fundakowski from SQLServerCentral.com

Explore using Compress/Decompress with varying types of data and examine size/storage usage More »


 

Exhuming the GDPR Bodies

Additional Articles from SimpleTalk

Since the GDPR has gone into effect, the focus has often been on databases. There are many other ways that personally identifiable data may be stored by an organization. In this article, David Poole shows how to use Bash and PowerShell to locate that data in file shares More »


 

Using undocumented DBCC WRITEPAGE to instigate SQL Server database corruption

Additional Articles from MSSQLTips.com

In this tip we look at the undocumented command DBCC WRITEPAGE to corrupt a SQL Server database and then use the command to undo the corruption. More »


 

From the SQLServerCentral Blogs - [Video] Configuring Geo-Replication to SQL DB

SQLRUs from SQLServerCentral Blogs

With the hurricane bearing down on the east coast of the United States last week, making sure you have a... More »


 

From the SQLServerCentral Blogs - Azure Integration Options and Overview

DataOnWheels from SQLServerCentral Blogs

Today I’d like to talk about Azure integration services that you can leverage within the platform. Integration services allow data... More »

Question of the Day

Today's Question (by Steve Jones):

What happens when I run this code?

 DECLARE @d DATETIMEOFFSET , @c VARCHAR(20) ; SELECT @d = '20180903 11:55:34 -7:0' ; SELECT @c = @d ; SELECT @c AS 'TheDate' ; 

Think you know the answer? Click here, and find out if you are right.


We keep track of your score to give you bragging rights against your peers.
This question is worth 1 point in this category: Datetimeoffset.

We'd love to give you credit for your own question and answer.
To submit a QOTD, simply log in to the Contribution Center.

ADVERTISEMENT

Pro Power BI Desktop

This book shows how to deliver eye-catching Business Intelligence with Microsoft Power BI Desktop. You can now take data from virtually any source and use it to produce stunning dashboards and compelling reports that will seize your audience’s attention. Slice and dice the data with remarkable ease then add metrics and KPIs to project the insights that create your competitive advantage.

Yesterday's Question of the Day

Yesterday's Question (by Steve Jones):

What features are not supported on SQL Server 2017 for Linux as of Sept 1, 2018?

Answer: Transactional Replication

Explanation:

Replication is not currently supported for SQL Server 2017 on Linux.

Ref: Release Notes for SQL Server 2017 on Linux - click here


» Discuss this question and answer on the forums

Featured Script

Conditionally Order By Different Column

Noel Scheaffer from SQLServerCentral.com

I came across a situation yesterday that I don’t remember encountering before so I figured it would be worth sharing. The objective was to get the top 5 Card Numbers for each BIN based on the absolute value of either the CreditAmount or DebitAmount. I figured I needed to use a CASE statement which I have done plenty of times, but never quite like this.

More »

Database Pros Who Need Your Help

Here's a few of the new posts today on the forums. To see more, visit the forums.

SQL Server 2017 : SQL Server 2017 - Development

Running total over partition order - Hi, I need to find the running total for each group order by date. So the query is select......., sum(colA) OVER (PARTITION...

How to build an app with GUI that works with SQL Server? - I have to create a project which should have a GUI because people who gonna use it don't know TSQL....


SQL Server 2016 : SQL Server 2016 - Development and T-SQL

xp_cmdshell and Dynamic SQL - Hi I have an SP where I want to output a query to a csv file.  If I hard code the...

error using parameter for table name in dynamic sql - The code below isn't complete. I didn't include the creation of the temp table. My problem is that I'm using...


SQL Server 2014 : Administration - SQL Server 2014

performance issue in 2014 with peoplesoft application - Hi, We upgraded the sql server 2008R2 server to sql server 2014(side by side) along with OS, peoplesoft application. now we...

Patching Always on Secondary - Read only node - Hello, There are three nodes in Availability Group, Node 1 as Primary, Node 2 Read-Only, Node 3 Secondary. When Patching Node 2...


SQL Server 2014 : Development - SQL Server 2014

Varchar(4000) and Performance - Hi, What are the disadvantages of using many columns with varchar (4000) or nvarchar (4000) in terms of performance, DB size,...


SQL Server 2012 : SQL 2012 - General

How do I merge a set of records - My earlier post was a challenge. So I made it simple. run the following code. what i need as output is...


SQL Server 2012 : SQL Server 2012 - T-SQL

Need help in writing Query - Need help in writing query. I table Requestdetails which contain the below data. PkeyRequestIdStateNameResolverGroupDateCreated1123Resolved299/27/18 15:162123Acknowledge299/27/18 15:163


SQL Server 2008 : T-SQL (SS2K8)

Storing Spatial Data - Hi All, I work with geospatial specialists who provides me with polygons which i save it to my geography field. And...


Cloud Computing : SQL Azure - Development

MS SQL Server Azure - Hi All,  I have few SP's(monitoring stats) and Views ( sql server health data) written in SSMS ( Azure). I have to create...


Programming : General

Return temporary table from Stored procedure - I have a generic Sproc that I want to reuse. It returns a resulset which the Parent SProc needs to...

This email has been sent to newsletter@newslettercollector.com. 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.
Feel free to forward this to any colleagues that you think might be interested.
If you have received this email from a colleague, you can register to receive it here.
This transmission is ©2018 Redgate Software Ltd, Newnham House, Cambridge Business Park, Cambridge, CB4 0WZ, United Kingdom. All rights reserved.
Contact: webmaster@sqlservercentral.com