Qhov twg hauv qab no sawv cev rau qhov zoo ntawm tus yuam sij surrogate?
Qhov twg hauv qab no sawv cev rau qhov zoo ntawm tus yuam sij surrogate?

Video: Qhov twg hauv qab no sawv cev rau qhov zoo ntawm tus yuam sij surrogate?

Video: Qhov twg hauv qab no sawv cev rau qhov zoo ntawm tus yuam sij surrogate?
Video: zoo nyob tag npaum no xoom ceev2 kom phev los tso mam saib seb yog leej twg 2024, Kaum ib hlis
Anonim

A surrogate key yog ib qho tshwj xeeb, DBMS-muab tus cim siv los ua thawj tus yuam sij ntawm kev sib txheeb. Nws qhov zoo yog: (1) Lawv txawv nyob rau hauv lub rooj thiab yeej tsis hloov. (2) Lawv raug xa mus thaum kab yog tsim thiab rhuav tshem thaum kab yog tshem tawm.

Ib yam li ntawd, nws raug nug, qhov twg hauv qab no yog qhov zoo ntawm kev siv tus yuam sij surrogate?

Hauv qab no yog ib co qhov zoo ntawm kev siv tus yuam sij surrogate nyob rau hauv cov ntaub ntawv warehouse: Nrog kev pab los ntawm tus yuam sij surrogate , koj tuaj yeem sib sau ua ke cov ntaub ntawv sib txawv rau cov ntaub ntawv warehouse yog tias lawv tsis muaj ntuj lossis kev lag luam cov yuam sij . Koom nrog cov rooj (qhov tseeb thiab qhov ntev) siv tus yuam sij surrogate yog sai li no ua tau zoo dua.

Dab tsi yog tus yuam sij surrogate thiab vim li cas siv lawv? A tus tseem ceeb yog a tus yuam sij uas tsis muaj cov ntsiab lus lossis kev lag luam. Nws yog tsim "artificially" thiab tsuas yog rau lub hom phiaj ntawm kev txheeb xyuas cov ntaub ntawv. Feem ntau siv version ntawm a tus tseem ceeb yog ib qho kev nce zuj zus los yog "counter" tus nqi (piv txwv li 1, 2, 3).

Tom qab ntawd, dab tsi yog qhov zoo ntawm tus yuam sij surrogate Vim li cas peb tsis tuaj yeem siv cov yuam sij ntuj?

Surrogate yuam sij yuav tsis ua hloov kho raws sijhawm. Surrogate yuam sij feem ntau yog cov lej, uas tsuas yog xav tau 4 bytes khaws cia, yog li thawj tus yuam sij index structure yuav ua me me dua lawv natural key counterparts. Muaj cov qauv ntsuas me me txhais tau tias kev ua tau zoo dua rau JOIN cov haujlwm.

Dab tsi yog siv los ua tus yuam sij surrogate?

A tus tseem ceeb yog txhua kab los yog kab ke uas tuaj yeem tshaj tawm tias yog thawj tus yuam sij es tsis yog "tiag" lossis ntuj tus yuam sij . Hom ntau tshaj ntawm tus tseem ceeb yog ib qho incrementing integer, xws li auto_increment kem hauv MySQL, lossis ib ntu hauv Oracle, lossis kab ke tus kheej hauv SQL Server.

Pom zoo: