DML, DDL, DCL difference .

DML (data manipulation language): 
they are SELECT, UPDATE, INSERT, DELETE, just like its name, these 4 commands are the language used to manipulate the data in the database 
DDL (data definition language): 
DDL is more than DML To be more, 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 and other initialization work, they are mostly used when creating tables. Use 
DCL (Data Control Language): 
It is a database control function. It is a statement used to set or change database user or role permissions, including (grant, deny, revoke, etc.) statements. By default, only sysadmin, dbcreator, db_owner or db_securityadmin have the authority to execute DCL 

detailed explanations: 

1. DDL is Data Definition Language statements. Some examples: Data Definition Language, used to define and manage all objects in a SQL database 1.CREATE 
- to create objects in the database 
2.ALTER - alters the structure of the database 
3.DROP - delete objects from the database 
4. TRUNCATE - remove all records from a table, including all spaces allocated for the records are removed 
TRUNCATE TABLE [Table Name]. 
  The following is a description 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 data in the table. All rows. But TRUNCATE TABLE is faster than DELETE and uses less system and transaction log resources. 
  The DELETE statement deletes one row at a time and records an entry in the transaction log for each row deleted. TRUNCATE TABLE deletes data by freeing the data pages used to store the table data, and only records the freeing of pages in the transaction log. 
  TRUNCATE TABLE deletes all rows in the table, but leaves the table structure and its columns, constraints, indexes, etc. unchanged. The count value used for new row identification is reset to the seed for this column. If you want to preserve the identity count value, use DELETE instead. If you want to drop the table definition and its data, use the DROP TABLE statement. 
  For tables referenced by FOREIGN KEY constraints, TRUNCATE TABLE cannot be used, but a DELETE statement without a WHERE clause. Since TRUNCATE TABLE is not logged, it cannot activate triggers. 
  TRUNCATE TABLE cannot be used on tables participating 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, etc. 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 - update existing data within a table update 
4. DELETE - deletes all records from a table, the space for the records remain Delete 
5. CALL - call a PL/SQL or Java subprogram 
6. EXPLAIN PLAN - explain access path to data 
Oracle RDBMS executes each SQL statement must be evaluated by the Oracle optimizer. Therefore, understanding how the optimizer chooses (search) paths and how indexes are used can be 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 was obtained, that is, the search path (we usually call it the Access Path). So that we choose the optimal query method to achieve the maximum optimization effect. 
7. LOCK TABLE - control concurrency lock, used to control concurrency 

3. DCL is Data Control Language statements. Some examples: Data Control Language, used to grant or reclaim certain privileges to access the database, and to control the time and time when database manipulation transactions occur. effect, monitor the database, etc. 

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

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

first gives a diagram:





1 、 DDL

      1-1. Overview of
               DDL DDL (Data Definition Language) is used to manipulate objects and attributes of objects, such objects include the database itself, as well as database objects, such as tables, views, etc., DDL is responsible for these objects and attributes The management and definition are embodied 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 larger than the record. Take a table as an example: Create creates a data table, Alter can change the fields of the table, and Drop can delete the table. From here, we can see that the height of the DDL station will not operate on specific data.

      1-2. The main statement (operation) of DDL
               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 data table definition and properties.
      1-3. DDL operation object (table)
               1-3-1. The concept of
                           table The creation of the table is used to store data. Since 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 tends to be virtual (that is, to describe and describe the matter), 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 null , which can uniquely represent a record by the value in that field or group of fields.
                           Unique attribute: There can only be one primary key attribute in a table. For the user of the square table, a unique constraint is proposed; the unique constraint can be defined on one or more fields; the unique constraint makes the value of the field or the group of fields unique, which can be Empty, however, cannot be repeated.
                           Foreign key attribute: also called foreign key, also called foreign key constraint, the relationship with primary key and primary key constraint is the same; the foreign key constraint targets 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 main table, and table B is called the slave table, but it should be noted that the computer must know that you are in this relationship.

               Check, Null, and Default Properties: Check properties are also called check constraints, Null properties are also called Null constraints, and default properties are also called default constraints; these names describe a thing, describe a situation, this event or this Of course, we can do it artificially (just pay attention to input data), but their original intention is to achieve automation, that is, let the computer do it.
            (Do you know why an index is automatically created when a primary key and a unique constraint are established? And it is a unique index. Think about the fields where the index is mostly used, and the function of the index. Like primary key constraints, unique constraints , non-null constraints, foreign key constraints, check constraints and default constraints are the operations that make the table have certain characteristics, so here I think they are the properties of the table.)

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 the record.
      2-2. The main statement (operation) of DML
               Insert statement: Insert a record into the data sheet.
               Delete statement: deletes one or more records in the data table, and can also delete all records in the data table, but its operation object is still the record.
               Update statement: used to modify the content of the records in the existing table.
      2-3. Operational objects of DML - record
               2-3-1. Note that
                           when we perform Insert, Delete and Update operations on records, we must pay attention to some operations of DDL on them.

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 of DCL (operation)
                Grant statement: allows the creator of the object to give a user or a group or all users (PUBLIC) some specific permissions.
                Revoke statement: Can abolish a user or a group or all user access rights
       3-3, DCL operation object (user)
                The user at this time refers to the database user. 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324586411&siteId=291194637