Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
drako17
Starting Member
9 Posts |
Posted - 2008-06-25 : 06:20:45
|
| HiI am trying to check if some table exists in linked server.The flow is this:1.check if Linked Server Exists2.Check if Needed DB exists3.Check if needed table existsHere the script:IF EXISTS (SELECT 1 FROM [master].[dbo].[sysservers] WHERE srvname = 'LinkedServerName')BEGIN IF EXISTS(SELECT 1 FROM [LinkedServerName].[master].[dbo].[sysdatabases] WHERE [name]='DBNAME') BEGIN IF EXISTS (SELECT 1 FROM [LinkedServerName].[DBNAME].[dbo].[sysobjects] AS sysobjcts WHERE [sysobjcts].[name] ='TableName' AND [sysobjcts].[xtype]='U') PRINT 'OK' ENDENDThe problem occurs when the needed DB ('DBNAME') not exists in the Linked Server.and i get the following error:Server: Msg 7314, Level 16, State 1, Line 4OLE DB provider 'LinkedServerName' does not contain table '"DBNAME"."dbo"."sysobjects"'. The table either does not exist or the current user does not have permissions on that table.OLE DB error trace [Non-interface error: OLE DB provider does not contain the table: ProviderName='LinkedServerName', TableName='"DBNAME"."dbo"."sysobjects"'].How can i check if table exists in linked server?Thanks |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2008-06-25 : 12:20:35
|
| Hi,try to build functions for checking if the wanted object exists and use the returnvalue of each function to make your controlflow.It's because, i think, the parser is not looking at your if-statement at parse-time and then the not existing DBNAME always results in an error.GreetingsWebfred |
 |
|
|
drako17
Starting Member
9 Posts |
Posted - 2008-06-25 : 14:34:05
|
| ThanksI will try and inform you if it succeded |
 |
|
|
drako17
Starting Member
9 Posts |
Posted - 2008-06-26 : 04:36:27
|
| OK,Its working,But instead Function,I created Stored Procedure.UDF cannot be called in Linked Server.Thanks |
 |
|
|
|
|
|