当前位置:网站首页>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
);
边栏推荐
猜你喜欢

漫画手绘之临摹篇

chrome无痕浏览模式中使用插件

数字钱包红海角逐,小程序生态快速引入可助力占领智慧设备入口

Neuropathic pain classification picture Daquan, neuropathic pain classification

Revelations!The former Huawei microservice expert wrote 500 pages of practical notes on the landing architecture, which has been open sourced

宝塔一键部署WordPress(含宝塔添加站点、阿里云安全组配置、阿里云子域名解析)

How to improve the efficiency of telecommuting during the current epidemic, sharing telecommuting tools

Convolutional Neural Network Gradient Vanishing, The Concept of Gradient in Neural Networks

中小企业如何实施MES管理系统

Calculate the sum of an element of an array
随机推荐
servlet——servlet介绍 | 发布动态资源
MySQL表sql语句增删查改_增加
What is the difference between the qspi interface and the ordinary four-wire SPI interface?
困扰所有SAP顾问多年的问题终于解决了
期货开户最低的是交易所手续费不加佣金
How to build programming ideas and improve programming ideas
chrome插件开发入门-保姆级攻略
Dreamweaver网页作业——紫罗兰永恒花园动漫价绍网页 7页,含有table表格,js表单验证还有首页视频。以及列表页。浮
7 天找个 Go 工作,Gopher 要学的条件语句,循环语句 ,第3篇
使用函数计算打包下载OSS文件【遇坑锦集】
OAK-FFC Series Product Getting Started Guide
Have you encountered this kind of error? flink-sql writes to clickhouse
发布静态资源
放苹果
深度解析佛萨奇,Forsage魔豹联盟系统开发方案(源码部署)
【应用SLAM技术建立二维栅格化地图】
Ali Ermian: Do you know how to tune the JVM?
联想 U 盘装机后出现 start pxe over ipv4
MySQL数据库基础01
保证金监控中心保证期货开户和交易记录