DDL數據庫
數據庫模式定義語言 DDL (Data Definition Language),是用於描述數據庫中要存儲的現實世界實體的語言。一個數據庫模式包含該數據庫中全部實體的描述定義。設計
這些定義包括結構定義、操做方法定義等。索引
數據庫模式定義語言並不是程序設計語言,DDL數據庫模式定義語言是SQL語言(結構化程序設計語言)的組成部分。事務
SQL語言包括四種主要程序設計語言類別的語句:數據定義語言(DDL),數據操做語言(DML),數據控制語言(DCL)和事務控制語言(TCL)。ci
常見的DDL語句it
CREATE DATABASEio
建立數據庫table
CREATE {DATABASE | SCHEMA} db_name程序設計
[create_specification [, create_specification] ...]select
create_specification:
[DEFAULT] CHARACTER SET charset_name
| [DEFAULT] COLLATE collation_name
CREATE TABLE
建立數據庫表格
CREATE [TEMPORARY] TABLE tbl_name
[(create_definition,...)]
[table_options] [select_statement]
ALTER TABLE
修改數據庫表格
ALTER TABLE tbl_name
alter_specification [, alter_specification] ...
alter_specification:
ADD [COLUMN] column_definition [FIRST | AFTER col_name ]
| ADD [COLUMN] (column_definition,...)
| ADD INDEX (index_col_name,...)
| ADD [CONSTRAINT [symbol]]
PRIMARY KEY (index_col_name,...)
| ADD [CONSTRAINT [symbol]]
UNIQUE (index_col_name,...)
| ADD (index_col_name,...)
| ADD [CONSTRAINT [symbol]]
FOREIGN KEY (index_col_name,...)
[reference_definition]
| ALTER [COLUMN] col_name {SET DEFAULT literal | DROP DEFAULT}
| CHANGE [COLUMN] old_col_name column_definition
[FIRST|AFTER col_name]
| MODIFY [COLUMN] column_definition [FIRST | AFTER col_name]
| DROP [COLUMN] col_name
| DROP PRIMARY KEY
| DROP INDEX index_name
| DROP FOREIGN KEY fk_symbol
| DISABLE KEYS
| ENABLE KEYS
| RENAME [TO] new_tbl_name
| ORDER BY col_name
| CONVERT TO CHARACTER SET charset_name [COLLATE collation_name]
| [DEFAULT] CHARACTER SET charset_name [COLLATE collation_name]
| DISCARD TABLESPACE
| IMPORT TABLESPACE
| table_options
DROP TABLE
刪除數據庫表格
DROP [TEMPORARY] TABLE
tbl_name [, tbl_name] ...
[RESTRICT | CASCADE]
CREATE VIEW
建立查詢命令
CREATE [OR REPLACE] [ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}]
VIEW view_name [(column_list)]
AS select_statement
[WITH [CASCADED | LOCAL] CHECK OPTION]
ALTER VIEW
修改查詢命令
ALTER [ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}]
VIEW view_name [(column_list)]
AS select_statement
[WITH [CASCADED | LOCAL] CHECK OPTION]
DROP VIEW
刪除查詢命令
DROP VIEW
view_name [, view_name] ...
[RESTRICT | CASCADE]
TRUNCATE TABLE
刪除數據表內容
TRUNCATE TABLE name [DROP/REUSE STORAGE]
DROP STORAGE:顯式指明釋放數據表和索引的空間
REUSE STORAGE:顯式指明不釋放數據表和索引的空間