通过主键锁定唯一表头
数据库三范式
已主键为中心
-- 删除表
drop TABLE classes
-- 创建表
create table classes
(
classId int not NULL,
className VARCHAR(30) not null
)
-- 添加数据,注意字符串用单引号
INSERT INTO classes(classId ,className) VALUES (1,'1班');
INSERT INTO classes(classId ,className) VALUES (2,'2班');
INSERT INTO classes(classId ,className) VALUES (3,'3班');
INSERT INTO classes(classId ,className) VALUES (4,'4班');
-- 查询数据 *表示所有的列
SELECT *FROM classes;
-- 查询单列
SELECT classId FROM classes;
SELECT classId,className FROM classes;
-- 修改
UPDATE classes set className='一班' WHERE classId=1;
-- 删除
DELETE FROM classes WHERE classId=1;
DELETE FROM classes WHERE classId in (1,3);
SELECT * FROM classes WHERE not classId=2;
SELECT *FROM classes WHERE classId!=2;
SELECT *FROM classes WHERE classId>1;
SELECT *FROM classes WHERE classId BETWEEN 1 AND 3;
SELECT *FROM classes WHERE classId>1 AND classId<3;
SELECT *FROM classes WHERE classId=1 or classId=3;
-- 数据库关键在于查询
SELECT *FROM classes WHERE NOT classId=1;