目录
一.DDL 数据定义语言
-
对数据库的常用操作
-
对表结构的常用操作
-
修改表结构
1.操作数据库
create database if not exists 数据库名; drop database if exists 数据库名; use 数据库名; show databases; alter database 数据库名 character set utf8;
2.数据库表的操作
create table if not exists student( sid int, name varchar(20), gender varchar(20) ); show tables; show create table student; desc student; drop table student; -- 修改列名和表名,alter table 表名 change 旧列名 新列名 类型(长度) [约束] alter table student add column dept varchar(20); alter table 表名 drop 列名; rename table 表名 to 新表名;
二.DML是指数据操作语言(插入删除更新)
用来对数据库中标的数据几列进行更新。
插入Insert
删除delete
更新update
insert into 表(列名1,列表2,列表3...) values(值1,值2,值3...);// 向表中插入某些 insert into 表 values(值1,值2,值3...);// 向表中插入所有列 update 表名 set 字段名=值,字段名=值...; update 表名 set 字段名=值,字段名=值... where 条件; delete from 表名[where 条件]; truncate table 表名 或者truncate 表名
三.DQL查询
select [all|distinct] <目标列的表达式1> [别名], <目标列的表达式2> [别名]... from <表名或视图名> [列名],<表名或视图名> [别名]... [where<条件表达式>] [group by<列名> [having<条件表达式>]] [order by<列名>[asc|desc]] [limit<数字或者列表>]; select *| 列名 from 表 where 条件
四.多表查询
外键约束
内连接
子查询