Wednesday, August 26, 2015

ID Identity as Primary Key Cluster

Here is some sample code I give programmers. A composite PK is often a touch faster but sometimes a PK like this is the best alternative. Everything even Inserts are faster with a Primary Key and Cluster

CREATE TABLE [dbo].[TableName](
[ID] [int] IDENTITY(1,1) NOT NULL,
All your columns remember the last column statement has a comma after it,
 CONSTRAINT [PK_TableName] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

Friday, August 07, 2015

restore Master from Backup


To restore the master database

  1. Start the server instance in single-user mode.


To configure startup options

  1. In SQL Server Configuration Manager, click SQL Server Services.
  2. In the right pane, right-click SQL Server (<instance_name>), and then click Properties.
  3. On the Startup Parameters tab, in the Specify a startup parameter box, type the parameter, and then click Add.
    For example, to start in single-user mode, type -m in the Specify a startup parameter box and then click Add. (When you restart SQL Server in single-user mode, stop the SQL Server Agent. Otherwise, SQL Server Agent might connect first and prevent you from connecting as a second user.)
  4. Click OK.
  5. Restart the Database Engine.

To restore a full database backup of master

use the following RESTORE DATABASE Transact-SQL statement:
RESTORE DATABASE master FROM <backup_device> WITH REPLACE

C:\Users\boconnell>SQLCMD -E -S touch -Q "RESTORE DATABASE Master FROM DISK='\\BlahBlah\sqlbackups\PRD\VM\Blah05P$PRD5\master\FULL\Blah05P$PRD5_master_FULL_20150806_140500.bak" WITH REPLACE

Nota Bena:
make sure that all databases are present that were present beffore the restore. If any are not accessable then attach them.