Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Visualização de CONSTRAINT_COLUMN_USAGE
A visualização CONSTRAINT_COLUMN_USAGE contém todas as colunas usadas por
restrições.
Para restrições PRIMARY KEY, estas são as colunas da
visualização KEY_COLUMN_USAGE. Para restrições FOREIGN KEY, estas são as colunas
das tabelas referenciadas.
Esquema
A visualização INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE tem o seguinte esquema:
Nome da coluna
Tipo de dados
Valor
TABLE_CATALOG
STRING
Nome do projeto que contém o conjunto de dados.
TABLE_SCHEMA
STRING
O nome do conjunto de dados que contém a tabela, também
conhecido como datasetId
TABLE_NAME
STRING
O nome da tabela, também conhecido como
tableId
COLUMN_NAME
STRING
O nome da coluna.
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. Pode ser o nome da
chave primária, se a coluna for usada pela chave primária, ou o nome da
chave externa, se a coluna for usada por uma chave externa.
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-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```"]]