In SQL, adding an index to a table can provide us with a significant performance boost, especially if it’s a covering index for commonly run queries.
But what exactly is a covering index?
Let’s find out.
Continue readingIn SQL, adding an index to a table can provide us with a significant performance boost, especially if it’s a covering index for commonly run queries.
But what exactly is a covering index?
Let’s find out.
Continue readingWhen we have a column that’s defined as a composite type in PostgreSQL, we have some options when it comes to inserting data. For example, we can explicitly specify each individual field of the composite type, or we can use a row constructor to insert all fields at once.
Below are four different options for inserting composite values into a column in PostgreSQL.
Continue readingThere are various key types in SQL, each with their own characteristics. Some of these can be enforced with a constraint of one kind or another. Others are not necessarily enforced with a constraint, but are more of an abstract notion, albeit, an important one. These key types consist of one or more columns with certain characteristics that qualify it as the particular key.
One such key type is the superkey.
Continue readingIn relational databases, a foreign key is typically a field that is linked to another table‘s primary key field in a relationship between two tables.
However, there’s also a type of foreign key we call the self-referencing foreign key. The self-referencing foreign key refers to a field within the same table, creating a relationship between rows in the same table.
Continue readingIn SQL databases, triggers can play a significant role in automating responses to specific events within a database. Whether we’re dealing with data validation, logging changes, or enforcing business rules, SQL triggers can be a handy tool to ensure that certain actions are taken automatically when certain conditions are met.
This article covers what SQL triggers are, how they work, and provides an example to illustrate their use.
Continue readingIf you’re getting SQL Server error 107 that goes something like “The column prefix ‘e’ does not match with a table name or alias name used in the query“, look at your column prefix.
This error occurs when we use the asterisk wildcard (*
) that’s incorrectly qualified with a column prefix. The prefix, if provided, must match a table name or alias name. If you’re using a table alias, then you must use that instead of the table name.
When writing queries in SQL, we sometimes need to summarize data based on specific criteria. Fortunately SQL makes this easy to achieve with the GROUP BY
and HAVING
clauses. These two clauses allow us to aggregate data and filter the results based on group conditions.
More specifically, GROUP BY
allows us to group the results, and HAVING
is an optional clause that we can use to filter the results based on certain conditions.
Below is an example of where we can use these two clauses to aggregate data and filter it based on certain criteria.
Continue readingIn relational database design, the concept of a “key” is fundamental. Keys are essential for uniquely identifying records in a table, ensuring data integrity, and facilitating efficient data retrieval. Among the different types of keys used in SQL, the natural key is one that often sparks discussion among database designers, especially when compared with the surrogate key.
Let’s explore the concept of a natural key, its advantages and disadvantages, and look at a practical example to illustrate its use.
Continue readingWhile the primary key is almost certainly the most discussed key in SQL, there are other types of keys that we shouldn’t forget. One such key is the alternate key.
In this article, we’ll look at the concept of the alternate key in SQL.
Continue readingThere are many different “key” types in SQL. We have the primary key, the foreign key, and even the unique key.
But have you heard about the candidate key?
Continue reading