Manage tables

This document describes how to manage tables in BigQuery. You can manage your BigQuery tables in the following ways:

For more information about creating and using tables including getting table information, listing tables, and controlling access to table data, see Creating and using tables .

Before you begin

Grant Identity and Access Management (IAM) roles that give users the necessary permissions to perform each task in this document. The permissions required to perform a task (if any) are listed in the "Required permissions" section of the task.

Update table properties

You can update the following elements of a table:

Required permissions

To get the permissions that you need to update table properties, ask your administrator to grant you the Data Editor ( roles/bigquery.dataEditor ) IAM role on a table. For more information about granting roles, see Manage access to projects, folders, and organizations .

This predefined role contains the permissions required to update table properties. To see the exact permissions that are required, expand the Required permissionssection:

Required permissions

The following permissions are required to update table properties:

  • bigquery.tables.update
  • bigquery.tables.get

You might also be able to get these permissions with custom roles or other predefined roles .

Additionally, if you have the bigquery.datasets.create permission, you can update the properties of the tables of the datasets that you create.

Update a table's description

You can update a table's description in the following ways:

  • Using the Google Cloud console.
  • Using a data definition language (DDL) ALTER TABLE statement.
  • Using the bq command-line tool's bq update command.
  • Calling the tables.patch API method.
  • Using the client libraries.

To update a table's description:

Console

You can't add a description when you create a table using the Google Cloud console. After the table is created, you can add a description on the Detailspage.

  1. In the Explorerpanel, expand your project and dataset, then select the table.

  2. In the details panel, click Details.

  3. In the Descriptionsection, click the pencil icon to edit the description.

    Edit description.

  4. Enter a description in the box, and click Updateto save.

SQL

Use the ALTER TABLE SET OPTIONS statement . The following example updates the description of a table named mytable :

  1. In the Google Cloud console, go to the BigQuerypage.

    Go to BigQuery

  2. In the query editor, enter the following statement:

     ALTER 
      
     TABLE 
      
     mydataset 
     . 
     mytable 
      
     SET 
      
     OPTIONS 
      
     ( 
      
     description 
      
     = 
      
    ' Description 
      
     of 
      
     mytable 
    ' ); 
    
  3. Click Run.

For more information about how to run queries, see Run an interactive query .

bq

  1. In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

    At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.

  2. Issue the bq update command with the --description flag. If you are updating a table in a project other than your default project, add the project ID to the dataset name in the following format: project_id : dataset .

    bq  
    update  
     \ 
    --description  
     " description 
    " 
      
     \ 
     project_id 
    : dataset 
    . table 
    

    Replace the following:

    • description : the text describing the table in quotes
    • project_id : your project ID
    • dataset : the name of the dataset that contains the table you're updating
    • table : the name of the table you're updating

    Examples:

    To change the description of the mytable table in the mydataset dataset to "Description of mytable", enter the following command. The mydataset dataset is in your default project.

    bq update --description "Description of mytable" mydataset.mytable

    To change the description of the mytable table in the mydataset dataset to "Description of mytable", enter the following command. The mydataset dataset is in the myotherproject project, not your default project.

    bq update \
    --description "Description of mytable" \
    myotherproject:mydataset.mytable

API

Call the tables.patch method and use the description property in the table resource to update the table's description. Because the tables.update method replaces the entire table resource, the tables.patch method is preferred.

Go

Before trying this sample, follow the Go setup instructions in the BigQuery quickstart using client libraries . For more information, see the BigQuery Go API reference documentation .

To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries .

  import 
  
 ( 
  
" context 
"  
" fmt 
"  
" cloud 
 . 
 google 
 . 
 com 
 / 
 go 
 / 
 bigquery 
" ) 
 // updateTableDescription demonstrates how to fetch a table's metadata and updates the Description metadata. 
 func 
  
 updateTableDescription 
 ( 
 projectID 
 , 
  
 datasetID 
 , 
  
 tableID 
  
 string 
 ) 
  
 error 
  
 { 
  
 // projectID := "my-project-id 
"  
 // datasetID := "mydataset 
"  
 // tableID := "mytable 
"  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 client 
 , 
  
 err 
  
 := 
  
 bigquery 
 . 
 NewClient 
 ( 
 ctx 
 , 
  
 projectID 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 return 
  
 fmt 
 . 
 Errorf 
 ( 
" bigquery 
 . 
 NewClient 
 : 
  
 % 
 v 
" , 
  
 err 
 ) 
  
 } 
  
 defer 
  
 client 
 . 
 Close 
 () 
  
 tableRef 
  
 := 
  
 client 
 . 
 Dataset 
 ( 
 datasetID 
 ). 
 Table 
 ( 
 tableID 
 ) 
  
 meta 
 , 
  
 err 
  
 := 
  
 tableRef 
 . 
 Metadata 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 return 
  
 err 
  
 } 
  
 update 
  
 := 
  
 bigquery 
 . 
 TableMetadataToUpdate 
 { 
  
 Description 
 : 
  
" Updated 
  
 description 
 .", 
  
 } 
  
 if 
  
 _ 
 , 
  
 err 
  
 = 
  
 tableRef 
 . 
 Update 
 ( 
 ctx 
 , 
  
 update 
 , 
  
 meta 
 . 
 ETag 
 ); 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 return 
  
 err 
  
 } 
  
 return 
  
 nil 
 }