- 创建数据库
#如果student存在就删除student
drop DATABASE if EXISTS student;
#创建student数据库
create database student;
- 创建表格
#如果存在studentinfo表就删除studentinfo表
drop table if EXISTS studentinfo;
#创建表studentinfo
create table studentinfo(
#id为主键自增
id int(4) PRIMARY KEY auto_increment,
name VARCHAR(50) not null,
sex VARCHAR(2) not null,
age int(3) not null,
address VARCHAR(50) not null
);
- 添加数据(有三种方法)
#添加数据
insert into studentinfo(name,sex,age,address) VALUES("张三","男",30,"郑州");
insert into studentinfo VALUES(null,"赵六","男",32,"许昌");
insert into studentinfo VALUES(0,"钱琦","女",18,"北疆");
执行结果为
4.修改数据
update studentinfo set name="张三2" where id=1;
执行结果为:
5.删除数据
#删除数据
DELETE FROM studentinfo WHERE id=1;
运行结果为: