-- 存在一个只有班级编号cID与班级名称cName的数据表class,下面对该表进行数据的插入与删除
-- 1.添加一个数据 选择性插入
INSERT INTO class(cName) VALUES ('一年级三班');
-- 2.完整插入
INSERT INTO class VALUES(NULL, '一年级四班');
-- 3.多条数据插入
INSERT INTO class(cName) VALUES
('二年级一班'),
('二年级二班'),
('二年级三班'),
('二年级四班');
-- 4.查询数据表中的数据
SELECT * FROM class OEDER BY cID;
-- 5.无条件删除数据 会删除表中所有数据
DELETE FROM class;
-- 6.有条件删除
DELETE FROM class WHERE cID = 10;
DELETE FROM class WHERE cName = '二年级二班';
-- 7.处理并且关系的条件
DELETE FROM class WHERE cID = 12 AND cName = '二年级三班';
-- 8.处理或者关系的条件
DELETE FROM class WHERE cID = 13 OR cName = '二年级三班';
DELETE FROM class WHERE cName = '二年级一班' OR cName = '二年级三班';
-- 9.处理非关系的条件
DELETE FROM class WHERE cName != '二年级二班';
-- 10.删除所有二年级的信息
-- LIKE 通配符_匹配任意一个字符 %匹配0-任意多个字符
DELETE FROM class WHERE cName LIKE '二年级%';
-- 11.修改数据
UPDATE class SET cName = '一年级3班', cID = 88 WHERE cID = 22;
如有错误或建议欢迎大家指出与评论哈,希望这篇博文能帮助到大家,大家也可以分享给需要的人。
如需转载,请注明出处。https://www.jianshu.com/p/5cf9e9d0f3e4