mssql
SQL Server database mirroring
Submitted by madvip on Thu, 04/10/2008 - 14:44.You can find lots of online resources which describe how to mirror an MSSQL database, however the ones I've seen all manage to fail to explain all the necessary prerequisites. The first step to correctly configure a database for mirroring is to take a full backup of the database and another backup of its transaction log file:
BACKUP DATABASE my_db TO DISK='c:\my_db_full.BAK' WITH INIT BACKUP LOG my_db TO DISK='c:\my_db_log.TRN' WITH INIT
Then we need to restore the database (but not recovering it, so we keep it closed for mirroring) on our destination site:
Removing duplicate rows from tables
Submitted by madvip on Thu, 04/10/2008 - 13:20.The most efficient way to remove duplicate rows from a table is by using what we database freaks call 'CTAS'. It is an exotic acronym for the SQL statement 'CREATE TABLE AS'. Imagine table T1 contains duplicate rows and we want to create table T2 as a non-duplicate version of T1. The syntax is as follows:
CREATE TABLE T1 AS SELECT DISTINCT * FROM T2;
In Oracle this will generate lots of temp information so be sure you provide an ample temp tablespace!
Setting up a Linked Server to an Oracle database
Submitted by madvip on Mon, 03/10/2008 - 14:55.To create a linked server you can use the following T-SQL:
USE MASTER GO EXEC master.dbo.sp_MSset_oledb_prop 'OraOLEDB.Oracle', 'AllowInProcess', 1 GO EXEC sp_addlinkedserver @server = 'ORA_DB', @srvproduct = 'Oracle', @provider = 'OraOLEDB.Oracle', @datasrc = 'ORA_DB' GO Exec sp_serveroption 'ORA_DB' , 'rpc' , TRUE GO Exec sp_serveroption 'ORA_DB' , 'data access' , TRUE GO Exec sp_serveroption 'ORA_DB' , 'rpc out' , TRUE GO USE [master] GO EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname = 'ORA_DB', @useself = 'False', @rmtuser = 'madvip',
Querying data from a remote SQL Server
Submitted by madvip on Wed, 03/05/2008 - 14:51.To query data from a remote SQL Server you need to first setup a linked server. Then you can query the linked server by using the following command:
SELECT * FROM linked-server.database-name.schema-name.table-name
MS SQL Windows authentication
Submitted by madvip on Mon, 02/04/2008 - 15:54.One often encounters a problem when presented with the 'Connect to Server' dialog box - if the Windows Authentication is selected from the Authentication drop-down, the User name & Password area is grayed out and unusable. The domain user account the user is authenticated with is visible, but grayed out, and the password field is blank and unusable. The fix for this is the following:
1) Click start/control panel/user accounts/click on my user account/manage my network passwords:
* Make an entry for the SQL Server computer hostname... MyConnection
Connecting to RMAN 8i
Submitted by madvip on Fri, 02/01/2008 - 13:43.There are two ways which I know of to connect to RMAN 8i. The first one uses password file authentication and the second one using o/s authentication:
Method 1:
/ora/ora8i$ export ORACLE_SID=my_db /ora/ora8i$ rman catalog rman/rman@my_rman_db Recovery Manager: Release 8.1.7.4.0 - Production RMAN-06008: connected to recovery catalog database RMAN# connect target RMAN-06005: connected to target database: my_db (DBID=3393849776) RMAN]
Method 2:
/ora/ora8i$ export ORACLE_SID=my_rman_db /ora/ora8i$ rman target system/password@my_db catalog rman/rman

