Load and query data

Get started with BigQuery by creating a dataset, loading data into atable, and querying the table.


To follow step-by-step guidance for this task directly in the Google Cloud console, clickGuide me:

Guide me


Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.create permission.Learn how to grant roles.
    Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.

    Go to project selector

  3. If you're using an existing project for this guide,verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

  4. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.create permission.Learn how to grant roles.
    Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.

    Go to project selector

  5. If you're using an existing project for this guide,verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

  6. Enable the BigQuery API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enable permission.Learn how to grant roles.

    Enable the API

    For new projects, the BigQuery API is automatically enabled.

  7. Optional:Enable billing for the project. If you don't want to enable billing or provide a credit card, the steps in this document still work. BigQuery provides you a sandbox to perform the steps. For more information, seeEnable the BigQuery sandbox.Note: If your project has a billing account and you want to use the BigQuery sandbox, thendisable billing for your project.

Required roles

To get the permissions that you need to create a dataset, create a table, load data, and query data, ask your administrator to grant you the following IAM roles on the project:

  • Run load jobs and query jobs:BigQuery Job User (roles/bigquery.jobUser)
  • Create a dataset, create a table, load data into a table, and query a table:BigQuery Data Editor (roles/bigquery.dataEditor)

For more information about granting roles, seeManage access to projects, folders, and organizations.

You might also be able to get the required permissions throughcustom roles or otherpredefined roles.

Create a BigQuery dataset

Use the Google Cloud console to create a dataset to store the data. Youcreate your dataset in the US multi-region location. For information onBigQuery regions and multi-regions, seeLocations.

  1. In the Google Cloud console, open the BigQuery page.
  2. Go to BigQuery
  3. In the left pane, clickExplorer.
  4. In theExplorer pane, click your project name.
  5. ClickView actions.
  6. SelectCreate dataset.
  7. On theCreate dataset page, do the following:
    1. ForDataset ID, enterbabynames.
    2. ForLocation type, selectMulti-region, and then chooseUS (multiple regions in United States). The public datasets are stored in theus multi-region location. For simplicity, store your dataset in the same location.
    3. Leave the remaining default settings as they are, and clickCreate dataset.

Download the file that contains the source data

The file that you're downloading contains approximately 7 MB of data aboutpopular baby names. It's provided by the US Social Security Administration.

For more information about the data, see the Social Security Administration'sBackground information for popular names.

  1. Download the US Social Security Administration's data by opening thefollowing URL in a new browser tab:

    https://www.ssa.gov/OACT/babynames/names.zip
  2. Extract the file.

    For more information about the dataset schema, see the zip file'sNationalReadMe.pdf file.

  3. To see what the data looks like, open theyob2024.txt file. This filecontains comma-separated values for name, assigned sex at birth, and numberof children with that name. The file has no header row.

  4. Note the location of theyob2024.txt file so that you can find it later.

Load data into a table

Next, load the data into a new table.

  1. In the left pane, clickExplorer.
  2. In theExplorer pane, expand your project name.
  3. ClickDatasets and then next to thebabynames dataset, clickView actions and selectOpen.
  4. ClickCreate table.

    Unless otherwise indicated, use the default values for all settings.

  5. On theCreate table page, do the following:
    1. In theSource section, forCreate table from, chooseUpload from the list.
    2. In theSelect file field, clickBrowse.
    3. Navigate to and open your localyob2024.txt file, and clickOpen.
    4. From theFile format list, chooseCSV.
    5. In theDestination section, in theTable field, enternames_2024.
    6. In theSchema section, click theEdit as text toggle, and paste the following schema definition into the text field:
    7. name:string,assigned_sex_at_birth:string,count:integer
    8. ClickCreate table.

      Wait for BigQuery to create the table and load the data.

Preview table data

To preview the table data, follow these steps:

  1. In the left pane, clickExplorer.
  2. In theExplorer pane, expand your project and clickDatasets.
  3. Click thebabynames dataset, and then select thenames_2024 table.
  4. Click thePreview tab. BigQuery displays the first few rows of the table.
  5. The table preview tab.
ThePreview tab is not available for all table types. For example, thePreview tab is not displayed for external tables or views.

Query table data

Next, query the table.

  1. Next to thenames_2024 tab, click theSQL query option. A new editor tab opens.
  2. In the query editor, paste the following query. This query retrieves the top five names for babies born in the US that were assigned male at birth in 2024.
    SELECTname,countFROM`babynames.names_2024`WHEREassigned_sex_at_birth='M'ORDERBYcountDESCLIMIT5;
  3. ClickRun. The results are displayed in theQuery results section.
    The query results panel

You have successfully queried a table in a public dataset and then loaded yoursample data into BigQuery using the Google Cloud console.

Clean up

To avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.

  1. In the Google Cloud console, open the BigQuery page.
  2. Go to BigQuery
  3. In the left pane, clickExplorer.
  4. In theExplorer pane, clickDatasets and then click thebabynames dataset that you created.
  5. Expand theView actions option and clickDelete.
  6. In theDelete dataset dialog, confirm the delete command: type the worddelete and then clickDelete.

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.