Cov txheej txheem:
Video: Yuav ua li cas koj tsim tus yuam sij txawv teb chaws hauv pgAdmin 4?
2024 Tus sau: Lynn Donovan | [email protected]. Kawg hloov kho: 2023-12-15 23:47
Hauv pgAdmin 4, ntawm no yog cov kauj ruam:
- Right-click rau ntawm lub rooj thiab xaiv Properties.
- Nyob rau hauv lub dialog uas tshwm, nyem qhov txwv / Foreign Key .
- Nyem lub + icon nyob rau sab xis ntawm lub qhov rais Tus yuam sij txawv teb chaws rooj.
Yog li ntawd, kuv yuav ntxiv tus yuam sij txawv teb chaws hauv postgresql li cas?
Ntxiv CONSTRAINT constraint_name LUB TSEV KAWM NTAWV (c1) REFERENCES parent_table (p1); Ib daim ntawv kawg thaum koj xav tau ntxiv tus yuam sij txawv teb chaws txwv nrog ON DELETE CASCADE rau lub rooj uas twb muaj lawm, koj yuav tsum ua cov kauj ruam hauv qab no: Tso cov uas twb muaj lawm txawv teb chaws key txwv. Ntxiv ib new txawv teb chaws key txwv nrog ON DELETE CASCADE kev txiav txim.
Ib sab saum toj no, Kuv yuav ua li cas khiav SQL hauv pgAdmin 4? Yog tias koj nkag mus rau cov cuab yeej Query ntawm Query Tool menu xaiv ntawm cov cuab yeej ntawv qhia zaub mov, koj tuaj yeem:
- Tshaj tawm ad-hoc SQL queries.
- Execute arbitrary SQL commands.
- Txuag cov ntaub ntawv tso tawm nyob rau hauv lub vaj huam sib luag tso zis rau CSV cov ntaub ntawv.
- Tshawb xyuas cov phiaj xwm kev ua tiav ntawm SQL nqe lus hauv cov ntawv nyeem lossis cov duab nraaj.
Ntawm no, koj ua li cas los tsim ib qho tseem ceeb hauv pgAdmin?
- Xaiv lub rooj koj xav tau.
- Ctrl + Alt + Enter lossis right-click / Properties.
- Xaiv "Kev txwv" tab.
- Nyob rau sab laug-hauv qab ntawm daim ntawv koj yuav pom qhov kev xaiv "Primary Key"
- Nyem ntxiv.
- Xaiv "Kem" tab.
- Xaiv kab uas koj xav tau ua tus yuam sij.
- Nyem ntxiv.
Koj tsim ib lub rooj hauv pgAdmin 4 li cas?
Tsim cov lus hauv pgAdmin 4 nrog autoincrement kab. Qhib pgAdmin cuab yeej. Nthuav cov nodes hauv koj cov ntaub ntawv thiab mus rau qhov Rooj node. Right click lub Rooj node thiab xaiv Tsim -> Rooj.
Pom zoo:
Ib tus yuam sij tseem ceeb puas tuaj yeem muaj ob tus yuam sij txawv teb chaws?
Nws yog qhov zoo kawg nkaus kom muaj ob kab ntawv tseem ceeb txawv teb chaws xa mus rau tib lub ntsiab lus tseem ceeb hauv ib lub rooj sib txawv vim tias txhua tus nqi tseem ceeb txawv teb chaws yuav siv cov ntaub ntawv sib txawv hauv cov lus hais
Cov yuam sij tseem ceeb thiab cov yuam sij txawv teb chaws yog dab tsi?
Relation of Primary Key vs Foreign Key Ib lub ntsiab tseem ceeb tshwj xeeb qhia cov ntaub ntawv nyob rau hauv lub rooj sib tham database, whereas tus yuam sij txawv teb chaws yog hais txog lub teb nyob rau hauv ib lub rooj uas yog lub ntsiab tseem ceeb ntawm lwm lub rooj
Puas yog tus yuam sij tseem ceeb kuj yog tus yuam sij txawv teb chaws?
Cov yuam sij tseem ceeb ib txwm yuav tsum muaj qhov tshwj xeeb, cov yuam sij txawv teb chaws yuav tsum tso cai rau qhov tsis muaj txiaj ntsig yog tias lub rooj yog ib qho kev sib raug zoo. Nws yog qhov zoo kawg nkaus siv tus yuam sij txawv teb chaws los ua tus yuam sij tseem ceeb yog tias lub rooj sib txuas los ntawm kev sib raug zoo ib leeg, tsis yog ib qho kev sib raug zoo
Ib tus yuam sij txawv teb chaws puas tuaj yeem siv lwm tus yuam sij txawv teb chaws?
1 Teb. Tus yuam sij txawv teb chaws tuaj yeem siv txhua qhov chaw uas txhais tau tias nws txawv. Yog hais tias qhov tshwj xeeb teb yog nws tus kheej txhais tau tias yog tus yuam sij txawv teb chaws, nws tsis txawv. Yog tias nws yog thaj chaw tshwj xeeb, nws kuj tuaj yeem yog lub hom phiaj ntawm lwm FK
Tus yuam sij tseem ceeb thib ob thiab tus yuam sij txawv teb chaws yog dab tsi?
Txawv Teb Chaws Tseem Ceeb: Yog Lub Ntsiab Tseem Ceeb ib lub rooj tshwm (hloov-hais) hauv lwm lub rooj. Secondary (los yog lwm txoj kev) Key: Puas yog ib qho chaw hauv lub rooj uas tsis raug xaiv los ua ib qho ntawm ob hom saum toj no