How to Use Google Spreadsheets as a Database

Lana Rafaela Cindric Lana Rafaela Cindric
Written by Lana Rafaela Cindric
10 minutes read

You’ve probably used spreadsheet applications like Microsoft Excel and Google Sheets for all sorts of tasks. But did you know that you can actually use Google Sheets as a database too? 

Even though it wasn’t built specifically for that purpose, clever folks have figured out how to make it work. So, if you’re curious about whether Google Sheets could be your secret weapon as a database, stick around. 

Let’s dive into why and how you can turn those humble spreadsheets into a powerful database.

Benefits of Using a Google Spreadsheet as a Database

Before we get into the how, let’s go over the why of using Google Sheets as a database. Believe it or not, there are quite a few advantages that make it a tempting choice, including:

  • Cloud-Based: No more worries about losing your files or accidentally deleting important data. With Google Sheets being a web application, your database is always accessible online, ready to serve you wherever you go.
  • More Control: Google Sheets comes with a nifty access control system, meaning you can easily manage who can view and edit your data. With just a few clicks, you can grant permissions to collaborators or even revoke access if needed. 
  • Budget-Friendly: As a part of the Google suite of products, Google Sheets is absolutely free for unlimited usage. That’s right, no licensing fees or subscriptions are required! Compared to software like Microsoft Excel that can add to your application costs, Google Sheets keeps your wallet happy.
  • Easy Learning Curve: If you’ve ever worked with a spreadsheet application before (and chances are you have), diving into Google Sheets as a database won’t feel like an epic saga. The learning curve is pretty smooth, my friend. You’ll quickly get the hang of it and start unleashing its powerful capabilities to manage your data like a pro.
  • Visualize Like a Boss: Need to make your data pop? Google Sheets has got your back with a plethora of built-in features that let you jazz up the appearance and structure of your data. From cool charts to colorful formatting options, you can quickly transform those rows and columns into something easier on the eyes and simpler to analyze.

Example of Using Google Spreadsheet as a Database

Imagine you’re running a small online business selling handmade candles. You need a simple and efficient way to keep track of your inventory, customer orders, and sales data.

Instead of investing in a complex database management system, you decide to harness the power of Google Sheets as your database solution.

Here’s how you can make it happen:

1) Inventory Management

Start by creating a new Google Sheet and make it your inventory HQ. Add columns for stuff like candle names, quantities, prices, and any other deets that matter to you. Each row represents a unique candle masterpiece.

Now, fill in your inventory data, and you can even use color coding to show low stock or upcoming restocking dates.

2) Order Management Awesomeness

Now, it’s time to handle customer orders. Set up another sheet and call it “Customer Orders Central.” Create columns for things like customer names, contact info, order dates, candle types, quantities, and total prices.

As orders come flying in, just add new rows to this sheet and fill in the details.

And here’s the cool part: you can use formulas to automatically calculate the total price based on the quantity and unit price from your inventory sheet.

3) Sales Tracking Fun

So how do you keep up with sales? Now, create a separate sheet; let’s call it the “Sales Tracker.” Include columns like order IDs, customer names, order dates, total sales amounts, and any other nifty metrics you wanna track.

Use formulas to sum up those sales amounts and get an overview of your revenue over time. It’s like having your own mini sales dashboard right at your fingertips.

That’s just a quick example of how turning your spreadsheets into a database can help accelerate the growth of your business.

Now let’s take a look at some different ways you can do it yourself!

Enable Google Sheets as Database API

The first step will be enabling the Google Sheets API feature, so let’s dive right in:

  • Open up the Google Cloud Console and click on the “Select a project” option.
  • Next, click on “New Project” to create a new project under the search bar.
  • Give your project a name, select a location, and hit the “Create” button to bring it to life.
  • In the search bar, type in “Google Sheets API” and click on the one from the marketplace.
  • Now, click on “Enable” to activate the Google Sheets API for your project. Once it’s enabled, you’ll receive a confirmation message letting you know that you’re good to go.

By enabling the Google Sheets API, you’re unlocking a world of possibilities for using Google Sheets as a powerful database API.

Create a Service Account

Now that you’ve got the Google Sheets API up and running, let’s move on to creating a service account. This will allow you to connect to the API automatically and access its awesome features. Here’s how you can do it:

  • In the left-hand menu of the Google Cloud Console, navigate to the “Credentials” section.
  • Click on “Create Credentials” to begin the process.
  • Select “Service Account” as the credential type.
  • Give your service account a name and hit the “Create and Continue” button.
  • It’s time to choose a role for your service account. Click on “Select a role” and opt for the “Project > Editor” role to grant it the necessary permissions.
  • If you want to provide access to other users or groups, you can do that too. Just add them in the appropriate section. Once you’re done, click “Done” to wrap things up.

Congratulations! You’ve successfully created a service account. But wait, we’re not done yet. Next, we’ll need a service key so we can connect everything together.

Create a Service Key

