# Drop Database

## KIỂM TRA TRẠNG THÁI DATABASES

```sql
-- Code kiểm tra trạng thái các database
select * from sys.databases

---------------------------------------
```

## DROP DATABASE

1. Drop 1 database

```sql
DROP DATABASE TEN_DATABASE
```

2. Drop nhiều databases

```sql
-- Xóa nhiều database ngoại trừ database hệ thống
-- Khai báo tên database cần xóa (chỉ mang tính ví dụ, bạn cần thay đổi)
DECLARE @DatabaseName NVARCHAR(255)

-- Khai báo một cursor để lặp qua các database cần xóa
DECLARE db_cursor CURSOR FOR
SELECT name FROM sys.databases WHERE name not IN ('master', 'model', 'tempdb','msdb');

OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @DatabaseName

WHILE @@FETCH_STATUS = 0
BEGIN
    -- Xóa database
    EXEC('DROP DATABASE ' + @DatabaseName)
    PRINT 'Đã xóa database: ' + @DatabaseName

    FETCH NEXT FROM db_cursor INTO @DatabaseName
END

CLOSE db_cursor
DEALLOCATE db_cursor
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kythuat.dtechvn.com/sql-server/drop-database.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
