Creating a database in Cloud Spanner instances

With the following steps, we can create a database in Cloud Spanner from the GCP console itself:

  1. Click the Create Database button.
  2. We will create a database called holder_details and add its schema. Like previous examples, here too we have customer ID, name, account, and balance columns. We have also defined their datatypes. As you may have already noticed, all of this is happening without creating any instance.
  1. Once you have defined all of your columns, click on the Create Table button and it will lead you to the screen where you can verify your table and start adding data. There is another way of editing the schema as text where you need to set up your schema in Data Definition Language, which is pretty similar to MySQL, but is not mySQL (one of the downsides of making things proprietary you know!). You can check out the documentation for it:
  1. Notice that the customer_id as the primary key for this table is indicated by a little key icon in that particular row. We can add data in this table from the Data tab. Here you will find fields for all the columns and due to obvious reasons, the primary key column field cannot be left empty in any entry. In a similar way, we can enter all the data we want.
  1. Another variation that you can bring to your table is to customize its key to avoid hotspotting. In this small table hotspotting should not be an issue, but for larger databases, as we discussed earlier, consecutive keys can create larger splits that create hotspotting. To avoid this, we can have a primary key and a secondary key and change their datatypes to strings.

We have created the format of the composite keys, let's take a look at the outcome.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset