国产乱子轮XXX农村-精品久久国产字幕高潮-精品国产乱码久久久久久1区2区-国产AV一区二区三区传媒

深圳網(wǎng)站制作中mysql一些insert/update的用法

發(fā)布時間:2025-02-20 點擊:58
mysql一些insert/update的用法
在mysql中進行條件插入數(shù)據(jù)時,可能會用到以下語句,現(xiàn)小結(jié)一下。我們先建一個簡單的表來作為測試:
1
2
3
4
5
6
7
8
9
10
11
create table `books` (
`id` int(11) not null auto_increment,
`name` varchar(200) not null,
primary key (`id`),
unique key `newindex1` (`name`)
) engine=innodb default charset=utf8;
1.insert ignore into
當(dāng)插入數(shù)據(jù)時,如出現(xiàn)錯誤時,如重復(fù)數(shù)據(jù),將不返回錯誤,只以警告形式返回。所以使用ignore請確保語句本身沒有問題,否則也會被忽略掉。例如:
1
insert ignore into books (name) values (mysql manual)
2.on duplicate key update
當(dāng)primary或者unique重復(fù)時,則執(zhí)行update語句,如update后為無用語句,如id=id,則同1功能相同,但錯誤不會被忽略掉。例如,為了實現(xiàn)name重復(fù)的數(shù)據(jù)插入不報錯,可使用一下語句:
1
insert into books (name) values (mysql manual) on duplicate key update id = id
3.insert … select … where not exist
根據(jù)select的條件判斷是否插入,可以不光通過primary 和unique來判斷,也可通過其它條件。例如:
1
insert into books (name) select mysql manual from dual where not exists (select id from books where id = 1)
4.replace into
如果存在primary or unique相同的記錄,則先刪除掉。再插入新記錄。
1
replace into books select 1, mysql manual from books


網(wǎng)站建設(shè)效果應(yīng)該注意的問題
高端網(wǎng)站設(shè)計 為什么離不開溝通
營銷型網(wǎng)站具備的主要特征有哪些
什么是頁面活躍度?
極簡設(shè)計不僅好看,還能顯著減少網(wǎng)站跳出率-佛山網(wǎng)站設(shè)計
佛山網(wǎng)站建設(shè)公司我們該怎樣在網(wǎng)站建設(shè)中設(shè)計關(guān)鍵詞
網(wǎng)站設(shè)計中的排版與配色如何搭配自如
你們公司網(wǎng)站建設(shè)是怎么收費的?