MySQL笔记
#创建数据库
create database sboot_proj_demo;
#查看所有数据库
show databases;
#选择数据库
use sboot_proj_demo;
#查看数据库中的所有表
show tables;
#查看表是怎么创建的(查看表创建语句),\G表示让显示的表进行翻转
show create table 表名 \G;
#对于自增,通过修改auto_increment的值(这里自增值可以不是从1开始)
alter table 表名 auto_increment=1;
#删除表
drop table users;
#创建表
create table users
(
userId int auto_increment primary key,
userName varchar(20),
password varchar(20),
flag int
);
#查询表中所有内容
select * from users;
#查看表结构
describe users;
#向表中插入数据
INSERT INTO `users` (` userName`, ` password`, ` flag`) VALUES ('test1', 'test1', '1');
INSERT INTO `users` (` userName`, ` password`, ` flag`) VALUES ('test1', 'test1', '1');
-------------------------------------------------------------------------
操作符:
#创建一个商品分类表
create table category(
categoryId auto_increment primary key,
categoryName varchar(20)
)
#MySQL UNION 操作符用于连接两个以上的 SELECT 语句的结果组合到一个结果集合中。多个 SELECT 语句会删除重复的数据。
insert into category (categoryName) select '饮品' union select '食品';

上面的union省去了不用写两条插入语句,也就是说等同于
insert into category (categoryName) select '饮品';
insert into category (categoryName) select '食品';
numeric的使用
#创建一个商品信息表
create table goods(
goodId int auto_increment primary key,
goodsName varchar(200),
price numeric(5,1),
#numeric(5,1) 表示这个商品的价格包含小数点最多为五位,即他的最大值应该为9999.9
address varchar(200),
produceDate date,
picture varchar(200),
categoryId int,
#添加外键关联
foreign key(categoryId) references category(categoryId)
);
truncate 的用法:
https://www.cnblogs.com/zhoufangcheng04050227/p/7991759.html

浙公网安备 33010602011771号