2021-06-30

use xuexiao;

create table studentInfo(
name varchar(10),
sex char,
age int,
address varchar(20)
);

show tables;

-- 插入操作
-- 值需要按照字段的顺序插入,如果插入的值顺序和创建表的顺序相同,则字段可以省略
insert into studentInfo(name,sex,age,address) value ("马嘉祺",'男',18,'河南省郑州市');
insert into studentInfo(sex,address,age,name) value ("男",'重庆市',18,'丁程鑫');
insert into studentInfo value ("宋亚轩",'男',17,'广东省广州市');
select * from studentInfo;

-- 修改以创建的表字段默认值
alter table studentInfo change sex sex char default '男';

insert into studentInfo(name,sex,age,address) value ("翠花",'女',18,'河南省郑州市');
insert into studentInfo(sex,address,age,name) value ("女",'重庆市',8,'严美娜');
insert into studentInfo value ("宋人头",'男',17,'四川省');-- 有默认值 如果省略字段,则值需要写全
select * from studentInfo;

create table studentInfo2(
id int auto_increment primary key,
name varchar (10),
sex char,
age int ,
address varchar(20)

);

show tables;
insert into studentInfo2(id,name,sex,age,address) values (1,"马嘉祺",'女',18,'河南省郑州市');
insert into studentInfo2(name,sex,age,address) values ("马嘉祺2",'女',18,'河南省郑州市');
insert into studentInfo2(id,name,sex,age,address) values (3,"宋亚轩1",'女',18,'河南省郑州市');
insert into studentInfo2(id,name,sex,age,address) values (2,"宋亚轩1",'女',18,'河南省郑州市');
insert into studentInfo2(name,sex,age,address) values ("宋人头",'男',17,'四川省'),
("宋你离开",'男',17,'四川省'),
("刘耀文",'男',17,'重庆市'),
("张真源",'男',17,'重庆市'),
("严浩翔",'男',17,'四川省');

desc studentInfo2;
select *from studentInfo2;
select *from studentInfo;

insert into studentInfo values ("宋人头",'男',17,'四川省'),
("宋你离开",'男',17,'四川省'),
("刘耀文",'男',17,'重庆市'),
("张真源",'男',17,'重庆市'),
("严浩翔",'男',17,'四川省');

insert into studentInfo2 values (9,"宋人头",'男',17,'四川省'),
(10,"宋你离开",'男',17,'四川省'),
(11,"刘耀文",'男',17,'重庆市'),
(12,"张真源",'男',17,'重庆市'),
(13,"严浩翔",'男',17,'四川省');

select * from studentInfo2;

-- 修改 update ... set ... where 条件
-- 修改指定的数据
update studentInfo set name="潘金莲" where name ="翠花";
-- 没有写条件,则修改全部的数据
update studentInfo set name="潘金莲";

-- 删除 delete from table where ... 有日志留下,可以恢复
delete from studentInfo2 where name ="宋亚轩1";-- 删除符合条件的数据
delete from studentInfo ;-- 删除所有数据

-- 销毁数据 不留下日志,速度快,无法恢复
truncate table studentInfo2;

你可能感兴趣的:(2021-06-30)