Summary IconKey Takeaways

You can connect Google Sheets to SQL Server using any of the two methods below:

Method 1: Using Hevo
Step 1: Set Google Sheets as your source in Hevo.
Step 2: Select SQL Server as your destination.

Method 2: Using Google Apps Script
Step 1: Whitelist Google IP ranges in your SQL Server settings.
Step 2: Set up your spreadsheet and open the Script Editor in Google Sheets.
Step 3: Write custom Apps Script code to create the database, tables, and user, and to load your data.
Step 4: Run the script to transfer data from Sheets to SQL Server.

Google Sheets and SQL Server can make a powerful data management combination. The cloud-based Sheets provide easy collaboration, while SQL Server offers robust relational database capabilities for storing and querying data.

Connecting your Google Sheets to a SQL Server database allows you to synchronize data between these platforms. This opens up possibilities like building collaborative business intelligence dashboards on top of your Sheets data from the SQL Server database.

This guide outlines two simple methods for establishing connectivity and syncing data between Google Sheets and SQL Server. By linking these cloud-based spreadsheets and on-premises databases together, you can enable convenient data access and updates for your organization.

    Simplify Google Sheets Migration with Hevo!

    Ditch the manual process of writing long commands to connect your Google Sheets account to the SQL server and choose Hevo’s no-code platform to streamline your data migration. 

    With Hevo:

    1. Easily migrate different data types like CSV, JSON, etc. 
    2. 150+ connectors like SQL Server and Google Sheets(including 60+ free sources).
    3. Eliminate the need for manual schema mapping with the auto-mapping feature.

    Experience Hevo and see why 2000+ data professionals, including customers such as Thoughtspot, Postman, etc., rated us 4.3/5 on G2.

    Get Started with Hevo for Free

    What are the ways to load Google Sheets data to SQL Server?

    Method 1: Using Hevo

    Step 1: Configure Google Sheets as Your Source

    • Click on ‘Create a Pipeline’
    • Select your Source and Destination
    • Add all the details required:
      • Account details
      • Pipeline name
    • Select all sheets you require to migrate.
    Google sheets Source Configuration

    Step 2: Configure SQL Server as Your Destination

    • Configure your PostgreSQLSource by providing the following details:
    • Select other required parameters (Ingestion Modes, SSH/SSL, and advanced settings options).
    SQL Server Destination Configuration

    After your Source and Destination are configured, you can connect them and start migrating data.

    With these two steps, you will be able to connect Google Sheets and SQL Server seamlessly.

    Load Data from Google Sheets to MS SQL Server
    Load Data from Google Ads to MS SQL Server
    Load Data from Salesforce to MS SQL Server

    Method 2: Using the Apps Script

    Google App Script provides a JDBC service to connect to SQL Server. Below is the step-by-step approach to loading Google Sheets data to SQL Server.

    Step 1: Whitelisting the IP 

    Google JDBC service requires you to whitelist specific IPs to create a database connection using the JDBC service. In your MS SQL database settings, add the following IPs to the whitelist.

    64.18.0.0 - 64.18.15.255
    64.233.160.0 - 64.233.191.255
    66.102.0.0 - 66.102.15.255
    66.249.80.0 - 66.249.95.255
    72.14.192.0 - 72.14.255.255
    74.125.0.0 - 74.125.255.255
    173.194.0.0 - 173.194.255.255
    207.126.144.0 - 207.126.159.255
    209.85.128.0 - 209.85.255.255
    216.239.32.0 - 216.239.63.255

    Step 2: Create a Google Sheet

    • Log in to your Google Account and from the Apps section, go to Google Drive.
    • Once you log in to Drive, from the option New, select Google Sheets.
    • A new Sheet will open in a New Tab.
    • Provide a name to the SpreadSheet and add some data.
    Google sheet data
    • Launch the Script Editor from Extension> App Script. This editor will be used to write the scripts connecting to SQL Server. 
    • This is what the default page will look like:
    Execute Script

    Step 3: Create a Database, Table, and User

    Once you have created the spreadsheet and populated it with some data, now you have to create the database, tables, and users in the SQL Server to access the data from Google Sheets.

    It is possible to create databases, users, and tables by using the SQL Server command line or from the workbench, and in this case, you will do the same with the Apps Script. Go to the Script editor and write the following lines of code:

      Step 3.1: Create Connection Variables

      Update the variable assignment with the actual values.

      var connectionName = 'Instance_connection_name';
      var rootPwd = 'root_password';
      var user = 'user_name';
      var userPwd = 'user_password';
      var db = 'database_name';
      
      var root = 'root';
      var instanceUrl = 'jdbc:google:mysql://' + connectionName;
      var dbUrl = instanceUrl + '/' + db;

      Step 3.2: Create a New Database

      Use the following command to create a new database.

      function createDb() {
        var con = Jdbc.getConnection(instanceUrl, root, rootPwd);
        con.createStatement().execute('CREATE DATABASE ' + db);
      }

      Step 3.3: Create a New User with the Necessary Privileges

      Create a new user in the database with the necessary privileges.

      function createUser() {
        var conn = Jdbc.getConnection(dbUrl, root, rootPwd);
      
        var stmt = conn.prepareStatement('CREATE USER ? IDENTIFIED BY ?');
        stmt.setString(1, user);
        stmt.setString(2, userPwd);
        stmt.execute();
      
        conn.createStatement().execute('GRANT ALL ON `%`.* TO ' + user);
      }

      Step 3.4: Create a New Table

      Use the following command to create a new table:

      function createTable() {
        var conn = Jdbc.getCloudSqlConnection(dbUrl, user, userPwd);
        conn.createStatement().execute('CREATE TABLE employee'
            + '(emp_id INT NOT NULL, emp_name VARCHAR(255), emp_dept VARCHAR(255); ');
      }

      Step 4: Writing to Database

      Use the following code to write in SQL Server using batch mode. 

        Step 4.1: Create a Connection Variable

        Update the variable assignment with actual values.

        var connectionName = 'Instance_connection_name';
        var user = 'user_name';
        var userPwd = 'user_password';
        var db = 'database_name';
        var dbUrl = 'jdbc:google:mysql://' + connectionName + '/' + db;

        Step 4.2: Write Data to SQL Server

        Write data to a table in a single batch.

        function writeManyRecords() {
          var conn = Jdbc.getConnection(dbUrl, user, userPwd);
          conn.setAutoCommit(false);
        
          var start = new Date();
         var sheet = SpreadsheetApp.getActiveSheet();
         var data = sheet.getDataRange().getValues();
        
         var stmt = conn.prepareStatement('INSERT INTO employee ' +  '(emp_id, emp_name, emp_dept) values (?, ?, ?)');
        
         for (var i = 0; i < data.length; i++) {
          stmt.setString('Emo Id: ' + data[i][0]);
          stmt.setString('Emp Name: ' + data[i][1]);
          stmt.setString('Emp Dept: ' + data[i][2]);
          stmt.addBatch();
        
        }
        
          var batch = stmt.executeBatch();
          conn.commit();
          conn.close();
        
          var end = new Date();
          Logger.log('Time elapsed: %s ms for %s rows.', end - start, batch.length);
        }

        Click on the “Run Script” to run the script. Check the SQL Server for the data.

        Limitations of using the Apps Script

        Migrating your Google Sheets data to the SQL server could have the following benefits:

        • A lot of coding is required to move the data from Google Sheets. This method is only feasible for technical users.
        • Google Sheets cannot store massive amounts of data, i.e, perform as a database.
        • Google Sheets with Apps Script has some time limits on script execution. This process is not reliable when you need to move vast volumes of data.
        • Extra coding is required if you want to transform the data before moving it to SQL Server.

        You can also learn how to connect Google Sheets to REST API.

        What are Google Sheets?

        Google Sheets Logo

        Google Sheets is a cloud-based spreadsheet application offering a flexible and user-friendly platform for data organization, analysis, and collaboration. Users can access it from any device connected to the Internet, enabling real-time processing and many other useful features.

        Key Features:

        • Integration and Automation: It offers a variety of add-ons to extend functionality, including third-party integrations.
        • Real-Time Collaboration: It allows many users to work on the same spreadsheet, and all changes are saved automatically. The changes show up in real-time.
        • Accessibility and Convenience: It is accessible through any web browser or the mobile Google Sheets app. It also supports offline editing and automatically synchronizes changes once back online.
        • Data Management and Analysis: It offers extensive support for functions and formulas used in calculations and data analysis, together with tools for creating various charts and graphs that make it easy for its users to analyze data.

        Overview of SQL Server

        SQL Server Logo

        SQL Server is a relational database management system (RDBMS) developed by Microsoft. It is designed to store, manage, and retrieve data in response to requests from other software applications. SQL Server is built on the SQL (Structured Query Language) standard, which is used to query and manage relational databases.

        Key Features of SQL Server:

        • Cloud Integration: Comparatively much easier to integrate with Azure services.
        • TSQL: Robust Transact-SQL in complex queries and stored procedures.
        • Scalability: Supports huge databases and multiple concurrent users.
        • High Availability: SQL Server high availability has features, including Always On and Failover clustering.
        • Security: Tight security through solid encryption, auditing, and row-level security.
        • Integration: Integrates very well with other Microsoft services and Third-Party Tools
        • Data Tools: In-depth tools for ETL, reporting, and data analysis

        Why do you need to migrate Google Sheets Data?

        Migrating your Google Sheets data to the SQL server could have the following benefits: 

        • Enhanced Data Management: Centralized storage, improved data integrity, and better scalability.
        • Improved Data Analysis: Powerful querying capabilities and seamless integration with BI tools like Microsoft Power BI.
        • Enhanced Collaboration & Security: Controlled access, version control, and improved security.
        • Automation & Integration: Efficient ETL/ELT processes and seamless integration with other systems.

        Discover how to use Google Sheets as a database with our guide on leveraging its data management and analysis capabilities.

        You can also read more about:

        Choosing the Right Method

        When deciding between the two methods, consider your technical expertise and how frequently you need to sync data:

        • If you’re comfortable with scripting and need a lightweight or one-time solution, Google Apps Script gives you full control, though it requires manual setup and ongoing maintenance.
        • For a scalable, no-code alternative that automates the entire process, Hevo is a better fit. It offers pre-built connectors, automatic schema mapping, and ensures zero data loss, so you can spend more time analyzing data, not moving it around.

        Sign up for a 14-day free trial and experience a hassle-free data pipeline with Hevo. Also, check out Hevo’s pricing details to understand which plan fulfills all your business needs.

        FAQs

        How can I connect Google Sheets to SQL Server without coding?

        You can use Hevo, a no-code data pipeline platform, to connect Google Sheets with SQL Server in just two steps: set Google Sheets as your source and SQL Server as your destination. Hevo automatically syncs your data in real time without any manual uploads or scripts.

        Can I connect Google Sheets to SQL Server using Google Apps Script?

        Yes. You can use Google Apps Script’s JDBC service to connect Sheets to SQL Server. However, it requires manual setup, coding, and whitelisting Google’s IP ranges, making it more suitable for technical users or one-time data transfers.

        What are the main benefits of migrating Google Sheets data to SQL Server?

        Migrating data to SQL Server improves data management, security, scalability, and collaboration. It also enables advanced analytics and integrations with BI tools like Power BI, enhancing decision-making and reporting efficiency.

        Which method is better, Hevo or Apps Script?

        If you prefer a fully automated, no-code solution, Hevo is the best choice. It supports 150+ connectors, handles schema mapping automatically, and ensures zero data loss.
        If you’re comfortable coding and need a lightweight setup, Apps Script works but it requires ongoing maintenance.

        Is Hevo free to use for connecting Google Sheets to SQL Server?

        Hevo offers a 14-day free trial, allowing you to connect Google Sheets to SQL Server and test data flows without any commitment. After that, you can explore Hevo’s pricing plans to choose the best fit for your data volume and business needs.

        Vishal Agrawal
        Technical Content Writer, Hevo Data

        Vishal Agarwal is a Data Engineer with 10+ years of experience in the data field. He has designed scalable and efficient data solutions, and his expertise lies in AWS, Azure, Spark, GCP, SQL, Python, and other related technologies. By combining his passion for writing and the knowledge he has acquired over the years, he wishes to help data practitioners solve the day-to-day challenges they face in data engineering. In his article, Vishal applies his analytical thinking and problem-solving approaches to untangle the intricacies of data integration and analysis.