CTE yog dab tsi hauv SQL Server piv txwv?
CTE yog dab tsi hauv SQL Server piv txwv?

Video: CTE yog dab tsi hauv SQL Server piv txwv?

Video: CTE yog dab tsi hauv SQL Server piv txwv?
Video: Leng Yang - Yog Vim Dab Tsi (Official Full Song | Nkauj Tawm Tshiab) 2020/05/24 2024, Kaum ib hlis
Anonim

A Common Table Expression , kuj hu ua CTE hauv daim ntawv luv luv, yog ib lub npe hu ua qhov tshwm sim ib ntus uas koj tuaj yeem siv hauv SELECT, INSERT, UPDATE, lossis DELETE nqe lus. Cov CTE kuj tuaj yeem siv rau hauv Kev Pom Zoo. Nyob rau hauv tsab xov xwm no, peb yuav pom nyob rau hauv kom meej txog yuav ua li cas los tsim thiab siv CTEs los ntawm peb SQL Server.

Ib yam li ib tug yuav nug, CTE yog dab tsi hauv SQL nrog piv txwv?

A CTE ( Common Table Expression ) yog ib qho kev tshwm sim ib ntus uas koj tuaj yeem xa mus rau lwm qhov SELECT, INSERT, UPDATE, lossis DELETE nqe lus. Lawv tau qhia hauv SQL ntawv Server version 2005. Nco ntsoov: Tag nrho cov piv txwv rau zaj lus qhia no yog ua raws li Microsoft SQL ntawv Server Management Studio thiab AdventureWorks2012 database.

Qhov thib ob, yuav siv ob CTE hauv SQL Server li cas? Rau siv ntau CTE's nyob rau hauv ib qho lus nug koj tsuas yog yuav tsum ua kom tiav thawj zaug CTE , ntxiv ib qho comma, tshaj tawm lub npe thiab xaiv kab rau lwm qhov CTE , qhib CTE query nrog ib tug comma, sau cov lus nug, thiab nkag tau los ntawm a CTE cov lus nug tom qab hauv tib cov lus nug lossis los ntawm cov lus nug zaum kawg sab nraum CTEs.

Tsuas yog li ntawd, vim li cas peb thiaj siv CTE hauv SQL Server?

Vim li cas rau siv a CTE Hauv SQL ntawv , peb yuav siv sub-queries los koom nrog cov ntaub ntawv los yog lim cov ntaub ntawv los ntawm cov lus nug sub. Thaum twg peb xa tib cov ntaub ntawv los yog koom nrog tib cov ntaub ntawv teev tseg siv sub-query, cov cai tswj kev ruaj ntseg yuav nyuaj. A CTE ua kom zoo nyeem ntawv thiab kev saib xyuas yooj yim dua.

Qhov twg CTE khaws cia hauv SQL Server?

A CTE tshaj tawm hauv ib khaws cia txheej txheem yog li ntawd khaws cia ntawm disk. Muaj nuj nqi, txheej txheem, saib txhais thiab lwm yam yog khaws cia nyob rau hauv lub database uas lawv tsim. Qhov no txhais yog khaws cia ntawm disk, guaranteed. A CTE tshaj tawm hauv ib khaws cia txheej txheem yog li ntawd khaws cia ntawm disk.

Pom zoo: