Posts tagged: sp_dropserver

Compare two tables record (SQL Server)

By Ashish Khandelwal, July 15, 2011

Sometime we want to compare the records between two database tables. These databases could be on same server or on different servers. Here is some information about how we can compare records between two tables. Hope this will help and give you some information.

The ‘EXCEPT’ operator performs the compare between two tables:

When both databases are on same server:

The following query returns any distinct values from the query to the left of the EXCEPT operand that are not also found on the right query.

SELECT ProductID

FROM Production.Product

EXCEPT

SELECT ProductID

FROM Production.WorkOrder ;

–Result: 266 Rows (products without work orders)

Read more »

SQL Query to the remote SQL server

By Ashish Khandelwal, September 25, 2009

Sometimes you want to query to the remote SQL server (Server which is in network). Following statement will help you to fire a query to the remote server:

Select * from [ServerName].[DatabaseName].[Scheme].[TableName]

Before you fire query, you are required to link to the server on which you want to query.  The ‘sp_addlinkedserver’is a system store procedure which can be used to add a link server to the server you are sitting.

EXEC sp_addlinkedserver

@server = ‘SourceServer’

, @Srvproduct = ”

, @Provider = ‘SQLNCLI’

, @datasrc = ‘Remote SQL Server instance name’ Read more »