Dropping database on another SQL Server instance

  • Hi,

    I have managed to successfully connect to another SQL Server instance using a linked server.

    I can then do my select statement like this:

    select * from [servername\instancename].[databasename].[databaseowner].[tablename]

    I just wanted to know how I can drop the database on the other instance?

    I have tried doing: DROP DATABASE [servername\instancename].[databasename]

    but it doesn't work and expects a database name.

  • Try this

    EXEC [yourlinkedserver].tempdb.dbo.sp_executesql N'DROP DATABASE Test;';

    Need to ensure RPC is on in the linked server settings

  • i believe the command syntax like this will work as well: i use it for creating tables remotely:

    EXEC ('DROP DATABASE [SandBox]') AT MyLinkedServer

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • They work thanks.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply