当前位置:网站首页>MySQL数据库(一)
MySQL数据库(一)
2022-07-05 05:17:00 【司小幽】
1.数据库简介
# 数据库内容: 存储数据的仓库,对数据库中的数据进行增删改查
# 数据表:具体存放数据的地方
2.常用的数据库
# Oracle:收费的大型数据库
# mysql:开源免费 小型
# sqlserver:收费的中型的数据库
# db2:收费的
3.操作数据库
# 鼠标操作 SQL语句操作
# SQL的代码:
# sql语法:
# 不区分大小写
# 每一句sql之后分号 a查询 b查询
4.数据库中常用的数据类型
# int类型 数字的类型
# varchar(50) 字符串 不定长 字节65535 男 2个字节
# char 字符串 定长的字节 255个字节 男 2个字节 空中
# date日期 格式'yyyy-mm-dd'
# datetime日期 格式'yyyy-mm-dd hh:mm:ss'
5.常用SQL操作
-- 注释ctrl+/ 加注释 多行注释/**/
-- 用sql语句创建数据库 语法: create database 数据库名
CREATE database ysly;
-- 删除数据库 语法:drop database 数据库名;
drop database ysly;
-- 新建表
-- 语法
/* create table 表名( 字段名 字段类型 约束条件, 字段名 字段类型, ... 字段名 字段类型 )charset=utf8; */
-- not null 主键primary key 自增 default
-- 设置了主键 主键不能空,自增一定要是主键
-- 你创建的这个表放在哪个数据里面
create table you.student1(
id int PRIMARY key auto_increment,
name varchar(20) default 'zz',
age int,
sex char(20)
);
-- 表里面的所有字段都要添加进去
-- 新增数据 语法结构 insert into 表名 values(字段名数据,字段名数据,字段名数据,字段名数据)
insert into you.student1 values(1,'小翠',18,'女');
insert into you.student1 values('小翠2',18,'女');
-- 只添加部分字段
-- insert into 表名(字段名,字段名,字段名)values(字段数据,字段数据,字段数据)
insert into you.student1(name,age,sex) values('小翠2',18,'女');
insert into you.student1(age,sex) values(18,'女');
-- 一次性添加多个数据 values value
-- insert into 表名 values(字段名数据,字段名数据,字段名数据,字段名数据),(字段名数据,字段名数据,字段名数据,字段名数据),(字段名数据,字段名数据,字段名数据,字段名数据)
insert into you.student1(name,age,sex) value('小红',18,'女'),('小红2',18,'女'),('小红3',18,'女'),('小红3',18,'女');
-- 查询语句
-- 查询 select * from 表名;
select * from you.student1;
-- 查询部分数据 select 字段名,字段名 from 表名
select id,name from you.student1;
-- 修改语句 update 表名 set 字段名 = 修改的内容 整个表的整个字段
update you.student1 set name = '翠花';
-- 不想修改整个表的字段 只想修改编号为1的名字 或者 年龄为18条件 where 加条件
update you.student1 set name = '酸菜' where id = 1;
update you.student1 set name = '紫菜' where age = 30;
-- 删除 delete from 表名;delete from 表名 where条件;
delete from you.student1 where id = 2;
delete from you.student1;
-- drop table 表名;表结构
drop table you.student1;
-- truncate table 表名;
truncate you.student;
边栏推荐
- [binary search] 69 Square root of X
- Unity writes timetables (without UI)
- Time format conversion
- [interval problem] 435 Non overlapping interval
- room数据库的使用
- 质量体系建设之路的分分合合
- cocos_ Lua loads the file generated by bmfont fnt
- Unity check whether the two objects have obstacles by ray
- Embedded database development programming (zero)
- [turn]: OSGi specification in simple terms
猜你喜欢
服务熔断 Hystrix
[to be continued] [depth first search] 547 Number of provinces
支持多模多态 GBase 8c数据库持续创新重磅升级
[to be continued] [UE4 notes] L1 create and configure items
Applet Live + e - commerce, si vous voulez être un nouveau e - commerce de détail, utilisez - le!
质量体系建设之路的分分合合
[depth first search] 695 Maximum area of the island
Unity find the coordinates of a point on the circle
Shell Sort
Pointnet++的改进
随机推荐
Es module and commonjs learning notes -- ESM and CJS used in nodejs
Haut OJ 1350: choice sends candy
Use of snippets in vscode (code template)
UE fantasy engine, project structure
Unity writes timetables (without UI)
[to be continued] [UE4 notes] L1 create and configure items
FVP和Juno平台的Memory Layout介绍
Leetcode word search (backtracking method)
[speed pointer] 142 circular linked list II
Judge the position of the monster in the role under unity3d
[转]MySQL操作实战(三):表联结
Haut OJ 1241: League activities of class XXX
Embedded database development programming (VI) -- C API
Heap sort summary
Under the national teacher qualification certificate in the first half of 2022
[to be continued] I believe that everyone has the right to choose their own way of life - written in front of the art column
Shell Sort
嵌入式数据库开发编程(五)——DQL
Listview is added and deleted at the index
Haut OJ 1316: sister choice buys candy III