Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Ansicht CONSTRAINT_COLUMN_USAGE
Die Ansicht CONSTRAINT_COLUMN_USAGE enthält alle Spalten, die von Einschränkungen verwendet werden.
Für PRIMARY KEY-Einschränkungen sind dies die Spalten aus der Ansicht KEY_COLUMN_USAGE. Für FOREIGN KEY-Einschränkungen sind dies die Spalten der referenzierten Tabellen.
Schema
Die Ansicht INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE hat das folgende Schema:
Spaltenname
Datentyp
Wert
TABLE_CATALOG
STRING
Der Name des Projekts, zu dem das Dataset gehört.
TABLE_SCHEMA
STRING
Der Name des Datasets, das die Tabelle enthält (auch als datasetId bezeichnet)
TABLE_NAME
STRING
Der Name der Tabelle, auch als tableId bezeichnet.
COLUMN_NAME
STRING
Der Name der Spalte,
CONSTRAINT_CATALOG
STRING
Der Name des Einschränkungsprojekts.
CONSTRAINT_SCHEMA
STRING
Der Name des Einschränkungs-Datasets.
CONSTRAINT_NAME
STRING
Der Name der Einschränkung. Es kann der Name des Primärschlüssels sein, wenn die Spalte vom Primärschlüssel verwendet wird, oder der Name des Fremdschlüssels, wenn die Spalte von einem Fremdschlüssel verwendet wird.
Bereich und Syntax
Für Abfragen dieser Ansicht muss ein Dataset-Qualifizierer verwendet werden. Für Abfragen mit einem Dataset-Qualifier benötigen Sie Berechtigungen für das Dataset. Weitere Informationen finden Sie unter Syntax.
In der folgenden Tabelle werden die Regions- und Ressourcenbereiche für diese Ansicht gezeigt:
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 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```"]]