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 to use on the link.

sp_addlinkedsrvlogin 'DBLINK01','false',null,'sa','Pa$$w0rd';

The first parameter is the name of the link to use,
The fourth is the account of the remote server to use,
The fifth is the password for the account.

Simple script to backup all SQL Server databases

[draft]

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 db_cursor INTO @name

WHILE @@FETCH_STATUS = 0
BEGIN

SET @fileName = @path + @name + ‘_’ + @fileDate + ‘.BAK’
BACKUP DATABASE @name TO DISK = @fileName

FETCH NEXT FROM db_cursor INTO @name
END

CLOSE db_cursor
DEALLOCATE db_cursor

http://www.mssqltips.com/tip.asp?tip=1070

Sending Mail using PL/SQL

by m-c
by m-c

I have been playing with Oracle Management Server at work receenty to try and mke the management of all our Oracle 8i and 9i databases a little easier.
One of the thing I want to setup was something to monitor the amount of tablespace left in each tablespace. I already had a clunky way to do it using PL/SQL, shell scripts and web pages. But OMS looked like a better way to do it.

Read More »

Moving a database to a new ORACLE_HOME

I recently had a request at work to upgrade a 10.2.0.1 database to 10.2.0.4. Now normally this would be a fairly simple request. However, on the server the customers database is running on, the oracle home in question is shared by about 5 different databases. Now I don’t want to upgrade all the databases, just this one customers.

How do I do that? Move that database in question to a new ORACLE_HOME.

This sounds like it would be a difficult task, but its not that hard.
Check out the step after the break.

Read More »