A visualização INFORMATION_SCHEMA.TABLE_CONSTRAINTS tem o seguinte esquema:
Nome da coluna
Tipo
Significado
CONSTRAINT_CATALOG
STRING
O nome do projeto de restrição.
CONSTRAINT_SCHEMA
STRING
O nome do conjunto de dados de restrição.
CONSTRAINT_NAME
STRING
O nome da restrição.
TABLE_CATALOG
STRING
O nome do projeto na tabela restrita.
TABLE_SCHEMA
STRING
O nome do conjunto de dados da tabela restrita.
TABLE_NAME
STRING
O nome da tabela restrita.
CONSTRAINT_TYPE
STRING
PRIMARY KEY ou
FOREIGN KEY.
IS_DEFERRABLE
STRING
YES ou NO, dependendo de uma restrição ser
adiada. Somente NO é aceito.
INITIALLY_DEFERRED
STRING
Somente NO é aceito.
ENFORCED
STRING
YES ou NO, dependendo da aplicação da
restrição.
Somente NO é aceito.
Escopo e sintaxe
As consultas nesta visualização precisam ter um qualificador de conjunto de dados. Para consultas com um
qualificador de conjunto de dados, é preciso ter permissões para o conjunto de dados. Para mais
informações, consulte
Sintaxe.
A tabela a seguir explica os escopos de região e recurso dessa visualização:
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 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```"]]