Delete Data or Log Files from a Database
Applies to: SQL Server Azure SQL Managed Instance
This topic describes how to delete data or log files in SQL Server by using SQL Server Management Studio or Transact-SQL.
In This Topic
Before you begin:
To delete data or logs files from a database, using:
Before You Begin
Prerequisites
- A file must be empty before it can be deleted. For more information, see Shrink a File.
Security
Permissions
Requires ALTER permission on the database.
Using SQL Server Management Studio
To delete data or log files from a database
In Object Explorer, connect to an instance of the SQL Server Database Engine and then expand that instance.
Expand Databases, right-click the database from which to delete the file, and then click Properties.
Select the Files page.
In the Database files grid, select the file to delete and then click Remove.
Click OK.
Using Transact-SQL
To delete data or log files from a database
Connect to the Database Engine.
From the Standard bar, click New Query.
Copy and paste the following example into the query window and click Execute. This example removes the file
test1dat4
.
USE master;
GO
ALTER DATABASE AdventureWorks2022
REMOVE FILE test1dat4;
GO
For more examples, see ALTER DATABASE File and Filegroup Options (Transact-SQL).
See Also
Phản hồi
https://aka.ms/ContentUserFeedback.
Sắp ra mắt: Trong năm 2024, chúng tôi sẽ dần gỡ bỏ Sự cố với GitHub dưới dạng cơ chế phản hồi cho nội dung và thay thế bằng hệ thống phản hồi mới. Để biết thêm thông tin, hãy xem:Gửi và xem ý kiến phản hồi dành cho