Category: Database

Creating a link between two SQL servers

To create a link between two SQL Servers you need to use the sp_addlinkedserver and sp_addlinkedsrvlogin stored procedures. First, sp_addlinkedserver @server=’DBLINK01′,@srvproduct=”,@provider=’SQLOLEDB’,@datasrc=’SQL-HOU-01′; Where, @server is the name of the link @srvproduct is the type of product, by default SQL Server @datasrc is the server you link to Then, you need to set the username and password […]

Simple script to backup all SQL Server databases

DECLARE @name VARCHAR(50) — database name DECLARE @path VARCHAR(256) — path for backup files DECLARE @fileName VARCHAR(256) — filename for backup DECLARE @fileDate VARCHAR(20) — used for file name SET @path = ‘C:Backup’ SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) DECLARE db_cursor CURSOR FOR SELECT name FROM master.dbo.sysdatabases WHERE name NOT IN (‘master’,’model’,’msdb’,’tempdb’) OPEN db_cursor FETCH NEXT FROM […]

Next Page »