久久机这里只有精品,国产69精品一区二区亚洲孕妇,91精品国产综合久久婷婷香蕉,午夜久久久久久电影

最新活動(dòng):電腦PC端+手機(jī)端+微網(wǎng)站+自適應(yīng)網(wǎng)頁(yè)多模板選擇-建站388元起價(jià)!!!
當(dāng)前位置:主頁(yè) > 網(wǎng)站建設(shè) > 多表關(guān)聯(lián)同時(shí)更新多條不同的記錄方法分享建站

多表關(guān)聯(lián)同時(shí)更新多條不同的記錄方法分享建站

時(shí)間:2023-05-21 20:05:21 閱讀: 文章分類: 網(wǎng)站建設(shè) 作者: 網(wǎng)絡(luò)小編

導(dǎo)讀:1建站知識(shí)因?yàn)轫?xiàng)目要求實(shí)現(xiàn)一次性同時(shí)更新多條不同的記錄的需求,和同事討論了一個(gè)比較不錯(cuò)的方案,這里供大家參考下網(wǎng)站優(yōu)化seo培訓(xùn)網(wǎng)站seo優(yōu)化軟件。

網(wǎng)站優(yōu)化seo培訓(xùn)網(wǎng)站seo優(yōu)化軟件以下為測(cè)試?yán)印?1.首先創(chuàng)建兩張臨時(shí)表并錄入測(cè)試數(shù)據(jù):

復(fù)制代碼 代碼如下:

create table #temptest1 ( id int, name1 varchar(50), age int ) create table #temptest2 ( id int, name1 varchar(50), age int )

查詢出此時(shí)的表數(shù)據(jù)為:

#temptest1                 #temptest2

 

2.現(xiàn)在要將#temptest2中的年齡更新到相應(yīng)的#temptest1中的年齡。

其實(shí)就是讓[表1]中ID為1的年齡改成19,同時(shí)ID為2的年齡改成20。

當(dāng)然這里的要求是只用一句SQL,不能用循環(huán)。

結(jié)果如下:

 

實(shí)現(xiàn)方法如下:

Update t1 

Set t1 .age = t2.age

From  #temptest1 t1

Join #temptest2 t2

On  t1.id = t2.id

 

(補(bǔ)充)Sql Server 2008 Merge命令寫法:

merge into #temptest1 t1 using(select age,id from #temptest2) t2on t1.id = t2.idwhen matched thenupdate set t1.age = t2.age

 

是不是挺有趣的Sql。如何一次性更新多條不同值的記錄標(biāo)題可能沒說(shuō)清楚,假設(shè)有這樣兩張表:

復(fù)制代碼 代碼如下:

create table testA( id number, eng varchar2(3), chi varchar2(3) ) create table testB( id number, eng varchar2(3), chi varchar2(3), anythingother varchar2(1) )

