CREATE TABLE t_class( classsno INT(11), cname VARCHAR(20), loc VARCHAR(40), advisor VARCHAR(20) ); DESCRIBE T_CLASS;
INSERT INTO T_CLASS(classno,cname,loc,advisor)VALUES(1,'高一(2)班','西教学楼三楼','张三');
ALTER TABLE T_CLASS MODIFY classno INT(11) PRIMARY KEY AUTO_INCREMENT; ALTER TABLE T_CLASS MODIFY loc VARCHAR(40) DEFAULT '东教学楼2楼'; SHOW COLUMNS FROM T_CLASS;
INSERT INTO T_CLASS (cname,loc) VALUES ('高一(8)班','西教学楼四楼'); SELECT * FROM T_CLASS;
三条插入记录中classno都为0,由于已经设置为自动增长列,故自动排序增长classno
INSERT INTO T_CLASS VALUES(0,'高一(9)班','西教学楼五楼','高克谦'), (0,'高一(10)班','西教学楼六楼','张香桐'), (0,'高一(11)班','西教学楼七楼','何基沣'); SELECT * FROM T_CLASS;
没有数据插入的字段classno使用自动增加约束生成值
INSERT INTO T_CLASS (cname,loc) VALUES ('高二某班','东教学楼某层'), ('高三某班','西教学楼某层'); SELECT * FROM T_CLASS;
SHOW TABLES; CREATE TABLE t_advisor( id INT PRIMARY KEY, aname VARCHAR(20), loc VARCHAR(40), advisor VARCHAR(20) ); ALTER TABLE T_ADVISOR MODIFY ID INT AUTO_INCREMENT; DESCRIBE T_ADVISOR;
INSERT INTO T_ADVISOR VALUES(0,'C1','D1','X'),(0,'C2','D2','Y'); DESC T_ADVISOR; SELECT * FROM T_ADVISOR;
INSERT INTO T_CLASS (cname,loc) SELECT aname,loc FROM T_ADVISOR; SELECT * FROM T_CLASS;
UPDATE T_CLASS SET loc='D3',advisor='E1' WHERE cname='C1'; SELECT * FROM T_CLASS;
UPDATE T_CLASS SET loc='loc_all',cname='cname_all' WHERE classno<=9&&classno>=8; SELECT * FROM T_CLASS;
DELETE FROM T_CLASS WHERE cname='高二某班'; SELECT * FROM T_CLASS;
DELETE FROM T_CLASS WHERE classno<=21&&classno>=11; SELECT * FROM T_CLASS;