Database Fundamentals #27: Creating a Primary Key in the Table Designer

Database Fundamentals
Defining primary keys is the hardest part of the operation. You will need to work very closely with the business in order to define exactly what column or columns make a row unique. Often, this will be difficult for a business to define, but you will need to persist in order to be sure that you can properly maintain the integrity of the data being stored. It’s hard for a business to define partly because people just don’t think in terms of “unique values.” They tend to think in terms of pointing at a thing and saying “that’s the one I want.” But invariably there’s a way to uniquely identify almost any concept that business can come up with. You just have to work with the business people to find…
Read More

Extended Events Capturing the T-SQL of Prepared Statements

SQL Server, T-SQL, Tools
I asked this question myself: Is there a way to use Extended Events to capture the T-SQL of a prepared statement? Why would I be concerned with prepared statements? Wouldn't sql_batch_completed and rpc_completed cover us? Well, no. What happens when you use sp_prepare? What happens when you're using an ORM tool that's using prepared statements? You may see queries that look like this: EXEC sp_execute 5, 48766; What the heck code is that executing? Let's find out. sp_statement_completed Here's a set of sample code that I swiped from Microsoft (they don't mind, but, full attribution like a good citizen, you'll find it here): DECLARE @P1 int; EXEC sp_prepare @P1 output, N'@Param int', N'SELECT * FROM Sales.SalesOrderDetail AS sod INNER JOIN Production.Product AS p ON sod.ProductID = p.ProductID WHERE SalesOrderID =…
Read More

SQL Server Backups on AWS RDS

RDS
One of the things I love the most about Platform as a Service offerings is the fact that it makes it so I don't have to do silly things backup SQL Server databases on RDS. However! I'm also a paranoid control freak, aka, a DBA. While I appreciate that AWS has a good backup process and I can test it through recovery of my databases, I still want to do my own backups under some circumstances. Can I backup SQL Server databases on RDS? No and yes. Let's talk about it. Backup SQL Server Databases on RDS I have an RDS SQL Server instance running right now on AWS. I can connect up to it and run the following command: BACKUP DATABASE HamShackRadio; Which results in the following: Msg 262,…
Read More

State of Database Monitoring

Redgate Software
Redgate published a report that many of you helped with by providing information. First, thanks! Your info really helped. Second, do you want to see it? You can. Go here and get a copy. However, want to talk about it? Anthony Nocentino and I are hosting a little chat this week on Wednesday at 4-5 BST, 10-11 Central. You can click on this to get registered. Please do. It's going to be great information and, since it'll be live, you can ask questions. It will be recorded and you can watch it later. However, where's the fun in that? Join in. Be there live.
Read More

Database Fundamentals #26: The Primary Key War

Database Fundamentals
There is a war about primary keys in the database world. There are two camps. The first camp believes that primary keys should only ever be created on meaningful information. For example, there is an ISO standard for the abbreviation of state names in the United States. You could create a table for looking up state names and make the primary key that abbreviation because it is guaranteed to be unique. The other camp believes that primary keys should never be created on meaningful information because, meaningful information is subject to change and you don’t want your primary keys to be changing. A changing primary key means changing all the tables that are related to that value. This camp believes that all primary keys should be artificial. As far as…
Read More

Combining DMVs, Query Store and Extended Events Is Challenging

Uncategorized
I was recently asked a question on a forum by a person who was frustrated with all the tool choices we have for measuring performance. Moreover, they were frustrated that a simple and clear combination of the tools to achieve synergy was extremely challenging. In fact, they said that, just using the query_hash as an example, they never saw a single match between the DMVs, Query Store and Extended Events. Now, that's pretty unlikely and I'm sure we could talk about why that might be the case. However, this idea of combining the tools, I shared a bunch of thoughts on it. I decided, maybe it's worth sharing here too. Achieving Synergy Honestly, this is tough. I work for a company that makes a monitoring tool. We are trying to…
Read More

AWS RDS and SQL Server Deadlocks

AWS, RDS
What's the story with AWS RDS and SQL Server deadlocks? I'm approaching AWS RDS like I was taking on a new role at a new organization. Do we have backups in place? Yes, great. Can I test them? Yes. Do they meet our RTO & RPO? Yes. Moving on. What have we got for monitoring? AWS RDS has a good percentage of the fundamentals. Now, it's laid out a little oddly. You have the stuff going through CloudWatch which is largely OS oriented. Then you have enhanced monitoring, which you have to turn on, which covers eight key metrics for SQL Server. Finally, you can enable Performance Insights which gives you metrics on query behaviors (and yeah, any or all of these may be the subject of upcoming blog posts).…
Read More

Fun Fact: AWS RDS and system_health

AWS, RDS
Did you know that the system_health Extended Event session was running in your RDS instances? Well, it is. HOWEVER. This query, which works perfectly fine on my on premises instance of SQL Server, will fail: SELECT @path = dosdlc.path FROM sys.dm_os_server_diagnostics_log_configurations AS dosdlc; SELECT @path = @path + N'system_health_*'; WITH fxd AS (SELECT CAST(fx.event_data AS XML) AS Event_Data FROM sys.fn_xe_file_target_read_file(@path, NULL, NULL, NULL) AS fx ) SELECT dl.deadlockgraph FROM ( SELECT dl.query('.') AS deadlockgraph FROM fxd CROSS APPLY event_data.nodes('(/event/data/value/deadlock)') AS d(dl) ) AS dl; Whereas, thanks to Aaron Bertrand, this query will work just fine: WITH fxd AS (SELECT CAST(fx.event_data AS XML) AS Event_Data FROM sys.fn_xe_file_target_read_file(N'system_health*.xel', NULL, NULL, NULL) AS fx ) SELECT dl.deadlockgraph FROM ( SELECT dl.query('.') AS deadlockgraph FROM fxd CROSS APPLY event_data.nodes('(/event/data/value/deadlock)') AS d(dl) ) AS dl;…
Read More

Getting Started on AWS RDS

AWS, RDS
I'm expanding my skill set into AWS in a big way. So, one of the things I do when I'm learning a technology is to write blog posts about that tech. So, prepare yourself for a bunch of info on AWS. I'll be working with RDS, which will include SQL Server & PostgreSQL for certain. I'll also be posting quite a bit on AWS DevOps as I get into it. The usual stuff, including SQL Server, query tuning, Extended Events, Azure, Azure DevOps, and all the rest is not going away. I'm just adding another topic. Today, we're getting started on AWS RDS. Creating an RDS Instance The thing is, there's a lot of documentation available on getting started on AWS RDS, directly from Amazon. It's embedded neatly into the…
Read More

Let’s Talk About The Cloud

Uncategorized
I'm launching a new initiative called the Community Circle Cloud Conversation Club (c5 for short). It's going to a panel discussion lead by experts on cloud technologies. I'll be hosting it every Friday at 13:00 EDT starting next Friday, June 5. Every week will feature five different experts speaking on different topics. This coming week's experts are: Kellyn Pot'Vin-GormanBob PusateriFrank GeislerMindy CurnuttCarlos Robles Follow this link to take part on Friday. Our topic will be: "Why Platform as a Service is a Must For Cloud-Based Data Management" This is part of the Community Circle content hosted by Redgate. For all the details on the Community Circle go here. In a nutshell, it's community oriented training, videos, blog posts, classes and even a cookbook. All in support of your continued learning…
Read More