跳至正文內容
TursoDB.cn 獨立社群 · MVCC 並行寫入與每 Agent 獨立庫實戰 閱讀解析 →
Turso Database SQL 參考 SQL 語句

DROP TYPE

從資料庫移除使用者自訂的型別

DROP TYPE

注意

Turso 擴充功能:DROP TYPE 是 Turso 專屬的陳述式,標準 SQLite 並未提供。此功能為實驗性,必須先啟用才能使用。

DROP TYPE 陳述式會從資料庫移除使用者自訂的型別。型別一經移除,其名稱就無法再用於新的欄位定義。

語法

DROP TYPE [IF EXISTS] type-name;

說明

DROP TYPE 會從資料庫移除具名的自訂型別。除非指定 IF EXISTS 子句,否則該型別必須存在。

子句

子句 說明
IF EXISTS 抑制型別不存在時會發生的錯誤。找不到該型別時,此陳述式不會執行任何操作。
type-name 要移除的自訂型別名稱。

限制

當任何資料表欄位使用某型別時,就無法移除該型別。必須先移除該型別的所有欄位,或先移除資料表,才能移除該型別。

CREATE TYPE cents BASE integer ENCODE value * 100 DECODE value / 100;

CREATE TABLE prices (
    id INTEGER PRIMARY KEY,
    amount cents
) STRICT;

-- This fails because the 'prices' table has a column of type 'cents'
DROP TYPE cents;
-- Error: type 'cents' is in use

-- Drop the table first, then the type
DROP TABLE prices;
DROP TYPE cents;

範例

移除自訂型別

CREATE TYPE reversed_text BASE text
    ENCODE turso_reverse(value)
    DECODE turso_reverse(value);

DROP TYPE reversed_text;

使用 IF EXISTS 移除型別

-- Safe to run even if the type does not exist
DROP TYPE IF EXISTS reversed_text;

另請參閱

同步自官方 Turso 文件倉庫 ( tursodatabase/turso-docs · MIT 開源授權) 檢視官方原文 ↗
搜尋
按 Esc 關閉 · 由 Pagefind 靜態索引驅動