国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

MySQL replace into 語句淺析(二 )

2019-11-02 15:27:19
字體:
來源:轉載
供稿:網友

   這篇文章主要介紹了MySQL replace into 語句淺析(二),本文著重給出了幾個特殊案例分析,需要的朋友可以參考下

  一 介紹

  上一篇文章介紹了replace into的基本原理。本章內容通過一個例子說明 replace into 帶來的潛在的數據質量風險,當涉及replace into操作的表含有自增主鍵時,主備切換后會造成數據覆蓋等不一致的情況發生。

  二 案例分析

  在主庫上操作

  代碼如下:

  [email protected] 12:36:51>show create table t1 G

  *************************** 1. row ***************************

  Table: t1

  Create Table: CREATE TABLE `t1` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `name` varchar(20) DEFAULT NULL,

  PRIMARY KEY (`id`),

  UNIQUE KEY `name` (`name`)

  ) ENGINE=InnoDB DEFAULT CHARSET=utf8

  1 row in set (0.00 sec)

  [email protected] 12:37:41>insert into t1(name) values('a')

  此時檢查主備庫上t1的表結構都是一樣的,AUTO_INCREMENT 都是2.

  代碼如下:

  [email protected] 12:37:51>show create table t1 G

  *************************** 1. row ***************************

  Table: t1

  Create Table: CREATE TABLE `t1` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `name` varchar(20) DEFAULT NULL,

  PRIMARY KEY (`id`),

  UNIQUE KEY `name` (`name`)

  ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8

  1 row in set (0.00 sec)

  在主庫上進行進行replace into操作

  [email protected] 12:37:58>replace into t1(name) values('a');

  [email protected] 12:38:40>replace into t1(name) values('a');

  [email protected] 12:38:49>select * from t1;

  +----+------+

  | id | name |

  +----+------+

  | 3 | a |

  +----+------+

  1 row in set (0.00 sec)

  此時檢查主備庫中t1 表結構,請注意AUTO_INCREMENT=4

  代碼如下:

  [email protected] 12:38:51>show create table t1 G

  *************************** 1. row ***************************

  Table: t1

  Create Table: CREATE TABLE `t1` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `name` varchar(20) DEFAULT NULL,

  PRIMARY KEY (`id`),

  UNIQUE KEY `name` (`name`)

  ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8

  1 row in set (0.00 sec)

  從庫上t1的表結構 ,AUTO_INCREMENT=2

  代碼如下:

  [email protected] 12:39:35>show create table t1 G

  *************************** 1. row ***************************

  Table: t1

  Create Table: CREATE TABLE `t1` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `name` varchar(20) DEFAULT NULL,

  PRIMARY KEY (`id`),

  UNIQUE KEY `name` (`name`)

  ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8

  1 row in set (0.00 sec)

  [email protected] 12:39:43>select * from t1;

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 咸宁市| 南乐县| 东丰县| 汾西县| 阳东县| 湟源县| 阜城县| 昆山市| 德化县| 房山区| 宁明县| 衢州市| 贡觉县| 奉贤区| 莱芜市| 砚山县| 新乐市| 浑源县| 巴彦县| 拉孜县| 长宁区| 乌拉特中旗| 灵武市| 西藏| 赞皇县| 潮州市| 梧州市| 南召县| 吉水县| 陵川县| 思南县| 南城县| 绩溪县| 五家渠市| 汉源县| 姚安县| 固安县| 贺兰县| 托克逊县| 京山县| 博罗县|