Cov txheej txheem:

Kuv yuav ua li cas thiaj tau txais cov npe ntawm kab hauv SQL?
Kuv yuav ua li cas thiaj tau txais cov npe ntawm kab hauv SQL?

Video: Kuv yuav ua li cas thiaj tau txais cov npe ntawm kab hauv SQL?

Video: Kuv yuav ua li cas thiaj tau txais cov npe ntawm kab hauv SQL?
Video: Yuav ua li cas thiaj khiav dim lub ntiajteb no 2024, Kaum ib hlis
Anonim

Microsoft SQL ntawv Server Management Studio 2008 R2: Hauv a nug editor, yog tias koj tseem ceeb cov ntawv sau npe (ex dbo. MyTable) thiab ntaus ALT + F1, koj yuav tau txais lis kab npe, hom, ntev, thiab lwm yam.

Tsuas yog li ntawd, kuv yuav ua li cas thiaj li tau txais cov npe ntawm kab hauv lub rooj SQL?

Cov lus nug thawj zaug no yuav rov qab tag nrho cov ntxhuav hauv cov ntaub ntawv koj tab tom nug

  1. Xaiv TABLE_NAME los ntawm INFORMATION_SCHEMA. TABLES.
  2. SELECT TABLE_NAME, COLUMN_NAME NTAWM INFORMATION_SCHEMA. COLUMNS.
  3. SELECT COLUMN_NAME NTAWM INFORMATION_SCHEMA. COLUMNS WHERE TABLE_NAME = 'Album'
  4. YOG TAM SIM NO (XIM * Los ntawm INFORMATION_SCHEMA.

Kuv yuav ua li cas thiaj tau txais cov npe ntawm txhua lub rooj hauv SQL? Muaj ntau qhov kev pom hauv phau ntawv txhais lus cov ntaub ntawv koj tuaj yeem nug, thiab qhov twg koj tuaj yeem pom yuav nyob ntawm koj cov cai. Qhov yooj yim tshaj plaws kom pom tag nrho cov rooj nyob rau hauv lub database yog nug cov all_tables saib: Xaiv tus tswv, table_name FROM all_tables; Qhov no yuav qhia tus tswv (tus neeg siv) thiab lub npe ntawm tus rooj.

Tom qab ntawd, ib tus tuaj yeem nug, Kuv yuav ua li cas thiaj tau txais cov npe ntawm txhua lub rooj thiab kab hauv SQL Server?

Cov nram qab no Microsoft SQL Server T-SQL cov lus nug sau tag nrho cov ntxhuav nrog kab thiab cov ntaub ntawv siv INFORMATION_SCHEMA saib cov ntaub ntawv database metadata:

  1. USE AdventureWorks2008;
  2. SELECT SchemaName = c. table_schema,
  3. TableName = c.
  4. ColumnName = c.
  5. DataType = data_type.
  6. Los ntawm information_schema.
  7. INNER JOIN information_schema.
  8. ON c.

SQL Select nqe lus yog dab tsi?

Cov SQL SELECT nqe lus xa rov qab cov txiaj ntsig ntawm cov ntaub ntawv los ntawm ib lossis ntau lub rooj. A SELECT nqe lus retrieves xoom lossis ntau kab los ntawm ib lossis ntau lub rooj database lossis database views. ORDER BY qhia qhov kev txiav txim kom rov qab cov kab. AS muab lub npe hu ua alias uas tuaj yeem siv los hloov npe ib ntus cov ntxhuav lossis kab.

Pom zoo: