1 创建数据库
create database student
2 创建表
create table stu(
id int(4) not null primary key auto_increment,
sname varchar(255) not null,
discri varchar(255) not null,
price double(10,2) not null,
password varchar(20) not null,
)
# double(10,2) 代表整数加小数位数为10 其中小数位数为2位
3 修改表
# 修改表的主键为自增
ALTER TABLE stu MODIFY id INT(4) NOT NULL AUTO_INCREMENT
4 操作数据
#增加数据
INSERT INTO stu(sname,discri,price,PASSWORD) VALUES('莹莹','耶','0','1234')
#查询所有
select * from stu
#登录
SELECT * FROM stu WHERE sname='莹莹' and password='1234'
#通过id修改用户
update stu set sname='莹莹',discri='耶',price='0',password='1234'
where id=1
#通过id删除学生
delete from stu where id=1