MySQL's sql language classification DML, DQL, DDL, DCL,

SQL language total is divided into four broad categories: data definition language DDL, data manipulation language DML, data query language DQL, Data Control Language DCL

1. The data definition language DDL (Data Definition Language)

  Object: databases and tables

  Keywords: create alter drop truncate (delete the current table and then create a table structure exactly the same)

  Create a database: create database school;

  Delete the database: drop database school;

  Switching database: use school;

  Create a table: create table student (

      id int(4) primary key auto_increment,

      name varchar(20),

      score int(3)

    );

  View existing database table: show tables;

  note:

    varchar type of a variable length, when creating the table specifies the maximum length, the definition, the maximum value may take any value between 0-65535, but recorded in this range, how many number distribution,

varchar type of the actual space is the actual length of the string plus one. Thus, the system can effectively save space. varchar specific data type is mysql.

    char type of fixed length, when creating the table is specified, the length of which may be any value between 0 and 255. Although char occupy a larger space, but its fast processing speed.

  Modify the table: alter table student rename (to) teacher;

      alter table student add password varchar(20);

      alter table student change password pwd varchar(20);

      alter table student modify pwd int;

      alter table student drop pwd;

  Delete tables: drop table student;

  Check-table sql statement: show create table student;

  View table structure: desc student;

2. The data manipulation language DML (Data Manipulation Language)   

  Object: a record (row)

  Keywords: insert update delete

  Insert: insert into student values ​​(01, 'tonbby', 99); (insert all fields)

     insert into student (id, name) values ​​(01, 'tonbby'); (inserts the specified field)

  更新:update student set name = 'tonbby',score = '99' where id = 01;

  删除:delete from tonbby where id = 01;

  note:

     Development rarely used delete, delete and remove physical tombstone, which can add a tombstone field (isDel) through to the table, if the value of 1 indicates deleted; if the value is 0, representing no deleted.

     In this case, the deletion of data becomes the update operation.

  truncate and delete the difference between:

    truncate table is to delete and re-create the table. Belongs to the DDL, delete the data one by one to delete the table, part of DML.

3. data query language DQL (Data Query Language)

  select ... from student where group by grouping condition having a field order by sort field conditions

  执行顺序:from->where->group by->having->order by->select

  Note: usually polymerizable group by function (avg (), count () ...) used together, often using the first keyword group by group, and then the set operation.

     group by used with having, you can limit the output of the results, the results will only show to satisfy the conditional expression.

  having and where the difference between:

    Both works are not the same place, where acting on the table or view, is the query tables and views. after having applied to the recording packets, for selecting a group satisfies the condition.

4. Data Control Language DCL (Data Control Language)

  Data Control Language or DCL used to grant certain privileges to access the database recovery, and control the time and the effect of manipulating the database transaction occurs, the implementation of surveillance, users, permissions, and other transactions on the database.

  grant: authorization, rollback: rollback. commit: commit.

Guess you like

Origin www.cnblogs.com/changxin7/p/11484260.html