Reading Time: 4 minutesA primary key constraint and a unique constraint are both meant to enforce uniqueness in column(s). Since that’s true, it begs the question: What’s the difference? In this very brief tutorial, we’ll discuss the two main differences between primary key constraints and unique constraints. Difference # 1: Primary key constraints Continue Reading
SQL Server Week Number: Use this ONE Simple Function!
Reading Time: 2 minutesSQL Server makes it very easy to gather the week number of a specific date. Maybe you need to know what week of the year a certain date falls within. The DATEPART system function is what we can use to gather that information. Using the DATEPART system function The date Continue Reading
SQL Server QUALIFY: Doesn’t Exist, Do THIS Instead
Reading Time: 3 minutesSQL Server has many useful window functions available to us that can make the task of gathering aggregate/ranking/offset data very easy. One tool that you might have heard of is the QUALIFY clause. This tool can be used to filter the result of a window function. The problem is that Continue Reading
DELETE Statement with a JOIN: How it’s done
Reading Time: 4 minutesIt is very easy to write a DELETE statement with a JOIN. In this very brief tutorial, we’ll walk through how it’s done. We’ll go over just these two topics: Write it as a SELECT statement first Convert your query to a DELETE statement Everything in this tutorial can also Continue Reading
Default Values in Stored Procedure Parameters: Do you know this rule?
Reading Time: 4 minutesIt is very easy to set up a default value for an input parameter in a stored procedure. When we establish a default value for an input parameter, it becomes optional to provide a value for that parameter when calling the procedure. In that event, the value used for the Continue Reading
SQL Server WAITFOR DELAY: Explained
Reading Time: < 1 minuteThe WAITFOR DELAY system function is the best tool we have in Microsoft SQL Server to introduce a pause in our SQL code. The syntax is extremely simple. We just run the WAITFOR DELAY statement on its own, like this: WAITFOR DELAY ’00:00:10′ You can see how in single quotes, Continue Reading
How to Gather User ID Values in SQL Server: Just use this one helpful function.
Reading Time: < 1 minuteThere may be times where it might be helpful to gather the ID of the person or application that is interacting with the data or objects in your database. Maybe you are trying to audit changes to your data, or maybe you want to get a better idea of how Continue Reading
SQL Server Functions VS Stored Procedures: What’s the difference?
Reading Time: 6 minutesTwo of the most helpful objects you can create in Microsoft SQL Server are user-defined functions and stored procedures. If you are just starting out with SQL Server, you might wonder “What’s the difference?“. In this very brief tutorial, we’ll discuss the difference between SQL Server functions and stored procedures Continue Reading
SQL Server Filtered Indexes: Explained for Beginners
Reading Time: 5 minutesFiltered indexes in SQL Server can dramatically increase the efficiency of queries against data in your database. They are a fantastic optimization tool you should understand and remember during the design and development of tables in your database! In this brief tutorial, we’ll discuss what a filtered index is and Continue Reading
SQL Server Covering Indexes: Explained with Examples
Reading Time: 6 minutesIndexes are extremely important when it comes to writing queries that return data in an efficient way. We not only want to make sure our queries return exactly the information we need, but we also want that information to be returned to us quickly. In this brief tutorial, we’ll discuss the Continue Reading