TheINFORMATION_SCHEMA.TABLE_CONSTRAINTSview has the following schema:
Column Name
Type
Meaning
CONSTRAINT_CATALOG
STRING
The constraint project name.
CONSTRAINT_SCHEMA
STRING
The constraint dataset name.
CONSTRAINT_NAME
STRING
The constraint name.
TABLE_CATALOG
STRING
The constrained table project name.
TABLE_SCHEMA
STRING
The constrained table dataset name.
TABLE_NAME
STRING
The constrained table name.
CONSTRAINT_TYPE
STRING
EitherPRIMARY KEYorFOREIGN KEY.
IS_DEFERRABLE
STRING
YESorNOdepending on if a constraint is
deferrable. OnlyNOis supported.
INITIALLY_DEFERRED
STRING
OnlyNOis supported.
ENFORCED
STRING
YESorNOdepending on if the constraint is
enforced. OnlyNOis supported.
Scope and syntax
Queries against this view must include a dataset qualifier. For queries with a
dataset qualifier, you must have permissions for the dataset. For more
information seeSyntax.
The following table shows the region and resource scopes for this view:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 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```"]]