Posts Tagged ‘TSQL’

TSQL: Restore a multiple file backup

Just a follow up post using the backup files created in TSQL: Backup a database to multiple files. Here’s the script I used… ?View Code TSQLSET STATISTICS IO ON; SET STATISTICS TIME ON; GO   — Single file restore RESTORE DATABASE dbname FROM DISK = ‘\\path\to\backup\location\tmp\single_file_backup.bak’ WITH RECOVERY, MOVE ‘dbname’ TO ‘d:\SQLData\dbname.mdf’, MOVE ‘dbname_log’ TO […]

TSQL: Backup a database to multiple files

I wanted to see how much I could reduce backup times by specifying multiple files in the BACKUP TSQL command. Here’s a script I wrote to do this and I present a summary of the results below. The times are based on a database that produced a backup file(s) of approximately 51GB. You mileages will […]

TSQL: Estimated database restore completion

Here’s a query proving you approximate percentage compeled, and estimated finish time, of any database restores happening on a SQL Server instance… ?View Code TSQLSELECT st.[text], r.percent_complete, DATEADD(SECOND, r.estimated_completion_time/1000, GETDATE()) AS estimated_completion_time, r.total_elapsed_time FROM sys.dm_exec_requests r CROSS APPLY sys.dm_exec_sql_text(r.[sql_handle]) st WHERE [command] = ‘RESTORE DATABASE'; The resultset will look something like below… text percent_complete estimated_completion_time […]

TSQL: Database Mirroring with Certificates

Here’s some more TSQL for the 70-462 exam. The script shows the actions needed to configure database mirroring using certificates for authentication. Explanatory notes are included but you’re likely to need the training materials for this to make sense. TSQL is not included for the backup/restore parts needed for database mirroring. ?View Code TSQLSELECT * […]

TSQL: Database Permission Excercise for 70-462

Here’s the TSQL for an exercise, involving database permissions, from the 70-462. Explanatory comments are included. ?View Code TSQLCREATE DATABASE Saturn; GO   USE Saturn; GO CREATE ROLE Moon_Table_Editors; GO   — Create tables CREATE TABLE Mimas ( id INTEGER IDENTITY(1,1) NOT NULL PRIMARY KEY, column1 VARCHAR(100) NOT NULL ); GO CREATE TABLE Thethys ( […]