To establish a smooth connection to the Google Sheets API, create a service key. This key will be instrumental in enabling automatic access. Here’s how you can make it happen:

  • In the “Credentials” section of the Google Cloud Console, find and click on your newly created service account name.
  • Navigate to the “Keys” tab and click on “Add Key” followed by “Create new key.”
  • Select the “JSON” option for your key type and hit the “Create” button.
  • Voila! You now have a service key in the form of a JSON file. This key is like the secret handshake that will allow your application to connect with the Google Sheets API effortlessly.

With the Google Sheets API enabled, a service account created, and a service key in hand, you’re all set to use Google Sheets as a database API. 

Use Google Sheets as a Database for Web Applications

Imagine you’re an aspiring musician with a passion for sharing your original compositions with the world. You’ve got a killer website where you showcase your latest tracks, but wouldn’t it be awesome if you could manage all your songs and their details in a spreadsheet and have your website automatically update with the latest additions? 

Well, with Google Sheets as your database and a little JavaScript magic, you can make it happen!

Here’s how it works:

1) Setting Up Your Google Sheets Database

First things first, create a Google Sheet with columns for song titles, release dates, album names, and any other relevant information you want to display on your website. Each row in the sheet represents a unique song entry.

Populate your sheet with your existing tracks and their details, and keep it handy for future updates.

2) Writing the JavaScript Code

To integrate your Google Sheets database with your website, you’ll need to write a custom JavaScript snippet. Here’s an example of how you can extract and display the song information from your Google Sheet:

// Include the Google Sheets API JavaScript library
<script src="https://apis.google.com/js/api.js"></script>

// Define the Google Sheets API key
const apiKey = "YOUR_API_KEY";

// Load the client library
gapi.load("client", init);

// Initialize the client library
function init() {
  gapi.client.init({
    apiKey: apiKey,
    discoveryDocs: ["https://sheets.googleapis.com/$discovery/rest?version=v4"],
  }).then(() => {
    // Call the Google Sheets API to fetch the data
    gapi.client.sheets.spreadsheets.values.get({
      spreadsheetId: "YOUR_SPREADSHEET_ID",
      range: "Sheet1!A2:D", // Adjust the range based on your sheet's structure
    }).then((response) => {
      const data = response.result.values;

      // Display the song information on your website
      data.forEach((row) => {
        const songTitle = row[0];
        const releaseDate = row[1];
        const albumName = row[2];
       
        // Use the retrieved data to dynamically generate HTML elements
        // and display details on your website
        // ...
      });
    });
  });
}

Make sure to replace YOUR_API_KEY with your actual Google Sheets API key and YOUR_SPREADSHEET_ID with the ID of your Google Sheet.

3) Integrating the JavaScript Code

To integrate this JavaScript code into your website, you can include it within a <script> tag on your web page. Customize the code as needed to match your website’s design and functionality.

Once implemented, your website will dynamically fetch information from your Google Sheets database and display it on the page. You can easily adapt this Javascript code to work for your website.

How Do I Create a Relational Database in Google Sheets?

While Google Sheets is a powerful spreadsheet application, it’s important to note that it doesn’t function as a traditional relational database. 

For more advanced relational database features, you may want to explore tools like Airtable. However, if you want to simulate some relational functionality in Google Sheets, here’s a simple approach:

Create a Table

Start by creating separate tables for each entity you want to store data about. For instance, if you’re managing project information, create a table with columns for the project name, start date, end date, and assigned team members. Each table represents a different entity in your database.

You can use the built-in =LINK function in Google Sheets to establish relationships between tables. 

Let’s say you want to link the project table to the clients table. You can use the following function:

=LINK("projects", "clients")

This function links the project_id column in the projects table to the project_id column in the clients table.

Query the Data

Once the tables are linked, you can utilize functions like =FILTER or =QUERY to query the data in your linked tables.

The =FILTER function allows you to filter the data based on specific criteria. For example, if you want to find all projects assigned to a client with the ID of 1, you can use the following:

=FILTER("projects", "client_id", 1)

This function will return all rows from the projects table where the client_id column is equal to 1.

The =QUERY function in Google Sheets enables you to write SQL-like queries to retrieve specific data from your linked tables. For instance, if you want to find all clients based in New York, you can use a query like this:

=QUERY("SELECT * WHERE city='New York'", "clients")

This query will return all rows from the clients table where the city column is equal to New York.

While these functions provide some simulation of relational database functionality in Google Sheets, it’s important to remember their limitations. 

Google Sheets is not specifically designed as a dedicated relational database management system. If you need more complex relational database needs, we suggest looking for more specialized tools.

Turn Your Google Sheets into a Powerful Database Today!

Say goodbye to manual data entry and hello to the world of Sheet Best! It’s time to turn your Google Sheets into a powerful database that works wonders for you.

With Sheet Best, you can supercharge your spreadsheets by transforming them into REST APIs. Imagine seamlessly integrating your data into your web or mobile applications without any hassle.

Learn more: Our customers’ favorite ways to use Sheet Best.

No more manual copying and pasting. No more tedious updates. Sheet Best automates the process, allowing you to focus on what matters most: your projects, your business, and your success.

So, why wait? Unlock the full potential of your data with Sheet Best!

Lana Rafaela Cindric

Lana Rafaela Cindric

Marketing manager

Leading marketing efforts for Sheet Best and helping our builder community understand and get the most out of the service