MySQL
安装 MySQL(过程参考【精选】2023 年 MySQL 8.0 安装配置 最简易(保姆级)_mysql8.0安装配置教程_mobeicanyue的博客-CSDN博客)
win + R 管理员权限使用cmd,验证MySQL安装是否成功
mysql -u root -p
安装 MySQL Workbench (过程参考MySQL及MySQL Workbench下载与安装 - 知乎 (zhihu.com))
创建表 create table(来源牛客SQL109)
DROP TABLE IF EXISTS `Customers`; CREATE TABLE IF NOT EXISTS `Customers`( cust_name VARCHAR(255) NOT NULL COMMENT '顾客id', cust_contact VARCHAR(255) NOT NULL COMMENT '顾客联系方式', cust_state VARCHAR(255) NOT NULL COMMENT '顾客州', cust_email VARCHAR(255) NOT NULL COMMENT '顾客email' ); INSERT `Customers` VALUES ('cust10','8695192','MI','cust10@cust.com'),('cust1','8695193','MI','cust1@cust.com'),('cust2','8695194','IL','cust2@cust.com');
查询 select
select * from Customers
添加 insert / insert into
insert `Customers`
values ('cust20','8695195','NEW','cust20@cust.com')
更新 update
涉及到where语句中条件不为主键,MySQL Workbench默认安全更新模式,关闭安全更新模式即可(mysql workbench 关闭安全更新模式_mysqlworkbench关闭安全模式-CSDN博客)
update Customers set cust_state = 'UPDATED' where cust_name = 'cust20'
删除 delete
delete from Customers where cust_name = 'cust20'
排序 order by,asc升序(不写则默认升序),desc降序
select * from Customers order by cust_contact asc
select * from Customers order by cust_contact desc
联合 unoin 两张表,order by需要在末尾,而不能是两个子表各自都有
select cust_name, cust_contact, cust_email from Customers where cust_state = 'MI' union select cust_name, cust_contact, cust_email from Customers where cust_state = 'IL' order by cust_name