0

How delete detached database from disk using T-SQL? I want to delete a detached database from my hard disk. What should I do in T-SQL? I want to create a database with the same name and I get this error in Microsoft SQL Server 2014 Management Studio:

Cannot create file 'H:...\Restaurant_Data.mdf' because it already exists. Change the file path or the file name, and retry the operation.
Poorya
  • 11
  • 3

1 Answers1

0

There are at least three ways:

  1. Attach the database and drop it
  2. Log-in interactively on the server and delete the files from the disk
  3. Use xp_cmdshell (after enabling it), but don't forget to disable it (if it's not needed)
Razvan Socol
  • 5,426
  • 2
  • 20
  • 32