增删查改操作
插入数据
INSERT INTO `person` (`username`,`password`,`realname`,`age`,`email`,`sex`,`phone`,`mobile`,`address`,`status`)
VALUES('admin','123456','张三',25,'123456@qq.com',1,'0769-87767612','13800138000','东莞市',1);
更新数据
UPDATE `person` SET `username`='zhangsan' WHERE id=1;
删除数据
DELETE FROM `person` WHERE id=2;
查询数据
SELECT * FROM `person` where id=1;
SELECT * FROM `student` WHERE collegeId=1 LIMIT 0,5;
学习创建数据表
多表查询
内连接
内连接就是表间的主键与外键相连,只取得键值一致的,可以获取双方表中的数据连接方式
SELECT a.name,a.phone,b.collegeName
FROM `student` as a
INNER JOIN `college` as b
ON a.collegeId = b.collegeId;
左连接
左连接是以左表为标准,只查询在左边表中存在的数据,当然需要两个表中的键值一致
SELECT a. NAME,a.phone,b.collegeName
FROM`student` AS a
LEFT JOIN `college` AS b
ON a.collegeId = b.collegeId;
右连接
右连接将会以右边作为基准,进行检索
SELECT a. NAME,a.phone,b.collegeName
FROM`student` AS a
RIGHT JOIN `college` AS b
ON a.collegeId = b.collegeId;