[Oracle] The difference and understanding of DDL, DML and DCL

DML, DDL, DCL difference .

General explanation:

DML (data manipulation language):
They are SELECT, UPDATE, INSERT, DELETE, just like its name, these 4 commands are used to manipulate the data in the database language
DDL (data definition language):
DDL is more than DML, the main commands are CREATE, ALTER, DROP, etc., DDL is mainly used to define or change the structure of the table (TABLE), data types, links and constraints between tables, etc. In the initialization work, most of them use
DCL (Data Control Language) when creating tables : it
is a database control function. It is a statement used to set or change the permissions of a database user or role, including (grant, deny, revoke, etc.) statements. In the default state, only sysadmin, dbcreator, db_owner or db_securityadmin and other personnel have the right to execute DCL

detailed explanation:

1. DDL is Data Definition Language statements. Some examples: data definition language, used to define and manage all objects in the SQL database language
1.CREATE - to create objects in the database to create
2.ALTER - alters the structure of the database modifications
3.DROP - delete objects from the database to delete
4. TRUNCATE-remove all records from a table, including all spaces allocated for the records are removed
TRUNCATE TABLE [Table Name].
  The following is an explanation of the usage and principle of the Truncate statement in MSSQLServer2000:
  Truncate table table name is fast and efficient, because:
  TRUNCATE TABLE is functionally the same as the DELETE statement without the WHERE clause: both delete the table All lines. But TRUNCATE TABLE is faster than DELETE, and it uses fewer system and transaction log resources.
  The DELETE statement deletes one row at a time, and records one item in the transaction log for each row deleted. TRUNCATE TABLE deletes data by releasing data pages used to store table data, and only records the release of pages in the transaction log.
  TRUNCATE TABLE deletes all rows in the table, but the table structure and its columns, constraints, indexes, etc. remain unchanged. The count value used for the new row identification is reset to the seed of the column. If you want to keep the mark count value, use DELETE instead. If you want to delete the table definition and its data, use the DROP TABLE statement.
  For tables referenced by FOREIGN KEY constraints, TRUNCATE TABLE cannot be used, but DELETE statements without WHERE clauses should be used. Since TRUNCATE TABLE is not recorded in the log, it cannot activate triggers.
  TRUNCATE TABLE cannot be used for tables that participate in indexed views.
5.COMMENT-add comments to the data dictionary
6. GRANT-gives user's access privileges to database authorization
7. REVOKE-withdraw access privileges given with the GRANT command

2. DML is Data Manipulation Language statements. Some examples: data manipulation language, data processing in SQL and other operations Collectively referred to as data manipulation language

1. SELECT-retrieve data from the a database query
2. INSERT-insert data into a table add
3. UPDATE-updates existing data within a table update
4. DELETE-deletes all records from a table, the space for the records remain deleted
5. CALL-call a PL/SQL or Java subprogram
6. EXPLAIN PLAN-explain access path to data
Every SQL statement executed by Oracle RDBMS must be evaluated by the Oracle optimizer. Therefore, understanding how the optimizer chooses (search) paths and how the index is used is of great help in optimizing SQL statements. Explain can be used to quickly and easily find out how the query data in a given SQL statement is obtained, that is, the search path (we usually call it Access Path). So that we can choose the best query method to achieve the greatest optimization effect.
7. LOCK TABLE-control concurrency lock, used to control concurrency

Three, DCL is Data Control Language statements. Some examples: data control language, used to grant or reclaim certain privileges to access the database, and control the time when the database manipulation transaction occurs and Effect, monitor the database, etc.

1. COMMIT-save work done
2. SAVEPOINT-identify a point in a transaction to which you can later roll back
3. ROLLBACK-restore database to original since the last COMMIT
4. SET TRANSACTION-Change transaction options like what rollback segment to use Set the characteristics of the current transaction, it has no effect on subsequent transactions.

The understanding of DDL, DML and DCL (Zhang Qingshan)

