CREATE SCHEMA
適用於: Databricks SQL Databricks Runtime
建立具有指定名稱的架構(資料庫)。 如果具有相同名稱的架構已經存在,則會擲回例外狀況。
語法
CREATE SCHEMA [ IF NOT EXISTS ] schema_name
[ COMMENT schema_comment ]
[ LOCATION schema_directory | MANAGED LOCATION location_path ]
[ WITH DBPROPERTIES ( { property_name = property_value } [ , ... ] ) ]
參數
-
要建立之架構的名稱。
目錄中建立的
hive_metastore
架構只能包含英數位元 ASCII 字元和底線(INVALID_SCHEMA_OR_RELATION_NAME)。 如果不存在
如果架構不存在,則建立具有指定名稱的架構。 如果具有相同名稱的架構已經存在,則不會發生任何動作。
位置
schema_directory
LOCATION
Unity 目錄不支援。 如果您要在 Unity 目錄中指定架構的儲存位置,請使用MANAGED LOCATION
。schema_directory
是常STRING
值。 要在其中建立指定架構之文件系統的路徑。 如果基礎文件系統中沒有指定的路徑,請建立具有路徑的目錄。 如果未指定位置,則會在預設倉儲目錄中建立架構,其路徑是由靜態組態spark.sql.warehouse.dir
所設定。schema_comment
常
STRING
值。 架構的描述。受控位置
location_path
MANAGED LOCATION
是選擇性的,而且需要 Unity 目錄。 如果您要為工作區層級 Hive 或第三方中繼存放區中註冊的架構指定儲存位置,請改用LOCATION
。location_path
必須是STRING
常值。 指定與目錄或中繼存放區記憶體根位置不同之架構之記憶體根位置的路徑。 此路徑必須在外部位置設定中定義,而且您必須具有CREATE MANAGED STORAGE
外部位置設定的許可權。 您可以使用外部位置組態或子路徑中定義的路徑(換句話說,'abfss://container@storageaccount.dfs.core.windows.net/finance'
或'abfss://container@storageaccount.dfs.core.windows.net/finance/product'
)。 在 Databricks SQL 或執行 Databricks Runtime 11.3 LTS 和更新版本之叢集上支援。另 請參閱受控數據表 和 建立 Unity 目錄中繼存放區。
WITH DBPROPERTIES ( { property_name = property_value } [ , ... ] )
索引鍵/值組中架構的屬性。
OPTIONS
設定連線時識別目錄所需的連線類型特定參數。
option
選項索引鍵。 索引鍵可以包含一或多個 以點分隔的標識碼 ,或
STRING
常值。選項索引鍵必須是唯一的,而且區分大小寫。
value
選項的值。 值必須是
BOOLEAN
、STRING
、INTEGER
或DECIMAL
常數表達式。 此值也可能是 SQL 函式的SECRET
呼叫。 例如,的value
password
可能會組成secret('secrets.r.us', 'postgresPassword')
,而不是輸入常值密碼。
範例
-- Create schema `customer_sc`. This throws exception if schema with name customer_sc
-- already exists.
> CREATE SCHEMA customer_sc;
-- Create schema `customer_sc` only if schema with same name doesn't exist.
> CREATE SCHEMA IF NOT EXISTS customer_sc;
-- Create schema `customer_sc` only if schema with same name doesn't exist with
-- `Comments`,`Specific Location` and `Database properties`. LOCATION is not supported in Unity Catalog.
> CREATE SCHEMA IF NOT EXISTS customer_sc COMMENT 'This is customer schema' LOCATION '/samplepath'
WITH DBPROPERTIES (ID=001, Name='John');
-- Create schema with a different managed storage location than the metastore's. MANAGED LOCATION is supported only in Unity Catalog.
> CREATE SCHEMA customer_sc MANAGED LOCATION 'abfss://container@storageaccount.dfs.core.windows.net/finance';
-- Verify that properties are set.
> DESCRIBE SCHEMA EXTENDED customer_sc;
database_description_item database_description_value
------------------------- --------------------------
Database Name customer_sc
Description This is customer schema
Location hdfs://hacluster/samplepath
Properties ((ID,001), (Name,John))