mirror of
https://github.com/allankoechke/turso.git
synced 2026-12-01 01:27:37 +00:00
Comprehensive SQL reference at docs/sql-reference/ covering all supported statements, functions, expressions, PRAGMAs, and extensions. Includes mdBook-based local preview (./preview.sh). Turso-specific features (CDC, materialized views, custom types, MVCC, vector search, FTS, encryption) are integrated inline with callouts. Experimental features link to a dedicated page with enablement instructions for the CLI and all SDKs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
57 lines
1.3 KiB
Plaintext
57 lines
1.3 KiB
Plaintext
---
|
|
title: DETACH DATABASE
|
|
description: Remove an attached database from the current connection
|
|
sidebarTitle: DETACH DATABASE
|
|
---
|
|
|
|
# DETACH DATABASE
|
|
|
|
The DETACH DATABASE statement removes a previously attached database from the current connection. After detaching, tables in that database are no longer accessible through the schema name.
|
|
|
|
## Syntax
|
|
|
|
```sql
|
|
DETACH [DATABASE] schema-name;
|
|
```
|
|
|
|
## Description
|
|
|
|
DETACH closes the connection to the attached database identified by `schema-name` and frees its resources. Any subsequent references to `schema-name.table-name` will fail.
|
|
|
|
### Clauses
|
|
|
|
| Clause | Description |
|
|
|--------|-------------|
|
|
| `DATABASE` | Optional keyword. Has no effect on behavior. |
|
|
| `schema-name` | The schema name assigned when the database was attached. |
|
|
|
|
The `main` and `temp` schemas cannot be detached.
|
|
|
|
<Info>
|
|
DETACH cannot be used while a transaction is active. Commit or roll back any open transaction before detaching a database.
|
|
</Info>
|
|
|
|
## Examples
|
|
|
|
### Detach a Database
|
|
|
|
```sql
|
|
ATTACH 'archive.db' AS archive;
|
|
|
|
-- Use the attached database
|
|
SELECT count(*) FROM archive.events;
|
|
|
|
-- Detach when done
|
|
DETACH DATABASE archive;
|
|
```
|
|
|
|
### Detach Without the DATABASE Keyword
|
|
|
|
```sql
|
|
DETACH archive;
|
|
```
|
|
|
|
## See Also
|
|
|
|
- [ATTACH DATABASE](/docs/sql-reference/statements/attach-database) for attaching a database
|