最近看了Neflix的后裔弃兵:Those who are busy challenging their fate spare no time complaining about it.
在线学习:老师讲的非常清楚,免费+免费电子书
https://www.imooc.com/learn/1281
常用的数据库与开发语言
框架
DDL:是对数据库+表+列,进行操作(Create 、Alter、Drop、Show 、Desc)
无论是表还是列,都是基于数据库存在的,所以总归是先创建数据库。再创建表,
表的结构与excel相似

3.1.1 Create:新建数据库、表
create database if not exists DBname; #创建一个新的数据库,DBname
use DBname; #进入数据库,DBname
show tables; #查看当前库内所有的表格
Create table if not exists Tablename( #创建表
`字段名1` 列类型(属性) 约束,
`字段名2` 列类型(属性) 约束);desc Tablename; #描述表结构
3.1.2 Alter:设计表
Alter table Tablename add 约束类型 (表字段名); # 创建约束
Alter table Tablename drop index 约束名; #删除约束(不建议使用index)
Alter table Tablename drop primary key; #删除约束
Alter table Tablename drop foreign key 外键名; #删除外键
Alter table 旧表名 rename as 新表名; #修改表名
Alter table Tablename add 字段名 列类型(属性); #添加字段
Alter table Tablename modify 字段名 列类型(属性); #修改字段类型
Alter table Tablename change 旧字段名 新字段名 列类型(属性); #修改字段
Alter table Tablename drop 字段名; #删除字段
3.1.3 Drop:删除库、表、约束
Drop database dbname; #删除库
Drop table Tablename; #删除表
Drop index 约束名 on Tablename; #删除约束
3.1.4 Show:查看所有数据库、表及查看约束
show databases; #查看所有数据库
show tables; #查看库内所有表
Show index(or keys) from Tablename; #查看约束
3.2、DML语句是对数据库中的表,进行操作(Insert、Delete、Update、Select、Truncate)


3.2.1 Select:查询数据
语法:Select field1,field2..fieldn from tablename [where conditions]; #见-2
3.2.2 Updata:更新数据
语法:update tablename set 字段名1=new_value1 字段名2=new_value2 where conditions;
3.2.3 Insert:插入数据
Insert into Tablename [(field1,field2...)] values (value1,value2...); #有字段名插入,值与字段名一一对应
Insert into Tablename values (value1,value2...); #无字段名插入,需包含所有的字段值
Insert into tablename[(feild..)] values (value..),(value..),...,(value..); #多个值的同时插入
sql语句中,对于自动增长的字段名在插入值时可以使用null或default代替,不可留空;
date类型的数据在插入时,用字符串即可
3.2.4 Delete:删除数据,
Delete from Tablename where condition; #根据条件删除数据
Delete from Tablename; #如无条件将删除整张表
3.2.5 Truncate
Truncate [table] Tablename; #清除表数据,但表结构、索引、约束等不变
DQL是对数据表进行,查询,查询专用语句,单独一个分类
SQL子句顺序
SELECT=>FROM=>WHERE=>GROUP BY=>HAVING=>ORDER BY=>LIMIT
Mysql约束
一般设计程序之前,会设计表,总共需要几张表,如何管理,以及权限




