SQL 什么是 DDL 和 DML?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2578194/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What are DDL and DML?
提问by Sachindra
I have heard the terms DDL and DML in reference to databases, but I don't understand what they are.
我听说过有关数据库的术语 DDL 和 DML,但我不明白它们是什么。
What are they and how do they relate to SQL?
它们是什么以及它们与 SQL 有何关系?
采纳答案by Terry
More information see here: MySQL What is DDL, DML and DCL?, the original is as follows:
更多信息请参见此处:MySQL 什么是 DDL、DML 和 DCL?,原文如下:
DDL
DDL is short name of Data Definition Language, which deals with database schemas and descriptions, of how the data should reside in the database.
- CREATE – to create database and its objects like (table, index, views, store procedure, function and triggers)
- ALTER – alters the structure of the existing database
- DROP – delete objects from the database
- TRUNCATE – remove all records from a table, including all spaces allocated for the records are removed
- COMMENT – add comments to the data dictionary
- RENAME – rename an object
DML
DML is short name of Data Manipulation Language which deals with data manipulation, and includes most common SQL statements such SELECT, INSERT, UPDATE, DELETE etc, and it is used to store, modify, retrieve, delete and update data in database.
- SELECT – retrieve data from the a database
- INSERT – insert data into a table
- UPDATE – updates existing data within a table
- DELETE – Delete all records from a database table
- MERGE – UPSERT operation (insert or update)
- CALL – call a PL/SQL or Java subprogram
- EXPLAIN PLAN – interpretation of the data access path
- LOCK TABLE – concurrency Control
DCL
DCL is short name of Data Control Language which includes commands such as GRANT, and mostly concerned with rights, permissions and other controls of the database system.
- GRANT – allow users access privileges to database
- REVOKE – withdraw users access privileges given by using the GRANT command
TCL
TCL is short name of Transaction Control Language which deals with transaction within a database.
- COMMIT – commits a Transaction
- ROLLBACK – rollback a transaction in case of any error occurs
- SAVEPOINT – to rollback the transaction making points within groups
- SET TRANSACTION – specify characteristics for the transaction
数据线
DDL 是数据定义语言的简称,它处理数据库模式和描述,数据应该如何驻留在数据库中。
- CREATE – 创建数据库及其对象,如(表、索引、视图、存储过程、函数和触发器)
- ALTER – 改变现有数据库的结构
- DROP – 从数据库中删除对象
- TRUNCATE – 从表中删除所有记录,包括为记录分配的所有空间都被删除
- COMMENT – 向数据字典添加注释
- RENAME – 重命名对象
数据管理语言
DML是处理数据操作的Data Manipulation Language的简称,包括最常见的SELECT、INSERT、UPDATE、DELETE等SQL语句,用于存储、修改、检索、删除和更新数据库中的数据。
- SELECT – 从数据库中检索数据
- INSERT – 将数据插入表中
- UPDATE – 更新表中的现有数据
- DELETE – 从数据库表中删除所有记录
- MERGE – UPSERT 操作(插入或更新)
- CALL – 调用 PL/SQL 或 Java 子程序
- EXPLAIN PLAN – 数据访问路径的解释
- LOCK TABLE – 并发控制
DCL
DCL是Data Control Language的简称,包括GRANT等命令,主要涉及对数据库系统的权限、权限等控制。
- GRANT – 允许用户访问数据库的权限
- REVOKE – 撤销使用 GRANT 命令授予的用户访问权限
TCL
TCL 是事务控制语言的简称,它处理数据库中的事务。
- COMMIT – 提交事务
- ROLLBACK – 发生任何错误时回滚事务
- SAVEPOINT – 回滚组内的交易制作点
- SET TRANSACTION – 指定交易的特征
回答by Pascal MARTIN
DDLis Data Definition Language: it is used to define data structures.
DDL是数据定义语言:它用于定义数据结构。
For example, with SQL, it would be instructions such as create table
, alter table
, ...
例如,对于 SQL,它将是诸如create table
, alter table
, ...
DMLis Data Manipulation Language: it is used to manipulate data itself.
DML是数据操作语言:它用于操作数据本身。
For example, with SQL, it would be instructions such as insert
, update
, delete
, ...
例如,对于 SQL,它将是诸如insert
, update
, delete
, ... 之类的指令。
回答by Raju
DDLis Data Definition Language :Specification notation for defining the database schema. It works on Schema level.
DDL是数据定义语言:用于定义数据库模式的规范符号。它适用于架构级别。
DDL commands are:
DDL 命令是:
create,drop,alter,rename
create,drop,alter,rename
For example:
例如:
create table account (
account-number char(10),
balance integer);
DMLis Data Manipulation Language.It is used for accessing and manipulating the data.
DML是数据操作语言,用于访问和操作数据。
DML commands are:
DML 命令是:
select,insert,delete,update,call
For example :
例如 :
update account set balance = 1000 where account_number = 01;
回答by JegsVala
DDL, Data Definition Language
DDL,数据定义语言
- Create and modify the structure of database object in a database.
- These database object may have the Table, view, schema, indexes....etc
- 在数据库中创建和修改数据库对象的结构。
- 这些数据库对象可能有表、视图、架构、索引......等
e.g.:
例如:
CREATE
,ALTER
,DROP
,TRUNCATE
,COMMIT
, etc.
CREATE
,ALTER
,DROP
,TRUNCATE
,COMMIT
,等。
DML, Data Manipulation Language
DML,数据操作语言
DML statement are affect on table. So that is the basic operations we perform in a table.
DML 语句对表有影响。这就是我们在表中执行的基本操作。
- Basic crud operation are perform in table.
- These crud operation are perform by the
SELECT
,INSERT
,UPDATE
, etc.
- 基本的 crud 操作在表中执行。
- 这些污物操作由执行
SELECT
,INSERT
,UPDATE
等。
Below Commands are used in DML:
以下命令用于 DML:
INSERT
,UPDATE
,SELECT
,DELETE
, etc.
INSERT
,UPDATE
,SELECT
,DELETE
,等。
回答by Satish Patel
In layman terms suppose you want to build a house, what do you do.
通俗地说,假设你想盖房子,你会怎么做。
DDL
i.e Data Definition Language
DDL
即数据定义语言
- Build from scratch
- Rennovate it
- Destroy the older one and recreate it from scratch
- 从头开始构建
- 翻新它
- 摧毁旧的并从头开始重新创建
that is
那是
CREATE
ALTER
DROP & CREATE
CREATE
ALTER
DROP & CREATE
DML
i.e. Data Manipulation Language
DML
即数据操作语言
People come/go inside/from your house
人们进/进/出你的房子
SELECT
DELETE
UPDATE
TRUNCATE
SELECT
DELETE
UPDATE
TRUNCATE
DCL
i.e. Data Control Language
DCL
即数据控制语言
You want to control the people what part of the house they are allowed to access and kind of access.
您想控制人们允许他们进入房屋的哪个部分以及进入的类型。
GRANT PERMISSION
GRANT PERMISSION
回答by Uc.IT_samuel
DML is abbreviation of Data Manipulation Language. It is used to retrieve, store, modify, delete, insert and update data in database.
Examples: SELECT, UPDATE, INSERT statements
DDL is abbreviation of Data Definition Language. It is used to create and modify the structure of database objects in database.
Examples: CREATE, ALTER, DROP statements
DML 是Data Manipulation Language 的缩写。它用于检索、存储、修改、删除、插入和更新数据库中的数据。
示例:SELECT、UPDATE、INSERT 语句
DDL 是数据定义语言的缩写。它用于在数据库中创建和修改数据库对象的结构。
示例:CREATE、ALTER、DROP 语句
Visit this site for more info: http://blog.sqlauthority.com/2008/01/15/sql-server-what-is-dml-ddl-dcl-and-tcl-introduction-and-examples/
访问此站点以获取更多信息:http: //blog.sqlauthority.com/2008/01/15/sql-server-what-is-dml-ddl-dcl-and-tcl-introduction-and-examples/
回答by Chinmoy
DDL is Data Definition Language: Just think you are defining the DB.
So we use CREATE,ALTER TRUNCATE commands.
DML is after defining we are Manipulating the data. So we use SELECT,INSERT, UPDATE, DELETE command.
DDL 是数据定义语言:只是认为您正在定义数据库。所以我们使用 CREATE,ALTER TRUNCATE 命令。
DML 是在定义我们正在操作数据之后。所以我们使用SELECT、INSERT、UPDATE、DELETE命令。
Remember DDL commands are auto-committed. You don't need to use COMMIT statements.
DML (Data Manipulation Language) commands need to be commited/rolled back.
记住 DDL 命令是自动提交的。您不需要使用 COMMIT 语句。
DML(数据操作语言)命令需要提交/回滚。
回答by Dorian
DDL: Change the schema
DDL:更改架构
DML: Change the data
DML:更改数据
Seems specific to MySQL limitations (rails's source code)
似乎特定于 MySQL 限制(rails 的源代码)
回答by Sakib
In simple words.
用简单的话来说。
DDL(Data definition language): will work on structure of data. define the data structures.
DDL(数据定义语言):将研究数据结构。定义数据结构。
DML (data manipulation language): will work on data. manipulates the data itself
DML(数据操作语言):将处理数据。操作数据本身
回答by Michael Buen
DDL= Data Definition Language, any commands that provides structure and other information about your data
DDL= 数据定义语言,任何提供数据结构和其他信息的命令
DML= Data Manipulation Language, there's only 3 of them, INSERT, UPDATE, DELETE. 4, if you will count SELECT * INTO x_tbl from tbl
of MSSQL (ANSI SQL: CREATE TABLE x_tbl AS SELECT * FROM tbl
)
DML= Data Manipulation Language,只有三种,INSERT、UPDATE、DELETE。4,如果你算上SELECT * INTO x_tbl from tbl
MSSQL的(ANSI SQL: CREATE TABLE x_tbl AS SELECT * FROM tbl
)