現(xiàn)有記錄 testA: ID ENG CHI =============== 1 a 一 2 b 二 3 c 三 testB: ID ENG CHI ANY.... ================= 1 d 四 2 e 五 3 f 六 我想把testB中的記錄的ENG,CHI字段更新到testA中去,以ID來(lái)對(duì)應(yīng)。 CODE: SQL> set autot on SQL> update ta set ta.b=(select tb.b from tb where ta.a=tb.a) where exists (select 1 from tb where ta.a=tb.a); 已更新4行。 已用時(shí)間: 00: 00: 00.01 執(zhí)行計(jì)劃 -網(wǎng)站seo優(yōu)化軟件--------------------------------------------------------- Plan hash value: 1137212925 -------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------------- | 0 | UPDATE STATEMENT | | 5 | 165 | 20 (30)| 00:00:01 | | 1 | UPDATE | TA | | | | | |* 2 | HASH JOIN SEMI | | 5 | 165 | 5 (20)| 00:00:01 | | 3 | TABLE ACCESS FULL | TA | 5 | 100 | 2 (0)| 00:00:01 | | 4 | VIEW | VW_SQ_1 | 4 | 52 | 2 (0)| 00:00:01 | | 5 | TABLE ACCESS FULL| TB | 4 | 52 | 2 (0)| 00:00:01 | |* 6 | TABLE ACCESS FULL | TB | 1 | 26 | 2 (0)| 00:00:01 | -------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("TA如何seo優(yōu)化推廣網(wǎng)站"."A"="ITEM_1") 6 - filter("TB"."A"=:B1) Note ----- - dynamic sampling used for this statement (level=2) 統(tǒng)計(jì)信息 ---------------------------------------------------------- 0 recursive calls 4 db block gets 23 consistent gets 0 physical reads 1004 redo size 840 bytes sent via SQL*Net to client 856 bytes received via SQL*Net from client 3 SQL*Net roundtrips to/from client 1 sorts (memory) 0 sorts (disk) 4 rows processed SQL> update ta set ta.b=(select tb.b from tb where ta.a=tb.a) where ta.a= (select tb.a from tb where ta.a=tb.a); 已更新4行。 已用時(shí)間: 00: 00: 00.00 執(zhí)行計(jì)劃 ---------------------------------------------------------- Plan hash value: 3571861550 ---------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ---------------------------------------------------------------------------- | 0 | UPDATE STATEMENT | | 1 | 20 | 7 (15)| 00:00:01 | | 1 | UPDATE | TA | | | | | |* 2 | FILTER | | | | | | | 3 | TABLE ACCESS FULL| TA | 5 | 100 | 2 (0)| 00:00:01 | |* 4 | TABLE ACCESS FULL| TB | 1 | 13 | 2 (0)| 00:00:01 | |* 5 | TABLE ACCESS FULL | TB | 1 | 26 | 2 (0)| 00:00:01 | ---------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - filter("TA"."A"= (SELECT "TB"."A" FROM "TB" "TB" WHERE "TB"."A"=:B1)) 4 - filter("TB"."A"=:B1) 5 - filter("TB"."A"=:B1) Note ----- - dynamic sampling used for this statement (level=2) 統(tǒng)計(jì)信息 ---------------------------------------------------------- 11 recursive calls 1 db block gets 53 consistent gets 0 physical reads 588 redo size 840 bytes sent via SQL*Net to client 858 bytes received via SQL*Net from client 3 SQL*Net roundtrips to/from client 1 sorts (memory) 0 sorts (disk) 4 rows processed 如果 create unique index tb_a_uidx on tb(a); [Copy to clipboard] [ - ] CODE: SQL> update (select ta.b tab1 ,tb.b tbb from ta,tb where ta.a=tb.a) set tab1=tbb; 已更新4行。 已用時(shí)間: 00: 00: 00.01 執(zhí)行計(jì)劃 ---------------------------------------------------------- Plan hash value: 1761655026 ---------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -----------------------------------------------seo網(wǎng)站排名優(yōu)化軟件----------------------------- | 0 | UPDATE STATEMENT | | 4 | 184 | 5 (20)| 00:00:01 | | 1 | UPDATE | TA | | | | | |* 2 | HASH JOIN | | 4 | 184 | 5 (20)| 00:00:01 | | 3 | TABLE ACCESS FULL| TB | 4 | 104 | 2 (0)| 00:00:01 | | 4 | TABLE ACCESS FULL| TA | 5 | 100 | 2 (0)| 00:00:01 | ---------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("TA"."A"="TB"."A") Note ----- - dynamic sampling used for this statement (level=2) 統(tǒng)計(jì)信息 ---------------------------------------------------------- 8 recursive calls 4 db block gets 17 consistent gets 0 physical reads 1004 redo size 840 bytes sent via SQL*Net to client 827 bytes received via SQL*Net from client 3 SQL*Net roundtrips to/from client 3 sorts (memory) 0 sorts (disk) 4 rows processed

關(guān)鍵詞標(biāo)簽: 不同 多條

聲明: 本文由我的SEOUC技術(shù)文章主頁(yè)發(fā)布于:2023-05-21 ,文章多表關(guān)聯(lián)同時(shí)更新多條不同的記錄方法分享建站主要講述多條,不同,多表關(guān)聯(lián)同時(shí)更新多條不同的記錄方法網(wǎng)站建設(shè)源碼以及服務(wù)器配置搭建相關(guān)技術(shù)文章。轉(zhuǎn)載請(qǐng)保留鏈接: http://www.bifwcx.com/article/web_3884.html

我的IDC 網(wǎng)站建設(shè)技術(shù)SEOUC.COM
專注網(wǎng)站建設(shè),SEO優(yōu)化,小程序設(shè)計(jì)制作搭建開發(fā)定制網(wǎng)站等,數(shù)千家網(wǎng)站定制開發(fā)案例,網(wǎng)站推廣技術(shù)服務(wù)。
  • 5000+合作客服
  • 8年從業(yè)經(jīng)驗(yàn)
  • 150+覆蓋行業(yè)
  • 最新熱門源碼技術(shù)文章

    主站蜘蛛池模板: 格尔木市| 长岭县| 射阳县| 台湾省| 胶州市| 长沙县| 南安市| 古交市| 双流县| 武平县| 香港| 阿拉尔市| 罗江县| 辛集市| 奉节县| 教育| 新邵县| 富川| 长岭县| 南靖县| 乐安县| 兴业县| 台山市| 崇阳县| 扶绥县| 迭部县| 彝良县| 陆良县| 荥经县| 永胜县| 郓城县| 龙井市| 新沂市| 保德县| 阿克陶县| 怀集县| 清苑县| 吴堡县| 阿拉善左旗| 伊金霍洛旗| 柞水县|