Archive for the ‘SQL Server’ Category

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: When were databases last restored

Here’s a couple of queries I’ve modified from When was the last time your SQL Server database was restored? This first query shows restore times by database and restore type. ?View Code TSQLDECLARE @dbname sysname, @days int SET @dbname = NULL –substitute for whatever database name you want   — Max data / restore type […]

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 ( […]

TSQL: Create SQL Logins using certificates and asymmetric keys 70-462

Here’s some TSQL for creating sql logins using certificates and asymmetric keys. Explanatory comments are included. ?View Code TSQLCREATE CERTIFICATE myCert ENCRYPTION BY PASSWORD = ‘Secret2014′ WITH SUBJECT = ‘My certificate for sql logins’;   USE [master] GO   — create sql user with the cert CREATE LOGIN [sql_user_a] FROM CERTIFICATE [myCert]; GO   — […]

TSQL: Partially Contained Databases 70-462

Here’s some TSQL for the Partially Contained Databases section of the 70-462. Explanatory comments are included. ?View Code TSQL– enable show advanced options and view current config EXEC sp_configure ‘show advanced options’, 1; GO RECONFIGURE WITH OVERRIDE; GO EXEC sp_configure; GO — enable the feature EXEC sp_configure ‘contained database authentication’, 1; GO RECONFIGURE WITH OVERRIDE; […]