当前位置:网站首页>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;
边栏推荐
- Animation
- Django reports an error when connecting to the database. What is the reason
- 被舆论盯上的蔚来,何时再次“起高楼”?
- cocos_ Lua listview loads too much data
- Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
- Cocos2dx Lua registers the touch event and detects whether the click coordinates are within the specified area
- Simple HelloWorld color change
- Heap sort summary
- Out and ref functions of unity
- LeetCode之單詞搜索(回溯法求解)
猜你喜欢

YOLOv5添加注意力機制

Bucket sort

Leetcode word search (backtracking method)

Applet Live + e - commerce, si vous voulez être un nouveau e - commerce de détail, utilisez - le!

Do a small pressure test with JMeter tool
![[转]MySQL操作实战(一):关键字 & 函数](/img/b1/8b843014f365b786e310718f669043.png)
[转]MySQL操作实战(一):关键字 & 函数

win10虚拟机集群优化方案

Generate filled text and pictures

Embedded database development programming (zero)

远程升级怕截胡?详解FOTA安全升级
随机推荐
Count sort
2022/7/1學習總結
Embedded database development programming (zero)
Judge the position of the monster in the role under unity3d
Research on the value of background repeat of background tiling
对象的序列化
2022/7/2做题总结
Haut OJ 1321: mode problem of choice sister
[to be continued] [depth first search] 547 Number of provinces
YOLOv5添加注意力机制
Leetcode word search (backtracking method)
[allocation problem] 455 Distribute cookies
Page countdown
质量体系建设之路的分分合合
Lua determines whether the current time is the time of the day
Unity intelligent NPC production -- pre judgment walking (method 1)
【ES实战】ES上的native realm安全方式使用
Under the national teacher qualification certificate in the first half of 2022
The difference between heap and stack
cocos2dx_ Lua particle system