菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
342
0

DDL DML DQL DCL TCL

原创
05/13 14:22
阅读数 52351

遍查网上关于SQL语言分类的情况,有对有错,经Adam验证,共分为四大类(及TCL):

数据查询语言DQL,(data query Language)

select

 

DML statements are used for performing queries on the data within schema objects. The purpose of DQL Command is to get some schema relation based on the query passed to it.

 

Example of DQL:

 

  • SELECT – is used to retrieve data from the a database.

 

SELECT 列名称 FROM 表名称

数据操纵语言DML,(data manipulation language)

INSERT,UPDATE,DELETE,EXPLAIN PLAN 也是

DML(Data Manipulation Language) : The SQL commands that deals with the manipulation of data present in the database belong to DML or Data Manipulation Language and this includes most of the SQL statements.

Examples of DML:

  • INSERT – is used to insert data into a table.
  • UPDATE – is used to update existing data within a table.
  • DELETE – is used to delete records from a database table.

1) 插入:INSERT
2) 更新:UPDATE
3) 删除:DELETE

UPDATE 表名称 SET 列名称 = 新值 WHERE 列名称 = 某值
INSERT INTO table_name (列1, 列2,...) VALUES (值1, 值2,....)
DELETE FROM 表名称 WHERE 列名称 =

数据定义语言DDL,(data definition language)

CREATE,ALTER,DROP,TRUNCATE,COMMENT 

用来创建数据库中的各种对象-----表、视图、
DDL操作是隐性提交的!不能rollback 

DDL(Data Definition Language) : DDL or Data Definition Language actually consists of the SQL commands that can be used to define the database schema. It simply deals with descriptions of the database schema and is used to create and modify the structure of database objects in the database.

Examples of DDL commands:

  • CREATE – is used to create the database or its objects (like table, index, function, views, store procedure and triggers).
  • DROP – is used to delete objects from the database.
  • ALTER-is used to alter the structure of the database.
  • TRUNCATE–is used to remove all records from a table, including all spaces allocated for the records are removed.
  • COMMENT –is used to add comments to the data dictionary.
  • RENAME –is used to rename an object existing in the database.
CREATE TABLE 表名称
(
列名称1 数据类型,
列名称2 数据类型,
列名称3 数据类型,
....
)

ALTER TABLE table_name
ALTER COLUMN column_name datatype

DROP TABLE 表名称
DROP DATABASE 数据库名称

数据库控制语言DCL。(Database Control Language)

GRANT,REVOKE

是用来设置或更改数据库用户或角色权限的语句,包括(grant,deny,revoke等)语句。这个比较少用到。

1) GRANT:授权。

2) ROLLBACK [WORK] TO [SAVEPOINT]:回退到某一点。
回滚---ROLLBACK
回滚命令使数据库状态回到上次最后提交的状态。其格式为:
SQL>ROLLBACK;

 DCL(Data Control Language) : DCL includes commands such as GRANT and REVOKE which mainly deals with the rights, permissions and other controls of the database system.

Examples of DCL commands:

  • GRANT-gives user’s access privileges to database.
  • REVOKE-withdraw user’s access privileges given by using the GRANT command.

存储过程控制预言TCL(Transaction Control Language)

COMMIT,SAVEPOINT,ROLLBACK,SET TRANSACTION

TCL(transaction Control Language) : TCL commands deals with the transaction within the database.

Examples of TCL commands:

  • COMMIT– commits a Transaction.
  • ROLLBACK– rollbacks a transaction in case of any error occurs.
  • SAVEPOINT–sets a savepoint within a transaction.
  • SET TRANSACTION–specify characteristics for the transaction.

 

 

 

 

============================================================

这里的内容有冲突,以黄色为准

 

 

 

提交数据有三种类型:显式提交、隐式提交及自动提交

(1) 显式提交
用COMMIT命令直接完成的提交为显式提交。其格式为:
SQL>COMMIT;

(2) 隐式提交
用SQL命令间接完成的提交为隐式提交。这些命令是:
ALTER,AUDIT,COMMENT,CONNECT,CREATE,DISCONNECT,DROP,
EXIT,GRANT,NOAUDIT,QUIT,REVOKE,RENAME。

(3) 自动提交
若把AUTOCOMMIT设置为ON,则在插入、修改、删除语句执行后,
系统将自动进行提交,这就是自动提交。其格式为:
SQL>SET AUTOCOMMIT ON

 

发表评论

0/200
342 点赞
0 评论
收藏