Die Ansicht INFORMATION_SCHEMA.TABLE_CONSTRAINTS hat das folgende Schema:
Spaltenname
Typ
Bedeutung
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.
TABLE_CATALOG
STRING
Der Name des eingeschränkten Tabellenprojekts.
TABLE_SCHEMA
STRING
Der Name des eingeschränkten Tabellen-Datasets.
TABLE_NAME
STRING
Der Name der eingeschränkten Tabelle.
CONSTRAINT_TYPE
STRING
PRIMARY KEY oder FOREIGN KEY.
IS_DEFERRABLE
STRING
YES oder NO, je nachdem, ob eine Einschränkung zurückgestellt werden kann. Nur NO wird unterstützt.
INITIALLY_DEFERRED
STRING
Nur NO wird unterstützt.
ENFORCED
STRING
YES oder NO, je nachdem, ob die Einschränkung erzwungen wird. Nur NO wird unterstützt.
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-09-04 (UTC)."],[[["\u003cp\u003eThe \u003ccode\u003eTABLE_CONSTRAINTS\u003c/code\u003e view in BigQuery provides information about primary and foreign key relationships within a dataset.\u003c/p\u003e\n"],["\u003cp\u003eTo access this view and its data, users need specific IAM permissions, namely \u003ccode\u003ebigquery.tables.get\u003c/code\u003e and \u003ccode\u003ebigquery.tables.list\u003c/code\u003e, or one of the predefined roles like \u003ccode\u003eroles/bigquery.dataEditor\u003c/code\u003e, \u003ccode\u003eroles/bigquery.dataOwner\u003c/code\u003e, or \u003ccode\u003eroles/bigquery.admin\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe schema of the \u003ccode\u003eTABLE_CONSTRAINTS\u003c/code\u003e view includes columns such as \u003ccode\u003eCONSTRAINT_NAME\u003c/code\u003e, \u003ccode\u003eTABLE_NAME\u003c/code\u003e, and \u003ccode\u003eCONSTRAINT_TYPE\u003c/code\u003e, which detail constraint names, constrained tables, and whether the constraint is a \u003ccode\u003ePRIMARY KEY\u003c/code\u003e or \u003ccode\u003eFOREIGN KEY\u003c/code\u003e, respectively.\u003c/p\u003e\n"],["\u003cp\u003eQueries against \u003ccode\u003eTABLE_CONSTRAINTS\u003c/code\u003e must specify a dataset, and the user must have the appropriate permissions for that dataset, and the view's scope can be either dataset-level or at the dataset location.\u003c/p\u003e\n"],["\u003cp\u003eConstraints can be seen by querying the \u003ccode\u003eTABLE_CONSTRAINTS\u003c/code\u003e view by specifying a table to search for or by querying the entire dataset for all tables that contain constraints.\u003c/p\u003e\n"]]],[],null,["# TABLE_CONSTRAINTS view\n======================\n\nThe `TABLE_CONSTRAINTS` view contains [the primary and foreign key](/bigquery/docs/primary-foreign-keys)\nrelations in a BigQuery dataset.\n\nRequired permissions\n--------------------\n\nYou need the following\n[Identity and Access Management (IAM) permissions](/iam/docs/overview):\n\n- `bigquery.tables.get` for viewing primary and foreign key definitions.\n- `bigquery.tables.list` for viewing table information schemas.\n\nEach of the following\n[predefined roles](/iam/docs/understanding-roles#predefined)\nhas the needed permissions to perform the workflows detailed in this document:\n\n- `roles/bigquery.dataEditor`\n- `roles/bigquery.dataOwner`\n- `roles/bigquery.admin`\n\n| **Note:** Roles are presented in ascending order of permissions granted. We recommend that you use predefined roles from earlier in the list to not allocate excess permissions.\n\nFor more information about IAM roles and permissions in\nBigQuery, see\n[Predefined roles and permissions](/bigquery/docs/access-control).\n\nSchema\n------\n\nThe `INFORMATION_SCHEMA.TABLE_CONSTRAINTS` 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.TABLE_CONSTRAINTS\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\nsingle dataset. \n\n```googlesql\nSELECT *\nFROM PROJECT_ID.DATASET.INFORMATION_SCHEMA.TABLE_CONSTRAINTS;\n```\n\nWith existing constraints, the query results are similar to the following: \n\n```\n+-----+---------------------+-------------------+-----------------------+---------------------+--------------+------------+-----------------+---------------+--------------------+----------+\n| Row | constraint_catalog | constraint_schema | constraint_name | table_catalog | table_schema | table_name | constraint_type | is_deferrable | initially_deferred | enforced |\n+-----+---------------------+-------------------+-----------------------+---------------------+--------------+------------+-----------------+---------------+--------------------+----------+\n| 1 | myConstraintCatalog | myDataset | orders.pk$ | myConstraintCatalog | myDataset | orders | PRIMARY KEY | NO | NO | NO |\n| 2 | myConstraintCatalog | myDataset | orders.order_customer | myConstraintCatalog | myDataset | orders | FOREIGN KEY | NO | NO | NO |\n+-----+---------------------+-------------------+-----------------------+---------------------+--------------+------------+-----------------+---------------+--------------------+----------+\n```\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```"]]