1

How do I create an index on a table that exist in a remote SQL Server database using the openquery syntax?

Dan
  • 871
  • 1
  • 9
  • 13

2 Answers2

1

You can't on your side. The index must be added to a local object only. You can't use an indexed view either.

You can ask the other party to add an index for you to their table...

Edit: Expanding John's answer... You could try:

SELECT * FROM OPENQUERY(LinkedServer, 'CREATE INDEX etc;SELECT 0 AS foobar')
gbn
  • 422,506
  • 82
  • 585
  • 676
0

I'm not certain however I suspect that this cannot be done.

OPENQUERY is intended to return a Result Set and so is unlikely to accept DDL statements.

See the Microsoft Books Online reference for examples of acceptable usage scenarios.

http://technet.microsoft.com/en-us/library/ms188427.aspx

John Sansom
  • 41,005
  • 9
  • 72
  • 84