MySql数据库增删改查常用语句命令
[删除(380066935@qq.com或微信通知)]
更好的阅读体验请查看原文:https://blog.csdn.net/weixin_40605573/article/details/105905355?utm_medium=distribute.pc_feed_blog_category.none-task-blog-classify_tag-18.nonecasedepth_1-utm_source=distribute.pc_feed_blog_category.none-task-blog-classify_tag-18.nonecase
文章目录
增删改查语句
库操作
表操作
增删改查实例
准备表
插入数据
修改表数据
删除表数据
查询表数据
常见的MySQL语句命令
常见MySQL字段含义
增删改查语句
增删改查的语句命令为:
操作 命令
增 insert
删 delete
改 update
查 select或者show
库操作
操作 代码
创建数据库 create database shujuku;
创建带字符集的数据库 create database mydb2 CHARACTER SET = utf8;
创建带校验的数据库 create database mydb3 CHARACTER SET = utf8 COLLATE utf8_general_ci;
显示数据库 show databases;
删除数据库 drop database shujuku;
修改数据库编码 alter database shujuku character set gb2312;
表操作
创建数据库表:
创建一个表名为:employee,该表中含有id、name、sex、birthday、job字段
create table employee(
id int,
name varchar(40),
sex char(4),
birthday date,
job varchar(100)
);
1
2
3
4
5
6
7
表中增加image字段:
alter table employee add image blob;
1
修改job值,使其长度为60(原长度为100):
alter table employee modify job varchar(60);
1
删除sex列:
alter table employee drop sex;
1
表名改为user(原名employee):
rename table employee to user;
1
修改表的字符集为utf-8:
alter table user character set utf8;
1
列名name改为username:
alter table user change column name username varchar(100);
1
删除表:
drop table user;
1
增删改查实例
准备表
create table employee(
id int,
name varchar(40),
sex varchar(4),
birthday date,
entry_date date,
salary decimal(8,2),
resum text
);
1
2
3
4
5
6
7
8
9
插入数据
insert into employee(id,name,sex,birthday,entry_date,salary,resum)
values(1,'zhangsan','male','1993-03-04','2016-11-10','1000','i am a developer');
1
2
制定某些列插入数据:
insert into employee(id) values(6);
1
插入汉字:
insert into employee(id,name) values(6,'张三');
1
修改表数据
将所有员工薪水修改为5000元:
update employee set salary=5000;
1
将姓名为‘zhangsan’的员工薪水修改为3000元:
update employee set salary=3000 where name='zhangsan';
1
将姓名为‘aaa’的员工薪水修改为4000元,job修改为ccc:
update employee set salary=4000,job='ccc' where name='aaa';
1
将‘wu’的薪水在原有基础上增加1000元:
update employee set salary=salary+1000 where name='wu';
1
删除表数据
删除表中名称为‘zhangsan’的记录:
delete from employee where job='zhangsan';
1
删除表中所有记录:
delete from employee;
1
使用truncate删除表中记录:
truncate table employee;
1
查询表数据
查询表中所有学生的信息:
select id,name,chinese,english,math from student;
1
查询表中所有学生的姓名和对应的英语成绩:
select name,english from student;
1
查询姓名为wu的学生成绩:
select * from student where name='wu';
1
查询英语成绩大于90分的同学:
select name from student where english>'90';
1
查询英语分数在80-90之间的同学:
select * from student where english>=80 and english<=90;
1
常见的MySQL语句命令
操作 命令
进入MySQL命令行 mysql -u root -p;
查看所有数据库 show databases;
创建数据库 create database shujuku charset utf8;
删除数据库 drop database shujuku;
选择数据库 use database;
查看所有表 show tables;
查看创建数据库的语句 show create database databasename;
查看创建表的语句 show create table tablename;
查看表结构 desc tablename;
常见MySQL字段含义
字段 含义
auto_increment 自增长
not null 非空
default 默认值
unique 唯一
charset 指定字符集
primary key 主键
引用原文链接:https://www.shujukuba.com/mysql/99.html
————————————————
版权声明:本文为CSDN博主「Nlper_Zhao」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_40605573/article/details/105905355