CTE mssql yog dab tsi?
CTE mssql yog dab tsi?

Video: CTE mssql yog dab tsi?

Video: CTE mssql yog dab tsi?
Video: What is CTE ( Common Table Expression) in SQL Server ? | SQL Server CTE 2024, Hlis ntuj nqeg
Anonim

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 Server version 2005. Lawv yog SQL-raws li thiab ib feem ntawm ANSI SQL 99 specification. A CTE ib txwm rov qab ib qho txiaj ntsig.

Tom qab 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.

Ib sab saum toj no, CTE yog dab tsi hauv SQL Server thiab nws siv?

SQL Server CTE Cov hauv paus. Taw qhia hauv SQL Server 2005, cov lus qhia dav dav ( CTE ) yog lub npe teev npe ib ntus uas koj tuaj yeem siv hauv SELECT, INSERT, UPDATE, lossis DELETE nqe lus. Koj tuaj yeem ua tau siv a CTE hauv daim ntawv CREATE VIEW, uas yog ib feem ntawm tus saib SELECT nug.

Koj ua CTE li cas?

Koj tuaj yeem siv a CTE hauv a Tsim ib qho kev pom, raws li ib feem ntawm qhov saib qhov SELECT query. Ntxiv rau, raws li SQL Server 2008, koj tuaj yeem ntxiv ib qho CTE mus rau MERGE cov lus qhia tshiab. Tom qab koj txhais koj cov lus nrog CTEs, koj tuaj yeem xa mus rau CTEs raws li koj xav xa mus rau lwm lub rooj.

Pom zoo: