标签:ddl dcl dml
DDL (Data Definition Language)数据定义语言,主要用于改变表的结构,数据类型,表之间的链接和约束等初始化工作上,多用于建表时。主要命令有CREATE,ALTER,DROP
DML(Data Manipulation Language)数据操控语言,主要用于对表的操作,查询更新等,常用命令为SELECT ,UPDATE,INSERT,DELETE
DCL(Data Control Language)数据控制语言,主要用于设置或者理发数据库用户定义或角色,定义权限的语句,常用命令有GRANT,REVOKE
创建数据库
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)可以省略。
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)
修改张三的年龄为100
UPDATE STUDENTS SET AGE=100 WHERE NAME=‘ZHANGSAN‘;
修改TABLE STUDENT新增一个字段ADDRESS
UPDATE TABLE STUDENT ADD ADDRESS CHAR(100);
删除地址字段
UPDATE TABLE STUDENT DROP ADDRESS;
删除姓名为LISI的行
DELETE FROM STUDENTS WHERE NAME=‘LISI‘;
标签:ddl dcl dml
原文地址:http://francis198.blog.51cto.com/720670/1703606