
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Create BigQuery dataset and tables
/ 20
DML statements (INSERT, UPDATE, DELETE)
/ 20
SQL SELECT statements
/ 10
DDL statements
/ 10
UDFs and stored procedures
/ 20
BigQuery supports many types of SQL statements including data definition language (DDL), data manipulation language (DML), user-defined functions (UDFs), and stored procedures.
The objective of this lab is to provide Oracle professionals with the necessary knowledge and skills to begin working with SQL in BigQuery. Upon completion of this lab, Oracle professionals will have a deeper understanding of how to use SQL in BigQuery to create, update, and work with data structures in BigQuery.
In this lab, you create tables and views using DDL statements, update tables using DML statements, join data using SQL, and define custom user-defined functions (UDFs) and stored procedures.
In this lab, you learn how to:
SQL SELECT
statements.For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.
Sign in to Qwiklabs using an incognito window.
Note the lab's access time (for example, 1:15:00
), and make sure you can finish within that time.
There is no pause feature. You can restart if needed, but you have to start at the beginning.
When ready, click Start lab.
Note your lab credentials (Username and Password). You will use them to sign in to the Google Cloud Console.
Click Open Google Console.
Click Use another account and copy/paste credentials for this lab into the prompts.
If you use other credentials, you'll receive errors or incur charges.
Accept the terms and skip the recovery resource page.
Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is a panel populated with the temporary credentials that you must use for this lab.
Copy the username, and then click Open Google Console. The lab spins up resources, and then opens another tab that shows the Choose an account page.
On the Choose an account page, click Use Another Account. The Sign in page opens.
Paste the username that you copied from the Connection Details panel. Then copy and paste the password.
After a few moments, the Cloud console opens in this tab.
In BigQuery, you can use data definition language (DDL) to create datasets and tables. You can also use the SQL statement LOAD DATA to load data from one or more files into a new or existing table.
To learn more about using DDL statements to create BigQuery datasets and tables and using the LOAD DATA SQL statement to load data, review the documentation titled CREATE SCHEMA statement, CREATE TABLE statement, and LOAD DATA statement.
In this task, you use DDL to create a dataset and tables in BigQuery, and then load data into the new tables using the LOAD DATA statement.
The Welcome to BigQuery in the Cloud Console message box opens. This message box provides a link to the quickstart guide and the release notes.
Click Done.
This query creates a new BigQuery dataset named animals_dataset. Note that the DDL statement uses the term SCHEMA to refer to a logical collection of tables, views, and other resources, which in BigQuery is known as a dataset.
These queries create two tables called owners and pets in the BigQuery dataset you previously created named animals_dataset.
Before moving to the next step, update the field mode from REQUIRED to NULLABLE in the table schema to avoid errors in step 5.
In the Explorer panel, select the table name, choose SCHEMA tab, click EDIT SCHEMA, then update the field mode from REQUIRED to NULLABLE and click Save. Please repeat this step for all the fields with mode "REQUIRED" in both tables.
These queries load data into the owners and pets tables from CSV files in Cloud Storage.
The Results pane displays a message that the LOAD statement ran successfully.
Expand the Explorer pane (left side panel) which lists the dataset and table, and then click on the table name owners.
Click on the Details and Preview tabs to see more information about the table and a preview of the data.
You can click Refresh (top right) to refresh the data in the Preview tab.
Click Check my progress to verify the objective.
In BigQuery, you can use DML to update the data in an existing table, including adding, modifying, and deleting data from your BigQuery tables.
To learn more about using DML statements to work with data in BigQuery tables, review the documentation titled Data manipulation language (DML) statements in GoogleSQL.
In this task, you use DML to insert, update, and delete data from an existing BigQuery table.
After each insert query, the Results pane displays that one record has been added to the pets table.
The record for Mary in the owners table has been joined to the two records in the pets table for her dogs: George and Washington.
This statement modifies 10 rows in the pets table.
Verify that all the dogs are now identified as canines in the pets table.
You can click Refresh (top right) to refresh the data in the Preview tab.
This statement removes 1 row from the pets table.
Verify that all frogs have been removed from the pets table.
You can click Refresh (top right) to refresh the data in the Preview tab.
Click Check my progress to verify the objective.
In BigQuery, you can write SQL SELECT
statements with syntax for joins, CTEs, ordering, grouping, filtering, pivoting, windowing, and more, to retrieve the data that you need.
To learn more about SQL SELECT
syntax for working with data in BigQuery tables, review the documentation titled Query syntax.
In this task, you write SQL SELECT
statements that include JOIN
operations to join multiple tables and WITH
clauses to define CTEs.
JOIN
to select all owners and their pets:WHERE
clause to only select the canines:ORDER BY
to sort the results by the owner's name.There are 10 canines, 5 cats, 2 pigs, and 2 turtles in the pets table.
The owner named Doug has the most pets with 4 total pets.
ARRAY`s
of STRUCT`s
. The ARRAY_AGG(STRUCT…)
syntax provides the results as nested and repeated values and makes it easier to see the relationships between the data because joined values are organized clearly.
Another useful SQL option in BigQuery is to use a WITH
clause to define CTEs and query the results of another query. Using this syntax, you can avoid using nested SQL statements and make your code easier to read.
Click Check my progress to verify the objective.
In a previous task, you used DDL to create new BigQuery datasets and tables. In BigQuery, you can also use DDL to create both logical views and materialized views.
To learn more about using DDL statements to create views in BigQuery, review the documentation titled Introduction to views.
In this task, you use DDL to create new tables, logical views, and materialized views.
Expand the Explorer pane (left side panel) which lists the dataset and table, and then click on the table name owner_pets.
Click on the Schema tab to review the schema of the newly created table named owners_pets.
The schema includes a nested and repeated field named Pets, which contains the pet ID, name, type, and weight of each pet for each owner.
In a previous task, you ran a query that joined the owners and pets tables to count the number of pets for each owner. Now that the data is contained in a nested and repeated field, you can use the ARRAY_LENGTH
function to return the number of pets for each owner.
Click Go to View.
In the Explorer pane, click View Actions (the icon with three vertical buttons) for the small_pets view, and select Query.
In the query editor, run the following query to examine the data in the view:
In BigQuery, materialized views are precomputed views that periodically cache the results of a query for increased performance and efficiency. Materialized views can be especially useful for queries that require complex processing such as aggregations.
Click Go to Materialized View.
In the Explorer pane, click View Actions (the icon with three vertical buttons) for the pet_weight_by_type materialized view, and select Query.
In the query editor, run the following query to examine the data in the materialized view:
The canines have the highest total weight at 314 pounds.
Click Check my progress to verify the objective.
In BigQuery, you can define a custom UDF for cases in which there is not a built-in function that already does what you need. A UDF accepts one or more columns of input, executes actions on the input, and returns the result of those actions as the output. In addition, you can also define stored procedures as functions that execute collections of SQL statements such as SELECT
, INSERT
, and more, in a desired order.
To learn more about defining UDFs and stored procedures in BigQuery, review the documentation titled User-defined functions and Work with SQL stored procedures.
In this task, you define UDFs and stored procedures to recalculate existing values in a table and to make it easier to add new data records to a table.
You can also create a stored procedure to make adding a new pet easier. The following procedure finds the largest pet ID in the pets table and adds a value of 1
to that ID. It then assigns that new value as the ID for the new Pet. When the new pet is added, the value of the new pet ID is returned.
SELECT *
.Notice that the output variable of the function is the newly created record for a dog named Duke with a pet ID equal to 30
.
SELECT *
.Notice that the ID field keeps incrementing in value; the new pet ID for a cat named Fluffy is 31
.
Click Check my progress to verify the objective.
When you have completed your lab, click End Lab. Google Cloud Skills Boost removes the resources you’ve used and cleans the account for you.
You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.
The number of stars indicates the following:
You can close the dialog box if you don't want to provide feedback.
For feedback, suggestions, or corrections, please use the Support tab.
Copyright 2022 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one