一、DDL、DML、DCL常用语句 

1、DDL(Data Definition Language)数据库定义语言

(1)数据库模式定义

复制代码
#创建数据库   create database if exsites db_name;  #选定数据库 use db_name;  #删除数据库 drop database if exists db_name;  #修改数据库 alter database db_name set ...;  #展示所创建的数据库 show databases;
复制代码

 

(2)表定义    

复制代码
#创建表 create table test_table ( s_id int not null auto_increment, s_name char(50) not null default "hanmei", s_age int not null, primary key(s_id), index index_name(s_name) );  #删除表 drop table if exists test_table;   #展示表结构 desc test_table;
复制代码

 

2、DML(data manipulation language)数据库操作语言

复制代码
insert into test_table(s_age) values(18);  insert into test_table set s_age=19; #插入部分列值数据  inert ...select...;  #case...when 匹配条件 select s_name as name,s_sex case  when  'f' then ‘女’   else ''end as sex from test_table;  #使用内置函数 select count(*) from customers; select max(cust_id) from customers; select min(cust_id) from customers; select sum(cust_id) from customers; select avg(cust_id) from customers;    #