MySql教程

mysql数据库总结

本文主要是介绍mysql数据库总结,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

创建数据库的语句。
例如创建一个数据库名字叫做stumanager
create database if not exists stumanager character set utf8 collate utf8_general_ci;
使用数据库
use stumanager;
最好创建完数据库退出转到你所要创建的数据库下面去打代码。
创建数据表
4、创建考试成绩表。数据表名称:score(10分)
字段描述 字段名 数据类型 是否为空 说明
编号 ID Int 否 主键(primary key ),自增(auto_increment)
学期 Term Char(6) 否
学号 stuId Char(10) 是 外键:stuinfo(stuid)
课程编号 courseId Int 是 外键:courseinfo(courseid)
考试成绩 examGrad Float 是

以这个为例。
create table score(
id int PRIMARY key UNIQUE auto_increment COMMENT ‘编号’,
term char(6) COMMENT ‘学期’,
stuid char(10) NOT null COMMENT ‘学号’,
FOREIGN key(stuid) REFERENCES stuinfo(stuid),
courseid int not null COMMENT ‘课程编号’,
examgrad FLOAT not null COMMENT ‘考试成绩’,
FOREIGN key(courseid) REFERENCES courseinfo(courseid)
)ENGINE = INNODB;
查看所有表
show tables;
删除表
drop table 数据表
添加一条数据
insert into 表名 values(值1,值2,…);
查看表的结构
desc 表名;
更改表的名称
alter table 表名 rename 新表名;
添加字段
alter table 表名 add 要添加的东西;
删除字段
alter table 表名 drop 字段;
更改字段属性和属性
alter table 表名 change 要更改的字段属性;
只更改字段属性
alter table 表名 modify 字段属性;

删除表数据
delect from 表名 where 删除的表数据;
更改表数据
update 表名 set 修改的数据 where 来自哪里;
数据查找名字
select * from 表名 where 字段名字 like ‘%’;
数据排序
select * from 表名 order by 字段 asc|desc;

2021/11/22日写后续补全

这篇关于mysql数据库总结的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!