The MERGE
statement in SQL Server allows us to perform INSERT
, UPDATE
, and DELETE
operations in a single query. This makes it an efficient way to synchronize two tables, typically between a source and a target, based on a defined condition. Rather than running separate queries to handle insertions, updates, and deletions, we can combine all of these operations into one statement; the MERGE
statement.
Category: DBMS
Database Management Systems
Fix “Column, parameter, or variable #1: Cannot find data type” in SQL Server (Error 2715)
If you’re getting SQL Server error 2715, which reads something like “Column, parameter, or variable #1: Cannot find data type SERIAL“, it appears that you’re trying to define a column to have a data type that’s not supported in SQL Server.
To fix this issue, be sure to use a supported data type for all columns.
Continue readingA Deep Dive into PostgreSQL’s TRUNCATE Statement
Most relational database management systems support the TRUNCATE
statement, and PostgreSQL is no exception.
That said, PostgreSQL has a few differences in the way its TRUNCATE
statement works when compared to many other RDBMSs.
In this article, we’ll explore the various features of PostgreSQL’s implementation of the TRUNCATE
statement, along with examples to demonstrate.
A Comparison of 6 SQL Rank Functions
SQL rank functions can be handy things to have when analysing data. Most major RDBMSs implement a similar bunch of ranking functions, usually with the same names. These rank functions allow us to assign rankings to rows based on specific criteria.
In this article, we’ll look at six commonly used SQL ranking functions, and observe how they differ. We’ll throw them all together into a single query and see their results side by side.
The rank functions in question are: ROW_NUMBER()
, RANK()
, DENSE_RANK()
, NTILE()
, PERCENT_RANK()
, and CUME_DIST()
.
Fix “A MERGE statement must be terminated by a semi-colon (;)” in SQL Server (Error 10713)
If you’re getting SQL Server error 10713 that reads “A MERGE statement must be terminated by a semi-colon (;)“, it’s because you’re running a MERGE
statement without terminating it with a semi-colon.
The MERGE
statement requires a semi-colon at the end of it in order to correctly terminate the statement.
To fix this issue, put a semi-colon at the end of your MERGE
statement.
Return the Values that were Updated by an UPDATE Statement in SQL Server (Both Old and New Values)
When we run an UPDATE
statement in SQL, we might not always be interested in which rows or values were updated. But there may be times when we need to examine this data, or log it somewhere like in a separate table.
This is where SQL Server’s OUTPUT
clause can help tremendously.
Updating Composite Values in PostgreSQL
When we have a column with composite data in PostgreSQL, we can access each field by using dot notation. This is true whether we select the data or update it. This means that we can use dot notation to update individual fields within a composite column.
And if we need to update all fields at once, we can use the ROW
constructor.
Fix “Cannot insert explicit value for identity column in table” in SQL Server (Error 544)
If you’re getting an error that reads “An explicit value for the identity column in table ‘Dogs’ can only be specified when a column list is used and IDENTITY_INSERT is ON” in SQL Server, it appears that you’re trying to insert a value into an IDENTITY
column.
Specifically, you’re trying to do that while the IDENTITY_INSERT
option is set to OFF
.
To fix this issue, either enable IDENTITY_INSERT
before inserting the value, or omit the value from your list of values to insert (and let the IDENTITY
column do it’s thing).
How to Pad a String with Specific Characters in PostgreSQL
PostgreSQL provides us with a couple of functions that allow us to pad strings. We can use these functions to put one or more space characters or other characters on either the right side, left side, or both sides of the string.
Continue reading4 Ways to List All Indexes in a SQL Server Database
By default, SQL Server creates indexes automatically when we do things like create certain constraints. We also have the option of creating indexes separately for our own (usually performance related) reasons. Either way, there may be times where we need to check what indexes we have in our database.
In this article, we’ll explore four ways to retrieve information about all indexes in a SQL Server database.
Continue reading