Cov yuam sij tseem ceeb thiab cov yuam sij txawv teb chaws yog dab tsi?
Cov yuam sij tseem ceeb thiab cov yuam sij txawv teb chaws yog dab tsi?

Video: Cov yuam sij tseem ceeb thiab cov yuam sij txawv teb chaws yog dab tsi?

Video: Cov yuam sij tseem ceeb thiab cov yuam sij txawv teb chaws yog dab tsi?
Video: Dab ntxwg nyoos yog leej twg ...zaj no zoo heev. 2024, Plaub Hlis Ntuj
Anonim

Kev txheeb ze ntawm Lub Ntsiab Tseem Ceeb vs Foreign Key

A thawj tus yuam sij tshwj xeeb txheeb xyuas cov ntaub ntawv nyob rau hauv lub rooj sib tham database, whereas a txawv teb chaws key hais txog lub teb nyob rau hauv ib lub rooj uas yog tus thawj tus yuam sij ntawm lwm lub rooj.

Yog li, qhov txawv ntawm tus yuam sij tseem ceeb thiab tus yuam sij txawv teb chaws yog dab tsi?

Qhov sib txawv ntawm Cov Ntsiab Tseem Ceeb thiab Foreign Key . Thawj tus yuam sij tshwj xeeb txheeb xyuas cov ntaub ntawv hauv rooj. Tus yuam sij txawv teb chaws yog teb hauv table yog qhov tseem ceeb hauv lwm lub rooj. Los ntawm lub neej ntawd, Thawj tus yuam sij yog pawg index thiab cov ntaub ntawv hauv lub rooj database yog lub cev tsim hauv kab zauv ntawm pawg index.

Ib yam li ntawd, cov yuam sij tseem ceeb thiab txawv teb chaws hauv DBMS yog dab tsi? A thawj yog ib pawg ntawm cov cwj pwm / tus neeg sib tw tus yuam sij uas distinctify ib cov ntaub ntawv nyob rau hauv ib tug kev sib raug zoo. Txawm li cas los xij, a txawv teb chaws key nyob rau hauv ib lub rooj hais txog cov thawj tus yuam sij ntawm lwm lub rooj. Tsis muaj thawj tus yuam sij tus cwj pwm tuaj yeem muaj NULL qhov tseem ceeb whereas, a txawv teb chaws key tus cwj pwm tuaj yeem lees txais tus nqi NULL.

Xav txog qhov no, dab tsi yog qhov tseem ceeb thiab tus yuam sij txawv teb chaws nrog piv txwv?

A LUB TSEV KAWM NTAWV yog a tus yuam sij siv los txuas ob lub rooj ua ke. A LUB TSEV KAWM NTAWV yog ib daim teb (lossis sau cov teb) hauv ib lub rooj uas hais txog qhov TSEEM CEEB nyob rau hauv lwm lub rooj. Cov kab "PersonID" nyob rau hauv lub rooj "Tib neeg" yog lub TSEEM CEEB nyob rau hauv lub rooj "Cov neeg".

Dab tsi yog super thawj tus neeg sib tw thiab cov yuam sij txawv teb chaws?

Ib kem lossis pawg kab hauv ib lub rooj uas pab peb txheeb xyuas txhua kab hauv cov lus ntawd yog hu ua thawj tus yuam sij . Tag nrho cov cov yuam sij uas tsis yog thawj tus yuam sij hu ua alternate tus yuam sij . A tus yuam sij super tsis muaj tus cwj pwm rov qab hu ua tus neeg sib tw tus yuam sij.

Pom zoo: