La vista INFORMATION_SCHEMA.TABLE_CONSTRAINTS ha lo schema seguente:
Nome colonna
Tipo
Significato
CONSTRAINT_CATALOG
STRING
Il nome del progetto vincolo.
CONSTRAINT_SCHEMA
STRING
Il nome del set di dati dei vincoli.
CONSTRAINT_NAME
STRING
Il nome del vincolo.
TABLE_CATALOG
STRING
Il nome del progetto della tabella vincolata.
TABLE_SCHEMA
STRING
Il nome del set di dati della tabella vincolata.
TABLE_NAME
STRING
Il nome della tabella vincolata.
CONSTRAINT_TYPE
STRING
PRIMARY KEY o
FOREIGN KEY.
IS_DEFERRABLE
STRING
YES o NO a seconda che un vincolo sia posticipabile. È supportato solo NO.
INITIALLY_DEFERRED
STRING
È supportato solo NO.
ENFORCED
STRING
YES o NO a seconda che il vincolo sia applicato.
È supportato solo NO.
Ambito e sintassi
Le query su questa vista devono includere un qualificatore del set di dati. Per le query con un qualificatore del set di dati, devi disporre delle autorizzazioni per il set di dati. Per ulteriori informazioni, consulta la sezione Sintassi.
La tabella seguente mostra gli ambiti della regione e delle risorse per questa visualizzazione:
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 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```"]]