Check hauv SQL yog dab tsi?
Check hauv SQL yog dab tsi?

Video: Check hauv SQL yog dab tsi?

Video: Check hauv SQL yog dab tsi?
Video: Hmong new song 2016 - Yog dab tsi - Xub Hluav Taws (Official MV) 2024, Hlis ntuj nqeg
Anonim

SQL CHECK Kev txwv. Cov KOOB kev txwv yog siv los txwv tus nqi ntau yam uas tuaj yeem muab tso rau hauv kab. Yog koj txhais a KOOB txwv ntawm ib lub rooj nws tuaj yeem txwv qhov tseem ceeb hauv qee kab raws li qhov tseem ceeb hauv lwm kab hauv kab.

Ntxiv mus, dab tsi yog check hauv database?

A kuaj constraint yog ib hom kev ncaj ncees txwv hauv SQL uas qhia txog qhov yuav tsum tau ua uas yuav tsum tau ua raws li txhua kab hauv ib qho database rooj. Nws tuaj yeem xa mus rau ib kem, lossis ntau kab ntawm lub rooj. Qhov tshwm sim ntawm qhov predicate tuaj yeem yog TRUE, FALSE, lossis UNKNOWN, nyob ntawm seb muaj NULLs.

Tsis tas li ntawd, koj yuav hloov kho qhov kev txwv tsis pub dhau SQL li cas? Siv SQL Server Management Studio

  1. Hauv Object Explorer, right-click lub rooj uas muaj cov kev txwv kos thiab xaiv Tsim.
  2. Nyob rau ntawm Table Designer ntawv qhia zaub mov, nyem Kos Cov Kev Txwv.
  3. Nyob rau hauv Cheeb Tsam Constraints dialog box, nyob rau hauv Selected Check Constraint, xaiv qhov txwv koj xav hloov.

Ib yam li ntawd, nws tau nug, koj yuav ua li cas ntxiv daim tshev hauv SQL?

Lub syntax rau tsim ib kuaj kev txwv hauv ALTER TABLE nqe lus hauv SQL ntawv Server (Kev hloov pauv- SQL ntawv ) yog: ALTER TABLE table_name Ntxiv CONSTRAINT constraint_name KOOB (column_name condition); table_npe. Lub npe ntawm lub rooj uas koj xav hloov los ntawm ntxiv a kuaj txwv.

Lub hom phiaj ntawm daim ntawv txheeb xyuas cov lus nug yog dab tsi?

Cov txwv xyuas kom meej tias yog tias tus nqi nkag mus rau hauv kab ntawv teev tseg, nws yuav tsum twb muaj nyob rau hauv "ib" lub rooj lossis cov ntaub ntawv tsis ntxiv. UNIQUE. Xyuas kom meej tias tag nrho cov ntaub ntawv muaj nuj nqis khaws cia rau hauv ib kab ntawv tshwj xeeb. Nws txawv ntawm PRIMARY KEY vim nws tso cai rau NULL qhov tseem ceeb. KOOB.

Pom zoo: