# 查询结果集建表
CREATE TABLE class3
(SELECT * FROM class GROUP BY cname HAVING COUNT(cname) = 1);
# 建表
CREATE TABLE Score(
sid INT NOT NULL,
cname VARCHAR(20),
sscore DECIMAL,
sbirth DATE,
sgender TINYINT,
PRIMARY KEY(sid)
)DEFAULT CHARSET=utf8;
# 添加主键约束
ALTER TABLE score ADD PRIMARY KEY(sid);
# 添加其他约束
ALTER TABLE score MODIFY sid INT NOT NULL AUTO_INCREMENT;
# 添加unique约束
ALTER TABLE score MODIFY cname VARCHAR(20) UNIQUE;
SELECT * FROM score;
# auto_increment使用方法
INSERT INTO score (sid,cname) VALUES (NULL,"历史");
# 更新字段
UPDATE score SET sscore=98 WHERE cname="语文";