Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Tampilan CONSTRAINT_COLUMN_USAGE
Tampilan CONSTRAINT_COLUMN_USAGE berisi semua kolom yang digunakan oleh
batasan.
Untuk batasan PRIMARY KEY, ini adalah kolom dari
tampilan KEY_COLUMN_USAGE. Untuk batasan FOREIGN KEY, ini adalah kolom
tabel yang direferensikan.
Skema
Tampilan INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE memiliki skema berikut:
Nama Kolom
Jenis data
Nilai
TABLE_CATALOG
STRING
Nama project yang berisi set data.
TABLE_SCHEMA
STRING
Nama set data yang berisi tabel. Juga
disebut sebagai datasetId.
TABLE_NAME
STRING
Nama tabel. Juga disebut sebagai
tableId.
COLUMN_NAME
STRING
Nama kolom.
CONSTRAINT_CATALOG
STRING
Nama project batasan.
CONSTRAINT_SCHEMA
STRING
Nama set data batasan.
CONSTRAINT_NAME
STRING
Nama batasan. Nama ini dapat berupa nama
kunci utama jika kolom digunakan oleh kunci utama atau nama
kunci asing jika kolom digunakan oleh kunci asing.
Cakupan dan sintaksis
Kueri terhadap tampilan ini harus menyertakan penentu set data. Untuk kueri dengan penentu set data, Anda harus memiliki izin untuk set data. Untuk mengetahui informasi selengkapnya, lihat Sintaksis.
Tabel berikut menampilkan cakupan region dan resource untuk tampilan ini:
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-17 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eCONSTRAINT_COLUMN_USAGE\u003c/code\u003e view details all columns involved in constraints, including \u003ccode\u003ePRIMARY KEY\u003c/code\u003e columns from \u003ccode\u003eKEY_COLUMN_USAGE\u003c/code\u003e and \u003ccode\u003eFOREIGN KEY\u003c/code\u003e columns from referenced tables.\u003c/p\u003e\n"],["\u003cp\u003eThe schema includes columns like \u003ccode\u003eTABLE_CATALOG\u003c/code\u003e, \u003ccode\u003eTABLE_SCHEMA\u003c/code\u003e, \u003ccode\u003eTABLE_NAME\u003c/code\u003e, \u003ccode\u003eCOLUMN_NAME\u003c/code\u003e, \u003ccode\u003eCONSTRAINT_CATALOG\u003c/code\u003e, \u003ccode\u003eCONSTRAINT_SCHEMA\u003c/code\u003e, and \u003ccode\u003eCONSTRAINT_NAME\u003c/code\u003e, providing comprehensive constraint information.\u003c/p\u003e\n"],["\u003cp\u003eQueries against the \u003ccode\u003eCONSTRAINT_COLUMN_USAGE\u003c/code\u003e view require a dataset qualifier, and users need appropriate permissions for the specified dataset.\u003c/p\u003e\n"],["\u003cp\u003eYou can query the view for a single table's constraints by specifying the table name in the \u003ccode\u003eWHERE\u003c/code\u003e clause or retrieve all constraints within a dataset by omitting it.\u003c/p\u003e\n"],["\u003cp\u003eThe view displays a row for each constraint, or states that there is no data to display if there are no constraints in the specified table or dataset.\u003c/p\u003e\n"]]],[],null,["# CONSTRAINT_COLUMN_USAGE view\n============================\n\nThe `CONSTRAINT_COLUMN_USAGE` view contains all columns used by\n[constraints](/bigquery/docs/primary-foreign-keys).\nFor `PRIMARY KEY` constraints, these are the columns from\nthe `KEY_COLUMN_USAGE` view. For `FOREIGN KEY` constraints, these are the columns\nof the referenced tables.\n\nSchema\n------\n\nThe `INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE` view has the following schema:\n\nScope and syntax\n----------------\n\nQueries against this view must include a dataset qualifier. For queries with a\ndataset qualifier, you must have permissions for the dataset. For more\ninformation see\n[Syntax](/bigquery/docs/information-schema-intro#syntax).\nThe following table shows the region and resource scopes for this view:\n\nReplace the following:\n\n- Optional: \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: the ID of your Google Cloud project. If not specified, the default project is used.\n\n\u003cbr /\u003e\n\nExamples\n--------\n\nThe following query shows the constraints for a single table in a dataset: \n\n```googlesql\nSELECT *\nFROM PROJECT_ID.DATASET.INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE\nWHERE table_name = TABLE;\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: Optional. The name of your cloud project. If not specified, this command uses the default project.\n- \u003cvar translate=\"no\"\u003eDATASET\u003c/var\u003e: The name of your dataset.\n- \u003cvar translate=\"no\"\u003eTABLE\u003c/var\u003e: The name of the table.\n\nConversely, the following query shows the constraints for all tables in a single dataset. \n\n```googlesql\nSELECT *\nFROM PROJECT_ID.DATASET.INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE;\n```\n\nWith existing constraints, the query results are similar to the following: \n\n```\n+-----+---------------------+--------------+------------+-------------+---------------------+-------------------+-------------------------+\n| row | table_catalog | table_schema | table_name | column_name | constraint_catalog | constraint_schema | constraint_name |\n+-----+---------------------+--------------+------------+-------------+---------------------+-------------------+-------------------------+\n| 1 | myConstraintCatalog | myDataset | orders | o_okey | myConstraintCatalog | myDataset | orders.pk$ |\n| 2 | myConstraintCatalog | myDataset | orders | o_okey | myConstraintCatalog | myDataset | lineitem.lineitem_order |\n+-----+---------------------+--------------+------------+-------------+---------------------+-------------------+-------------------------+\n```\n| **Note:** `lineitem.lineitem_order` is the foreign key defined in the `lineitem` table.\n\nIf the table or dataset has no constraints, the query results look like this: \n\n```\n+-----------------------------+\n| There is no data to display |\n+-----------------------------+\n```"]]