mirror of https://github.com/dunwu/db-tutorial.git
feat: 更新示例
parent
4c3ab73e81
commit
088d49c81f
|
@ -6,11 +6,15 @@ import org.junit.jupiter.api.Test;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.sql.*;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
/**
|
||||
* Mysql 测试例
|
||||
* @author Zhang Peng
|
||||
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
|
||||
* @see https://dev.mysql.com/doc/connector-j/5.1/en/
|
||||
*/
|
||||
public class MysqlDemoTest {
|
||||
|
|
|
@ -7,7 +7,7 @@ import org.springframework.context.ApplicationContext;
|
|||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
* @author Zhang Peng
|
||||
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
|
||||
* @since 2018/6/19
|
||||
*/
|
||||
public class RedissonStandaloneTest {
|
||||
|
|
|
@ -15,7 +15,7 @@ import java.util.Set;
|
|||
/**
|
||||
* Jedis 测试例
|
||||
*
|
||||
* @author Zhang Peng
|
||||
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
|
||||
* @see https://github.com/xetorthio/jedis
|
||||
*/
|
||||
@Slf4j
|
||||
|
|
|
@ -16,7 +16,7 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Zhang Peng
|
||||
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ActiveProfiles("dev")
|
||||
|
|
|
@ -6,7 +6,7 @@ import org.springframework.boot.SpringApplication;
|
|||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* @author Zhang Peng
|
||||
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
|
||||
* @since 2019-03-05
|
||||
*/
|
||||
@Slf4j
|
||||
|
|
|
@ -6,7 +6,7 @@ import java.sql.ResultSet;
|
|||
import java.sql.Statement;
|
||||
|
||||
/**
|
||||
* @author Zhang Peng
|
||||
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
|
||||
* @since 2019-03-05
|
||||
*/
|
||||
public class SqliteDemo {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
-- --------------------------------------------------------------------------------------
|
||||
-- 查找重复的电子邮箱
|
||||
-- @link https://leetcode-cn.com/problems/duplicate-emails/
|
||||
-- @author Zhang Peng
|
||||
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
|
||||
-- @date 2020/02/29
|
||||
-- ----------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
-- --------------------------------------------------------------------------------------
|
||||
-- Mysql 查询示例
|
||||
-- @author Zhang Peng
|
||||
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
|
||||
-- @date 2018/5/5
|
||||
-- ----------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
-- --------------------------------------------------------------------------------------
|
||||
-- 函数操作影响索引效率示例
|
||||
-- @author Zhang Peng
|
||||
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
|
||||
-- ----------------------------------------------------------------------------------------
|
||||
|
||||
-- 步骤 1、建表
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
-- --------------------------------------------------------------------------------------
|
||||
-- 函数操作影响索引效率示例
|
||||
-- @author Zhang Peng
|
||||
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
|
||||
-- ----------------------------------------------------------------------------------------
|
||||
|
||||
CREATE TABLE t (
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
-- --------------------------------------------------------------------------------------
|
||||
-- Mysql 事务示例
|
||||
-- @author Zhang Peng
|
||||
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
|
||||
-- @date 2020/02/29
|
||||
-- ----------------------------------------------------------------------------------------
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
-- --------------------------------------------------------------------------------------
|
||||
-- 幻读示例
|
||||
-- 实验说明:以下 SQL 脚本必须严格按照顺序执行,并且事务 A 和事务 B 必须在不同的 Client 中执行。
|
||||
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
|
||||
-- @date 2023/10/25
|
||||
-- ----------------------------------------------------------------------------------------
|
||||
|
||||
-- --------------------------------------------------------------------- (1)数据初始化
|
||||
|
||||
-- 创建表 test
|
||||
CREATE TABLE `test` (
|
||||
`id` INT(10) UNSIGNED PRIMARY KEY AUTO_INCREMENT,
|
||||
`value` INT(10) NOT NULL
|
||||
);
|
||||
|
||||
-- 数据初始化
|
||||
INSERT INTO `test` (`id`, `value`) VALUES (1, 1);
|
||||
INSERT INTO `test` (`id`, `value`) VALUES (2, 2);
|
||||
INSERT INTO `test` (`id`, `value`) VALUES (3, 3);
|
||||
|
||||
-- --------------------------------------------------------------------- (2)事务 A
|
||||
|
||||
BEGIN;
|
||||
|
||||
-- 查询 id = 4 的记录
|
||||
SELECT * FROM `test` WHERE `id` = 4;
|
||||
-- 结果为空
|
||||
|
||||
-- --------------------------------------------------------------------- (3)事务 B
|
||||
|
||||
BEGIN;
|
||||
|
||||
INSERT INTO `test` (`id`, `value`) VALUES (4, 4);
|
||||
|
||||
COMMIT;
|
||||
|
||||
-- --------------------------------------------------------------------- (4)事务 A
|
||||
|
||||
-- 查询 id = 4 的记录
|
||||
SELECT * FROM `test` WHERE `id` = 4;
|
||||
-- 结果依然为空
|
||||
|
||||
-- 成功更新本应看不到的记录 id = 4
|
||||
UPDATE `test` SET `value` = 0 WHERE `id` = 4;
|
||||
|
||||
-- 再一次查询 id = 4 的记录
|
||||
SELECT * FROM `test` WHERE `id` = 4;
|
||||
-- 结果为:
|
||||
-- +----+-------+
|
||||
-- | id | value |
|
||||
-- +----+-------+
|
||||
-- | 4 | 0 |
|
||||
-- +----+-------+
|
||||
|
||||
COMMIT;
|
|
@ -0,0 +1,53 @@
|
|||
-- --------------------------------------------------------------------------------------
|
||||
-- 幻读示例
|
||||
-- 实验说明:以下 SQL 脚本必须严格按照顺序执行,并且事务 A 和事务 B 必须在不同的 Client 中执行。
|
||||
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
|
||||
-- @date 2023/10/25
|
||||
-- ----------------------------------------------------------------------------------------
|
||||
|
||||
-- --------------------------------------------------------------------- (1)数据初始化
|
||||
|
||||
-- 创建表 test
|
||||
CREATE TABLE `test` (
|
||||
`id` INT(10) UNSIGNED PRIMARY KEY AUTO_INCREMENT,
|
||||
`value` INT(10) NOT NULL
|
||||
);
|
||||
|
||||
-- 数据初始化
|
||||
INSERT INTO `test` (`id`, `value`) VALUES (1, 1);
|
||||
INSERT INTO `test` (`id`, `value`) VALUES (2, 2);
|
||||
INSERT INTO `test` (`id`, `value`) VALUES (3, 3);
|
||||
|
||||
-- --------------------------------------------------------------------- (2)事务 A
|
||||
|
||||
BEGIN;
|
||||
|
||||
-- 查询 id > 2 的记录数
|
||||
SELECT COUNT(*) FROM `test` WHERE `id` > 2;
|
||||
-- 结果为:
|
||||
-- +----------+
|
||||
-- | count(*) |
|
||||
-- +----------+
|
||||
-- | 1 |
|
||||
-- +----------+
|
||||
|
||||
-- --------------------------------------------------------------------- (3)事务 B
|
||||
|
||||
BEGIN;
|
||||
|
||||
INSERT INTO `test` (`id`, `value`) VALUES (4, 4);
|
||||
|
||||
COMMIT;
|
||||
|
||||
-- --------------------------------------------------------------------- (4)事务 A
|
||||
|
||||
-- 查询 id = 4 的记录
|
||||
SELECT COUNT(*) FROM `test` WHERE `id` > 2 FOR UPDATE;
|
||||
-- 结果为:
|
||||
-- +----------+
|
||||
-- | count(*) |
|
||||
-- +----------+
|
||||
-- | 2 |
|
||||
-- +----------+
|
||||
|
||||
COMMIT;
|
|
@ -1,6 +1,6 @@
|
|||
-- --------------------------------------------------------------------------------------
|
||||
-- Mysql 基本 DDL 语句示例
|
||||
-- @author Zhang Peng
|
||||
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
|
||||
-- @date 2018/4/28
|
||||
-- ----------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
-- --------------------------------------------------------------------------------------
|
||||
-- Mysql 基本 DML 语句示例
|
||||
-- @author Zhang Peng
|
||||
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
|
||||
-- @date 2018/4/28
|
||||
-- ----------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
-- --------------------------------------------------------------------------------------
|
||||
-- Mysql 基本 TCL 语句示例
|
||||
-- @author Zhang Peng
|
||||
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
|
||||
-- @date 2018/4/28
|
||||
-- ----------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
-- --------------------------------------------------------------------------------------
|
||||
-- Mysql 常见查询示例
|
||||
-- @author Zhang Peng
|
||||
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
|
||||
-- @date 2018/5/4
|
||||
-- ----------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
/**
|
||||
* Mysql 触发器(TRIGGER)创建、使用示例
|
||||
* @author Zhang Peng
|
||||
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
|
||||
* @date 2018/5/2
|
||||
*/
|
||||
-- --------------------------------------------------------------------------------------
|
||||
-- Mysql 基本 DDL 语句示例
|
||||
-- @author Zhang Peng
|
||||
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
|
||||
-- @date 2018/4/28
|
||||
-- ----------------------------------------------------------------------------------------
|
||||
|
||||
|
|
Loading…
Reference in New Issue