first give a picture:




 

1 、 DDL

      1-1. Overview of
               DDL DDL (Data Definition Language) is used to manipulate objects and object attributes. Such objects include the database itself, as well as database objects, such as tables, views, etc., for these objects and attributes. The management and definition of the specific manifestations in Create, Drop and Alter. Special attention: The concept of "object" in DDL operations, "object" includes objects and their attributes, and the smallest object is also a level larger than the record. Take a table as an example: Create creates a data table, Alter can change the fields of the table, Drop can delete this table, from here we can see that the height of the DDL station, he will not operate on specific data.

      1-2, DDL's main statement (operation)
               Create statement: You can create a database and some objects of the database.
               Drop statement: You can delete data tables, indexes, triggers, conditional constraints, and data table permissions.
               Alter statement: modify the definition and attributes of the data table.
      1-3. Operation object of DDL (table)
               1-3-1. Concept of
                           table The creation of table is used to store data. Because the data we store is not available, we need to define some data types to facilitate management .
               1-3-2, table attributes   
                           Primary key attribute: The primary key is the primary key constraint, but the name is different. The name of the primary key is biased to virtual (that is to describe the thing), and the name of the primary key constraint is biased to the actual (that is to describe the implementation of the operation), and the description is all It is the same thing, the primary key constraint is an attribute in the table; there can be at most one primary key in a table; a primary key can be defined in one or more fields; the primary key makes the value of one or more fields must be unique and not empty In this way, a record can be uniquely represented by the value in the field or the group of fields.
                           Unique attribute: There can only be one primary key attribute in a table. For the user of the table, a unique constraint is proposed; the unique constraint can be defined on one or more fields; the unique constraint makes the value in the field or group of fields unique, which can be Empty, however, cannot be repeated.
                           Foreign key attribute: also called foreign key, also called foreign key constraint, and the relationship between primary key and primary key constraint is the same; foreign key constraint is for two tables, if the primary key of table A is a field in table B, then This field is called the foreign key of table B, table A is called the master table, and table B is called the slave table, but note that the computer must know that you are in this relationship.

               Verification, Null and default attributes: Verification attributes are also called verification constraints, Null attributes are also called Null constraints, and default attributes are also called default constraints; these names describe one thing, describe a situation, this matter or this Of course, we can deliberately do it artificially (just pay attention to input data), but their original intention is to automate, that is, let the computer do this.
            (Do you know why the index is automatically created when the primary key and unique constraint are created? And it is a unique index. Think about the index is mostly used on those fields, and the role of the index will know. Like primary key constraints, unique constraints , Non-empty constraints, foreign key constraints, verification constraints, and default constraints are all operations that make the table have certain characteristics, so here I think they are all table attributes.)

2. DML

      2-1. Overview of
               DML DML (Data Manipulation Language) is used to manipulate the data contained in database objects, that is to say, the unit of operation is a record.
      2-2. The main statement (operation) of DML.
               Insert statement: Insert a record into the data table.
               Delete statement: Delete one or more records in the data table, or delete all records in the data table, but its operation object is still a record.
               Update statement: used to modify the content of a record in the existing table.
      2-3. The operation object of DML-record
               2-3-1. Note that
                           when we perform Insert, Delete and Update operations on the record, we must pay attention and we must be clear about some operations of DDL.

3. DCL

       3-1. Overview of
                DCL The operation of DCL (Data Control Language) is the authority of database objects, and the determination of these operations makes the data more secure.
       3-2. The main statement (operation) of DCL
                Grant statement: Allow the creator of the object to grant certain permissions to a certain user or a certain group or all users (PUBLIC).
                Revoke statement: You can revoke the access rights of a certain user or a certain group or all users.
       3-3. The operation object (user) of DCL.
                At this time, the user refers to the database user. 

Reference article

https://www.cnblogs.com/qxqbk/p/7240195.html

Guess you like

Origin blog.csdn.net/xiaoxiao_su123/article/details/114268045