当前位置:网站首页>1.MySQL ----数据库的基础操作
1.MySQL ----数据库的基础操作
2022-08-11 10:42:00 【陆悠漓】
1. 数据库的操作
MySQL 中对大小写不做区分接下来不会特别说明
MySQL 当中进行填写时执行过的代码不能修改只能进行重写很麻烦,在这里我们可以新建一个文本文档使用 IDEA 打开文本文档,在IDEA里面进行代码的填写
1.1显示当前数据库
show databases;
1.2 创建数据
create database if not exists 库名称;
-- 或者
create database 库名称;
添加 if not exists 是为了避免重复建库
1.3 使用数据库
use 库名称;
1.4 删除数据库
drop database 库名称;
注意:
~~~~~~~ 数据库删除以后,内部看不到对应的数据库,里边的表和数据全部被删除
2. 表的操作
2.1 库的使用
需要操作数据库中的表时,需要先使用该数据库
use 库名称;
2.2 创建表
create table if not exists 表名称(
字段1 类型1,
字段2 类型2 -- 注释内容,
字段3 类型3 comment '注释内容',
字段4 类型4
);
2.3 查看表的结构
desc 表名;
2.4 删除表
drop table 表名;
3.常用数据类型
int | 整型 |
---|---|
decimal(M,D) | 浮点数类型 |
varchar(size) | 字符串类型 |
timestamp | 日期类型 |
4.实践操作
有一个商店的数据,记录客户及购物情况,有以下三个表组成:
- 商品goods(商品编号goodId, 商品名goodName, 单价unitprice, 商品类别category, 供应商provider)
- 客户customer(客户号customerId, 姓名name, 住址address, 邮箱email, 性别sex, 身份证cardId)
- 购买purchase(购买订单号orderId, 客户号customerId, 商品号goodsId, 购买数量nums)
-- 代码部分
-- 创建数据库
create database if not exists shop;
-- 选择数据库
use shop;
-- 创建 表1 "商品"
-- 创建数据库
create database if not exists shop;
-- 选择数据库
use shop;
-- 创建 表1 "商品"
create table if not exists goods(
goodsId int,
goodsName varchar(30),
unitprice int,
category varchar(12),
provider varchar(60)
);
-- 创建 表2 "客户"
create table if not exists customer(
customerId int,
name varchar(20),
address varchar(256),
email varchar(64),
sex bit,
cardId varchar(18)
);
-- 创建 表3 "购买"
create table if not exists purchase(
orderId int comment '订单号',
customerId int,-- 订单编号
goodsId int,
nums int
);
边栏推荐
- 国产数据库有没有在国外的应用案例?
- 大疆2022秋招笔试 —— 最小时间差、数组的最小偏移量
- 错误代码: 1118 - Row size too large (> 8126). Changing some columns to TEXT or BLOB may help. In current
- 放苹果
- Use Function Compute to package and download OSS files [Encounter Pit Collection]
- 保证金监控中心保证期货开户和交易记录
- Qihua stores the future and interprets the origin of distributed
- 如何解决 “主节点故障恢复的自动化” 问题?
- Some time function records commonly used in mysql
- Cholesterol-PEG-FITC,Fluorescein-PEG-CLS,胆固醇-聚乙二醇-荧光素水溶性
猜你喜欢
运动健康服务场景事件订阅,让应用推送“更懂用户”
数字钱包红海角逐,小程序生态快速引入可助力占领智慧设备入口
【Mysql系列】03_系统设计
Neuropathic pain classification picture Daquan, neuropathic pain classification
How to improve the efficiency of telecommuting during the current epidemic, sharing telecommuting tools
Simple implementation of a high-performance clone of Redis using .NET (seven-end)
Cholesterol-PEG-FITC, Fluorescein-PEG-CLS, Cholesterol-PEG-Fluorescein water-soluble
安装nodejs
openresty概述及Lua语言的嵌入
【中央任务调度系统—通信开发】
随机推荐
Latex引用图片 发现 显示的图片标号不对
二维数组名的用途
Algorithm---Jumping Game (Kotlin)
打印时间的各种格式
宝塔计划任务执行周期设置【秒】为定时单位【或者更小】
计算数组某个元素的和
Qihua stores the future and interprets the origin of distributed
Word小技巧之图表实现自动编号和更新
【翻译】Drafting and Revision: Laplacian Pyramid Network for Fast High-Quality Artistic Style Transfer
MySQL表sql语句增删查改_查询
Convolutional Neural Network Gradient Vanishing, The Concept of Gradient in Neural Networks
Ali Ermian: Do you know how to tune the JVM?
Jetpack Compose学习(9)——Compose中的列表控件(LazyRow和LazyColumn)
【应用SLAM技术建立二维栅格化地图】
突破次元壁垒,让身边的玩偶手办在屏幕上动起来!
Neuropathic pain classification picture Daquan, neuropathic pain classification
Flexmonster 数据透视表和图表组件
本地开发好的 SAP UI5 应用部署到 ABAP 服务器时,中文字符变成乱码的原因分析和解决方案
Primavera P6 Professional 21.12 Login exception case sharing
二、第二章变量