sarika_patalay
asked on
How to check if a table exits on a different server
Hi Experts,
As a part of the stored procedure, I need to check from Server1, on which I the process will be scheduled to execute, if a given table exits on server2. Server 1 and Server 2 are linked. And to add to the complexity the table name I need to perform a lookup for is a variable.
I know, to find out if a given table exits on the same server, the syntax is this:
if exists (select * from information_schema where table_catalog = 'abc' and table_name = 'xyz')
do this..
But, I am not sure how to do the same, to check the table on a different server.
If there is no known way of doing this, is there anyway I can skip the error message. I do not wish to alarm the users.
Thanks in advance.
As a part of the stored procedure, I need to check from Server1, on which I the process will be scheduled to execute, if a given table exits on server2. Server 1 and Server 2 are linked. And to add to the complexity the table name I need to perform a lookup for is a variable.
I know, to find out if a given table exits on the same server, the syntax is this:
if exists (select * from information_schema where table_catalog = 'abc' and table_name = 'xyz')
do this..
But, I am not sure how to do the same, to check the table on a different server.
If there is no known way of doing this, is there anyway I can skip the error message. I do not wish to alarm the users.
Thanks in advance.
IF EXISTS (SELECT * FROM [SERVER1].INFORMATION_SCHE MA.TABLES where table_catalog = 'abc' and table_name = 'xyz')
BEGIN
END
ELSE
BEGIN
END
BEGIN
END
ELSE
BEGIN
END
ASKER
Sorry, dis not work. The syntax i used is:
SELECT * FROM [LV-SQL4].INFORMATION_SCHE MA.TABLES
i get this error:
Invalid object name 'LV-SQL4.INFORMATION_SCHEM A.TABLES'.
SELECT * FROM [LV-SQL4].INFORMATION_SCHE
i get this error:
Invalid object name 'LV-SQL4.INFORMATION_SCHEM
are you sure your using sql server 2005
select @@version
select @@version
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thanks Crag,
It works !
It works !
I need to check from Server1,
on which I the process will be scheduled to execute, if a given table exists on server2. Server 1 and Server 2 are linked. I know, to find
--If the table exists on server1 then check server2
IF EXISTS (SELECT * FROM [SERVER1].INFORMATION_SCHE
BEGIN
END
ELSE
BEGIN
END