Cov txheej txheem:

Dab tsi yog tus kheej kem hauv lub rooj?
Dab tsi yog tus kheej kem hauv lub rooj?

Video: Dab tsi yog tus kheej kem hauv lub rooj?

Video: Dab tsi yog tus kheej kem hauv lub rooj?
Video: nkauj noog hawj; kuv tsi yog tu koj hlub:cover 17/7/2021 2024, Kaum ib hlis
Anonim

Ib tus kheej kab yog a kem (tseem hu ua teb) nyob rau hauv ib lub database rooj uas yog tsim los ntawm cov nqi tsim los ntawm cov ntaub ntawv. Qhov no zoo ib yam li AutoNumber teb hauv Microsoft Access lossis ib ntu hauv Oracle. Hauv Microsoft SQL Server koj muaj kev xaiv rau cov noob (tus nqi pib) thiab qhov nce ntxiv.

Ntxiv mus, koj yuav ua li cas los tsim ib kab ke ntawm tus kheej hauv lub rooj?

Tsab ntawv

  1. CREATE TABLE dbo. Tmp_City(Id int NOT NULL IDENTITY(1, 1), Lub Npe varchar(50) NULL, Lub Tebchaws varchar(50),)
  2. ON [TSIJ]
  3. mus.
  4. SET IDENTITY_INSERT dbo. Tmp_City ON.
  5. mus.
  6. YOG TIAS EXISTS(xaiv * Los ntawm dbo. City)
  7. INSERT INTO dbo. Tmp_City(Id, Lub Npe, Lub Tebchaws)
  8. SELECT ID,

Ib yam li ntawd, kev siv tus kheej kem hauv SQL Server yog dab tsi? A SQL Server IDENTITY kab yog hom tshwj xeeb ntawm kem uas yog siv kom tau txais cov txiaj ntsig tseem ceeb raws li cov noob tau muab (pib point) thiab nce ntxiv. SQL Server muab rau peb nrog ntau lub luag haujlwm uas ua haujlwm nrog cov IDENTITY kab.

Hauv qhov no, txhua lub rooj yuav tsum muaj tus kheej kab ntawv?

10 Teb. Txhua lub rooj (tshwj tsis yog cov xwm txheej tsis tshua muaj) yuav tsum muaj PRIMARY KEY, uas yog tus nqi lossis ib txheej ntawm qhov tseem ceeb uas tsis paub txog kab. Saib ntawm no rau kev sib tham vim li cas. IDENTITY yog ib qho khoom ntiag tug ntawm a kem hauv SQL Server uas txhais tau tias cov kem yuav tau sau cia nrog incrementing qhov tseem ceeb.

Muaj pes tsawg tus neeg kab ntawv tuaj yeem muaj lub rooj?

Yog li, tsis yog, koj tsis tuaj yeem muaj ob kab ntawv qhia txog tus kheej . Koj tuaj yeem ua tus yuam sij tseem ceeb tsis yog pib nce ntxiv (tus kheej). Kho kom raug: msdn:CREATE TABLE (Transact-SQL) thiab CREATE TABLE (SQL Server 2000): Tsuas yog ib kem tus kheej tuaj yeem tsim ib lub rooj.

Pom zoo: