Execute DDL using openquery

Is it possible to run DDL statements using openquery? I want to drop a table on a linked server.  I tried the following 2 types of syntax, neither of which worked:

drop table OPENQUERY(server2, 'SELECT * FROM myDB.dbo.tablename')
select * from OPENQUERY(server2, 'DROP TABLE myDB.dbo.tablename')

I'm running on server1, and I want to drop a table on server2 (both servers are sql server) in the myDB database. If not openquery, is there another way to do it from server1?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Aneesh RetnakaranDatabase AdministratorCommented:
OPENQUERY is a row-set function. You have to use it with SELECT, INSERT, UPDATE or DELETE. in case you wish to run a ddl statement, you must retrun something
select *
from openquery (server2, 'drop table myDB.dbo.tablename; select @@error')
On my system the solution from aneeshattingal didn't create the table

exec server2.master.dbo.sp_executesql ' drop table mydb.dbo.tablename'

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
(rpc must be enable on the link server)
jcpwAuthor Commented:
Unfortunately, the security on our system is set up so that I cannot run that query. I also cannot run DDL on the server that I wanted to. But I will take your word for it that it works.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.