Get the Number of Rows Affected by Previous SQL Statement

Some RDBMSs provide an easy way for us to find out how many rows were affected by the last SQL statement. This can be handy when running INSERT, UPDATE, or DELETE statements.

The method used depends on the DBMS we’re using. Below, I look at how some of the major DBMSs implement this functionality.

Continue reading

7 Ways to Insert Multiple Rows in SQL

We can use the SQL INSERT statement to insert a row into a table. We can also use it to insert more than one row.

Below are seven ways to insert multiple rows into a table in SQL. Most of these examples should work in the major RDBMSs, with the possible exception of Oracle. But no worries, I’ve included an example just for Oracle.

Continue reading

Fix: “BACKUP LOG cannot be performed because there is no current database backup.” in SQL Server/SQL Edge

If you’re trying to back up the transaction logs in a SQL Server or SQL Edge database, but you get an error that states BACKUP LOG cannot be performed because there is no current database backup, you’ll need to perform at least one full backup of the database before you attempt to back up the transaction logs.

Continue reading

How to Add Leading & Trailing Zeros in Azure SQL Edge

Azure SQL Edge uses a limited version of the SQL Server Database Engine. One of the limitations of Azure SQL Edge, is that it doesn’t currently support CLR-dependent T-SQL functions, such as the FORMAT() function.

This can be a problem when trying to format numbers.

However, there are often ways around such limitations. Here are examples of how we can pad numbers with leading and trailing zeros in SQL Edge.

Continue reading

Fix: “The statement BACKUP LOG is not allowed while the recovery model is SIMPLE” in SQL Server (and SQL Edge)

If you get an error that reads The statement BACKUP LOG is not allowed while the recovery model is SIMPLE when trying to back up a database in SQL Server or Azure SQL Edge, it’s because you’re trying to back up the transaction logs on a database that uses the simple recovery model.

To fix this, change the recovery model to either full or bulk logging.

Continue reading