#DML 数据操作语言
CREATE TABLE student(
id int,
namea VARCHAR(20),
sex VARCHAR(4),
age int,
hobby VARCHAR(20),
classes VARCHAR(20)
)
#insert into 添加数据行
INSERT INTO student values (1,'二喜','男',19,'听歌','2018A');
INSERT into student (id,namea) VALUES(2,'三喜');
ALTER TABLE student alter sex set DEFAULT '男'
INSERT INTO student values (3,'四喜',NULL,19,'听歌','2018A');
INSERT INTO student values (4,'五喜',DEFAULT,19,'听歌','2018A');
SELECT * FROM student
#插入多行
INSERT into student (id,namea) VALUES(5,'小二'),
(6,'小三'),(7,'小四');
#将查询结果插入新表1,注意新的表必须是已经被创建的,并且字段列是匹配的
CREATE TABLE student1(
id int,
namea VARCHAR(20),
sex VARCHAR(4)
)
INSERT INTO student1 (id,namea,SEX) SELECT id,namea,SEX FROM student;
SELECT * FROM student1
#将查询结果插入新表2,通过CREATE TABLE SELECT语句将现有表中的数据添加到未存在的表中
CREATE TABLE student2 SELECT id,namea,SEX FROM student;
SELECT * FROM student2
#UPDATE语句
UPDATE student set namea = '星星',sex = '女' where id = 2
#删除语句
DELETE from student2 where id = 1
TRUNCATE TABLE student2
DELETE from student#标识列不重置,主键自动递增存在
truncate table student1#标识列重置,主键自动递增取消
INSERT INTO student values (null,'二喜','男',19,'听歌','2018A');
INSERT INTO student1 values (null,'二喜','男');