DDL (Data Definition Language)數據定義語言,主要用於改變表的結構,數據類型,表之間的連接和約束等初始化工做上,多用於建表時。主要命令有CREATE,ALTER,DROPmysql
DML(Data Manipulation Language)數據操控語言,主要用於對錶的操做,查詢更新等,經常使用命令爲SELECT ,UPDATE,INSERT,DELETEsql
DCL(Data Control Language)數據控制語言,主要用於設置或者理髮數據庫用戶定義或角色,定義權限的語句,經常使用命令有GRANT,REVOKE數據庫
建立數據庫bash
Mysql[mysql]>CREATE DATABASE TEST; MySQL [mysql]> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | TEST | | mysql | | performance_schema | +--------------------+ 4 rows in set (0.00 sec) MySQL [mysql]> USE TEST; Database changed MySQL [TEST]> CREATE TABLE STUDENTS(NAME CHAR(20) NOT NULL,AGE TINYINT,COURSE CHAR(100)); Query OK, 0 rows affected (0.01 sec) MySQL [TEST]> DESC STUDENTS; +--------+------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+------------+------+-----+---------+-------+ | NAME | char(20) | NO | | NULL | | | AGE | tinyint(4) | YES | | NULL | | | COURSE | char(100) | YES | | NULL | | +--------+------------+------+-----+---------+-------+ 3 rows in set (0.00 sec)
向新建的表中插入數據,格式爲INSERT INTO tb_name (col1,col2,...) VALUES (value1,value2...);能夠一次性插入一個字段,若是全部字段都插入的話,(NAME)能夠省略。
ide
MySQL [TEST]> INSERT INTO STUDENTS (NAME) VALUES ('ZHANGSAN'); Query OK, 1 row affected (0.00 sec) MySQL [TEST]> SELECT * FROM STUDENTS; +----------+------+--------+ | NAME | AGE | COURSE | +----------+------+--------+ | ZHANGSAN | NULL | NULL | +----------+------+--------+ 1 row in set (0.00 sec) INSERT INTO STUDENTS VALUES ('WANGWU',33,'YUWEN'),('LISI',45,'SHUXUE'),('LIMING',32,'ENGLISH'); Query OK, 3 rows affected (0.01 sec) Records: 3 Duplicates: 0 Warnings: 0 MySQL [TEST]> SELECT * FROM STUDENTS; +----------+------+---------+ | NAME | AGE | COURSE | +----------+------+---------+ | ZHANGSAN | NULL | NULL | | WANGWU | 33 | YUWEN | | LISI | 45 | SHUXUE | | LIMING | 32 | ENGLISH | +----------+------+---------+ 4 rows in set (0.00 sec)
修改張三的年齡爲100orm
UPDATE STUDENTS SET AGE=100 WHERE NAME='ZHANGSAN';
修改TABLE STUDENT新增一個字段ADDRESSip
UPDATE TABLE STUDENT ADD ADDRESS CHAR(100);
刪除地址字段it
UPDATE TABLE STUDENT DROP ADDRESS;
刪除姓名爲LISI的行io
DELETE FROM STUDENTS WHERE NAME='LISI';