SQL Server allows to handle errors with TRY ... CATCH
blocks, and provides several statements to get information about the error that is being handled.
Tag: level-intermediate
Db2 hash functions: HASH(), HASH4(), HASH8()
Db2 supports three different hash functions, and each of them can use different algorithms. Let’s shred some light on them to understand their use cases.
Find values that appear in multiple columns, in different rows
There are situations when you need to find values that occur in multiple columns, but oitentially in different rows. This can be done with the JOIN
or the INTERSECT
statement.
Concatenate multiple columns from the same table
Sometimes we want to concatenate multiple table columns, and see them as a single column in our resultset. This may be the case, for example, if we have columns like email1, email2, email3.
Copying tables in MariaDB and MySQL
There are many reasons why we may want to duplicate a table. We may want to copy the table structure alone, or include the rows, we may only want to copy some sample rows. Let’s see how to copy a table in MariaDB and MySQL.
Find dates in a given year
Sometimes we want to find all events that happened in a given year. For example, a count of the sales that happened in the year 2000. It’s frequent to run a correct query that turns out to be slow. Let’s see how to do it properly.
Select values that occur multiple times
There are many cases when we want to select values that occur multiple times: customers that ordered the same product multiple times, users with the same email, and so on. We can do this with GROUP BY
and HAVING
.
SQL Server: CHECKSUM() vs CHECKSUM_BINARY() vs HASHBYTES()
SQL Server has at least three functions to create checksums or hashes: CHECKSUM()
, CHECKSUM_BINARY()
, and HASHBYTES()
. Here we discuss what differences exist between them, and how to choose the proper function for a specific use case.
MariaDB: Running a prepared statement in a stored procedure
How to run prepared statements in a MariaDB stored procedure. The article covers one-off prepared statements, reusable prepared statements, and parameters.
PostgreSQL: Working with ENUM types
Sometimes a text column should not contain free texts, but only values from a predefined list. PostgreSQL allows to achieve this by creating an enumeration – or an ENUM
type. This allows validation on input, and makes the values more efficient.