
Mysql - 常用CRUD
MySQL数据库
–删除表
DROP TABLE IF EXISTS 表名
–新建表
CREATE table 表面(
字段名 类型 约束(主键,非空,唯一,默认值11111111)
)
CRUD
插入语句
INSERT INTO 表名(xx,xx,xx,xx) VALUES(xx,xx,xx,xx);
删除语句
delete from 表名 where id = x;
更新语句
update 表名 set xx = xx where id = x;
关联查询
内连接
select * from websites w join access_log a
on w.id = a.site_id
where sal>2000
左外连接,以左表为主,另一个表根据主表匹配(主表有多少数据,最终显示多少条数据)
select * from websites w left join access_log a
on w.id=a.site_id
右外连接,以右表为主,另一个表根据主表匹配主表有多少数据,最终显示多少条数据)
select * from websites w right join access_log a
on w.id=a.site_id
全连接
select * from websites w left join access_log a
on w.id=a.site_id
union
select * from websites w right join access_log a
on w.id=a.site_id