Easily move your data from Google Sheets to SQL Server to enhance your analytics capabilities. With Hevo’s intuitive pipeline setup, data flows in real-time—check out our 1-minute demo below to see the seamless integration in action!

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 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 fed from a SQL Server database.

In this guide, we outline 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.

Overview of SQL Server

SQL Server
  • SQL Server is a popular Relational Database Management System (RDBMS) provided by Microsoft Corporation. It offers many features that you can use to create, manage, and analyze databases.
  • Some of the key features that SQL Server provides include storing, retrieving, and securely managing relational data; it supports Transact SQL (TSQL), which enables you to query and manipulate data in your database. SQL Server also includes integration, analysis, and reporting capabilities that help in data modeling and generate useful insights.
Effortlessly Connect Google Sheets to SQL Server using these Methods

Method 1: Automatically Connect Google Sheets to SQL Server using Hevo
Manually connecting Google Sheets to SQL Server can be complex and time-consuming. Instead, use the Apps Script for a straightforward and efficient data migration solution. Follow our simple steps to establish your connection with ease!

Method 2: Using the Apps Script to Connect Google Sheets to SQL Server Manually
Skip the complexity of coding and multiple setup steps. With Hevo, you can seamlessly migrate data from Google Sheets to SQL Server in minutes. Simplify your data integration process effortlessly!

Get Started with Hevo for Free

Method 1: Automatically Connect Google Sheets to SQL Server using Hevo

Step 1.1: Configure Google Sheets as Your Source

Google Sheets to SQL Server: Source Configuration

Step 1.2: Configure SQL Server as Your Destination

Google Sheets to SQL Server: Destination Configuration

You may transfer data from a Google Form to SQL database by completing the above-mentioned steps.

Benefits of Using Hevo

  • In-built Transformations: Format your data on the fly with Hevo’s preload transformations using either the drag-and-drop interface or our nifty Python interface. Generate analysis-ready data in your warehouse using Hevo’s Postload Transformation.
  • Near Real-Time Replication: Get access to near real-time replication for all database sources with log-based replication. For SaaS applications, near real-time replication is subject to API limits.
  • Auto-Schema Management: Correcting improper schema after the data is loaded into your warehouse is challenging. Hevo automatically maps source schema with the destination warehouse so that you don’t face the pain of schema errors.
  • Security: Discover peace with end-to-end encryption and compliance with all major security certifications including HIPAA, GDPR, and SOC-2.

Method 2: Using the Apps Script to Connect Google Sheets to SQL Server Manually

Loading the data from Google Sheets to SQL Server is not a tedious task; however, it requires a script that will connect to SQL Server to access the objects. Google App Script provides a JDBC service to connect to SQL Server. Below is the step-by-step approach to load data from Google Sheets to SQL Server.

Step 2.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 below 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.2: Create a Google Sheet

  • Login 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 the New Tab.
  • Provide a name to the SpreadSheet and add some data.
Google Sheets to SQL Server:  Google sheet data
Image Source: Self
  • Launch the Script Editor from, Tools>Script Editor. This editor will be used to write the scripts connecting to SQL Server. 
  • This is what the default page will look like:
Google Sheets to SQL Server: Execute Script
Image Source: Self

Step 2.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 below lines of code:

Step 2.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 2.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 2.3.3: Create a New User with the Necessary Privileges

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

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 2.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 2.4: Writing to Database

Now that you have created the database, tables, and user, you will now create the function to write the data from Google Sheets to SQL Server. Use the following code to write in SQL Server using batch mode

Step 2.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 2.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 to Connect Google Sheets to SQL Server

Limitations of using Apps Script for connecting Google Sheets to SQL Server are listed below:

  • A lot of coding is required to move the data from Google Sheets to SQL Server. This method is only feasible for technical users.
  • 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.
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

Reasons to Migrate Data from Google Sheets to SQL Server

Google Sheets allows you to edit, arrange, and analyze various types of data. It enables collaborations, concurrent editing, and formatting by multiple users and tracks all spreadsheet revisions.

SQL Server offers improved performance thanks to its integrated transparent data compression and encryption features. SQL Server provides access controls and effective permission management tools to assist users in protecting sensitive business data.

When integrated together, moving data from Google Sheets to SQL Server could solve some of the biggest data problems for businesses.

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

Conclusion

  • In this blog, you have learned how to import data from Google Sheets to SQL Server using two methods.
  • One method includes using the Apps Script to connect Google Sheets to SQL Server manually.
  • The other method allows you to connect automatically, using Hevo to connect Google Sheets to SQL Server.

Sign up for a 14-day free trial and simplify your data integration process. Check out the pricing details to understand which plan fulfills all your business needs.

FAQ on Google Sheets to SQL Server

How to convert Google Sheets to database?

You can use tools like Google Apps Script to write a script that exports data from Google Sheets to a database or use third-party tools like Hevo Data.

How do I transfer data from Google Sheets to MySQL?

To export data from Google Sheets to MySQL, you can use tools like Sheet2SQL, Hevo Data, or Google Apps Script.

Does Google Sheets support SQL?

No, Google Sheets does not natively support SQL, but you can use Google Sheets Query functions for similar tasks.

How do I import a spreadsheet into SQL Server?

Use SQL Server Import and Export Wizard to import data from an Excel spreadsheet into SQL Server.

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.