In SQL Server Management Studio, I have created a linked server to another SQL Server. The name of the linked server that I created is "linkedserver". The linked server uses the Microsoft OLE DB provider. However, the problem described below occurs also with other providers.
In the remote SQL server there is a database [db] and a table [table] in the schema [schema]. [table] has two columns, [column] and [column2].
I have an SQL user 'user' in the remote SQL server which has only read rights, only for [column] but no for [column2]. The problem is that When I try to query data like the example below I get an error that I do not have access in [column2], although [column2] does not appear in the query. My work around is to create openqueries instead but this is not handy.
-- Fetch one column via the linked server - DOES NOT WORK
SELECT TOP 1 [column]
FROM [linkedserver].[db].[schema].[table]
The error message of the first failing query is:
Msg 2557, Level 16, State 7, Procedure sp_table_statistics2_rowset, Line 105
User 'user' does not have permission to run DBCC SHOW_STATISTICS for object '[db].[schema].[table]'.Msg 230, Level 14, State 1, Procedure sp_table_statistics2_rowset, Line 105
The SELECT permission was denied on the column 'column2' of the object 'table', database 'db', schema 'schema'.
The workaround with openquery is:
-- Fetch one column via the linked server through an openquery - WORKS
SELECT *
FROM OpenQuery (linkedserver
'SELECT TOP 1 [column]
FROM [db].[schema].[table]')
Do you know how to overcome this, or why is this done? My assumption is that the first query tries to fetch all columns of [table] and the apply the filter in SQL Manager Studio. Am I right on it? Can I overcome this problem somehow?