最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

MySQL數(shù)據(jù)庫高級(jí)數(shù)據(jù)操作之新增數(shù)據(jù)

 更新時(shí)間:2022年06月01日 10:48:53   作者:彭世瑜  
這篇文章主要介紹了MySQL數(shù)據(jù)庫高級(jí)數(shù)據(jù)操作之新增數(shù)據(jù),文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下

多數(shù)據(jù)插入

只要寫一次insert,可以插入多條數(shù)據(jù)

基本語法:

insert into 表名 [(字段列表)] values (值列表), (值列表)...;
create table my_student(
    id int primary key auto_increment,
    name varchar(10)
);
insert into my_student (name) values ('張三'), ('李四'), ('王五');

mysql> select * from my_student;
+----+--------+
| id | name   |
+----+--------+
|  1 | 張三   |
|  2 | 李四   |
|  3 | 王五   |
+----+--------+

主鍵沖突

insert into my_student (id, name) values (1, '張飛');
ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'

1、主鍵沖突更新

如果插入過程中主鍵沖突,那么采用更新方式

insert into 表名 [(字段列表)] on duplicate key update 字段=新值;

insert into my_student (id, name) values (1, '張飛') 
on duplicate key update name = '張飛';
mysql> select * from my_student;
+----+--------+
| id | name   |
+----+--------+
|  1 | 張飛   |
|  2 | 李四   |
|  3 | 王五   |
+----+--------+

2、主鍵沖突替換

replace into 表名 [(字段列表)] values (值列表);
replace into  my_student (id, name) values (1, '劉備');
mysql> select * from my_student;
+----+--------+
| id | name   |
+----+--------+
|  1 | 劉備   |
|  2 | 李四   |
|  3 | 王五   |
+----+--------+

蠕蟲復(fù)制

一分為二,成倍增加

從已有的數(shù)據(jù)中獲取數(shù)據(jù),并且插入到數(shù)據(jù)表中

insert into 表名 [(字段列表)] select */字段列表 from 表名;
insert into my_student (name) select name from my_student;
mysql> select * from my_student;
+----+--------+
| id | name   |
+----+--------+
|  1 | 劉備   |
|  2 | 李四   |
|  3 | 王五   |
|  4 | 劉備   |
|  5 | 李四   |
|  6 | 王五   |
+----+--------+

注意:

  • 蠕蟲復(fù)制通常是重復(fù)數(shù)據(jù),可以短期內(nèi)復(fù)制大量的數(shù)據(jù),從而測試表的壓力
  • 需要注意主鍵沖突

到此這篇關(guān)于MySQL數(shù)據(jù)庫高級(jí)數(shù)據(jù)操作之新增數(shù)據(jù)的文章就介紹到這了,更多相關(guān)MySQL新增數(shù)據(jù)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

梁平县| 织金县| 济南市| 秦皇岛市| 思南县| 林西县| 望奎县| 开化县| 闸北区| 荣成市| 巩义市| 肇源县| 广德县| 调兵山市| 宝鸡市| 资阳市| 义马市| 即墨市| 宜兰市| 贡山| 平陆县| 石景山区| 玛沁县| 江安县| 恩平市| 乌鲁木齐市| 胶州市| 沙雅县| 米易县| 铅山县| 女性| 贵德县| 长春市| 宣恩县| 油尖旺区| 米易县| 麦盖提县| 凤阳县| 南江县| 高台县| 德化县|