Restore a SQL Server Database (T-SQL)

If you use SQL Server Management Studio (SSMS) or some other GUI to manage your databases, you might be used to backing up and restoring databases using “point and click”.

Usually this involves right-clicking on the database and selecting Restore or similar, then following the prompts (for example, when restoring a database in Azure Data Studio).

But if you ever need to do it with T-SQL, you can use the RESTORE DATABASE statement.

Continue reading

SQL Server’s Equivalent to Sleep(): The WAITFOR Statement

In SQL Server, you can use the WAITFOR statement to delay the execution of a batch, stored procedure, or transaction.

It works similar to MySQL‘s sleep() function.

Actually, it’s probably more like a combination of Postgres‘s three “sleep” functions: pg_sleep(), pg_sleep_for(), and pg_sleep_until().

I say this, because SQL Server’s WAITFOR statement gives you the option of specifying either a time delay, or an actual fixed time before execution continues.

Continue reading