La vista INFORMATION_SCHEMA.TABLE_CONSTRAINTS tiene el siguiente esquema:
Nombre de la columna
Tipo
Significado
CONSTRAINT_CATALOG
STRING
El nombre del proyecto de la restricción.
CONSTRAINT_SCHEMA
STRING
El nombre del conjunto de datos de la restricción.
CONSTRAINT_NAME
STRING
El nombre de la restricción.
TABLE_CATALOG
STRING
El nombre del proyecto de la tabla restringida.
TABLE_SCHEMA
STRING
El nombre del conjunto de datos de la tabla restringida.
TABLE_NAME
STRING
El nombre de la tabla restringida.
CONSTRAINT_TYPE
STRING
PRIMARY KEY o FOREIGN KEY
IS_DEFERRABLE
STRING
YES o NO, lo cual depende de si una restricción es diferible. Solo se admite NO.
INITIALLY_DEFERRED
STRING
Solo se admite NO.
ENFORCED
STRING
YES o NO, según si se aplica la restricción. Solo se admite NO.
Permiso y sintaxis
Las consultas realizadas a esta vista deben tener un calificador de conjunto de datos. Para consultas con un calificador de conjunto de datos, debes tener permisos para el conjunto de datos. Para obtener más información, consulta Sintaxis.
En la siguiente tabla, se explican los permisos de la región y los recursos para esta vista:
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 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```"]]