When creating tables we may choose to use an INT column with an IDENTITY set as a unique clustering value. On occasions we find out that being able to store 2,147,483,647 records just isn’t enough and we need to change this field to be a BIGINT to let us store… well, a lot more. Here I’ll outline one approach which could […]
Querying with Aliases
When writing larger queries which return more fields or join together an increasing number of tables it can be easy for scripts to get unruly. A fundamental skill to help with the readablity of you queries is through the use of Aliases. An alias provides us a was to change how we reference part of […]
Performance Considerations using APPLY
In the previous post we looked at how to use the CROSS APPLY and OUTER APPLY operators as alternative to a JOIN in queries with some examples. As we wrapped that up I also mentioned that there can be drawbacks to using APPLY in our queries, particularly when we’re working with large data sets. The issue is due to the way that the right hand […]
Using Cross Apply and Outer Apply
When joining data in SQL we have a number of options to us including INNER and OUTER joins, but one of the ones I tend to use less frequently is the APPLY operator, specifically the CROSS APPLY and OUTER APPLY operators. As with other types of joins they operate slightly differently and have considerations which should be taken into account when deciding on the output […]
Complex Updates and Deletes
The UPDATE and DELETE statements allow us to manage the data within our databases and being able to use them effectively is key. There was recently a question from a junior developer asking about how to perform data changes when table joins are required so I thought it a good opportunity to put forward some more thought out details […]
Partition Elimination in SQL Server
Back in our introduction to partitioning I’d mentioned that using partitions can also bring us benefits in terms of performance. That performance comes in the way of partition elimination with our queries. Before we get started let’s set the stage with a sample table and one million records of data which we’ve used before: What is partition elimination Partition […]
2022 Year in Review
Happy new year folks! I hope everyone enjoyed the festive period and was able to get some sort of a break to spend time with those closest to you. This past year has been a busy one personally and quite a journey with this blog too. With that in mind I thought it was worth […]
SSMS Tip: Saving Schema Changes
When using SQL Server Management Studio (SSMS) you have the option of creating or maintaining tables via regular SQL DDL statements or you can use the built in Designer tool which provides a GUI interface covering a selection of the same functionality such as adding fields, changing data types, maintaining foreign keys etc. Sometimes the […]
SSMS Tip: Show Table Details
Sometimes when you’re querying a set of data for the first time it can be tricky to understand the results you see. What are the data types? How is the data keyed? Are there any constraints in place? Does the table have foreign keys relating to other tables? So you might then end up scanning […]
This month’s invitation from Garry asks us to talk about what SQL related end of year activities we have to look forward to. Garry has included a few typical DBA examples such as archiving or purging out old data, or updating calendars such as dimension tables or even partition schemes for the new year to come. However […]