MikeBronner
Programmer
I am able to get the list of tables from my linked server in SQL2000 using the following query:
However, this will not work in SQL2005, as the server object SYSREMOTE_TABLES no longer exists. To create the proper code, I checked the internals of the system stored procedure 'sp_tables_ex' (same as in SQL2000) which gets all the information on linked server tables. This stored procedure references 'sys.fn_remote_tables', so I tried using it:
This didn't work, and returned the following error:
A google search on 'fn_remote_tables' returned absolutely nothing. Is this a phantom function? I couldn't find the function in SQL server either.
Anyone know how to return the list of tables in a linked server on SQL2005, or fix the above error? Thanks!
Take Care,
Mike
Code:
BEGIN
DECLARE @t_tables TABLE (table_name VARCHAR(255))
DECLARE @s_current_table_name VARCHAR(255)
,@s_sql AS VARCHAR(4000)
DECLARE c_loop CURSOR FOR SELECT table_name
FROM @t_tables
INSERT INTO @t_tables (table_name)
SELECT table_name
FROM master.dbo.SYSREMOTE_TABLES (N'QODBC')
OPEN c_loop
FETCH NEXT FROM c_loop
INTO @s_current_table_name
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @s_sql = 'SELECT * INTO ' + LOWER(@s_current_table_name) + ' FROM QODBC...' + LOWER(@s_current_table_name)
-- EXEC @s_sql
PRINT(@s_sql)
FETCH NEXT FROM c_loop
INTO @s_current_table_name
END
END
Code:
BEGIN
DECLARE @t_tables TABLE (table_name VARCHAR(255))
DECLARE @s_current_table_name VARCHAR(255)
,@s_sql AS VARCHAR(4000)
DECLARE c_loop CURSOR FOR SELECT table_name
FROM @t_tables
INSERT INTO @t_tables (table_name)
SELECT table_name
FROM sys.fn_remote_tables (N'QODBC')
OPEN c_loop
FETCH NEXT FROM c_loop
INTO @s_current_table_name
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @s_sql = 'SELECT * INTO ' + LOWER(@s_current_table_name) + ' FROM QODBC...' + LOWER(@s_current_table_name)
-- EXEC @s_sql
PRINT(@s_sql)
FETCH NEXT FROM c_loop
INTO @s_current_table_name
END
END
Msg 208, Level 16, State 1, Line 1
Invalid object name 'sys.fn_remote_tables'.
A google search on 'fn_remote_tables' returned absolutely nothing. Is this a phantom function? I couldn't find the function in SQL server either.
Anyone know how to return the list of tables in a linked server on SQL2005, or fix the above error? Thanks!
Take Care,
Mike