Tutorial: Automate Daily SQL Queries in 4 minutes
Tags: sql, automation, beginners
Published: 2020-04-15 12:57:34

##Introduction
Looking to automate SQL queries? You're in the right place. In this tutorial, we'll look at how we can set up an automated system using WayScript, which will query your SQL based database daily, hourly, weekly, or at whatever time interval you want. Let's get started!

*WayScript is a rapid development platform built for busy developers. Currently in Beta, it's free and would love your feedback.*

##Prerequisites
No prerequisites but some content you might find helpful:
[Working with our SQL Module](https://docs.wayscript.com/library/modules/sql)
[Working with our Time Triggers](https://docs.wayscript.com/library/triggers/time-trigger)

##Automating an Action at Intervals
On WayScript, we're able to easily automate complex interactions on a schedule. Whether you need to run a script by the day, hour, or minute, you can easily do this in our editor. To start programming on WayScript, sign up on the home page, or login to your account. We can create scripts, by clicking on the "+ New Script" at the top of the webpage. These scripts are what will house our automations.

We're able to automate anything on a schedule using time triggers. We can pull a time trigger into our workflow and configure the settings:

![Alt text of image](https://cdn.wayscript.com/blog_img/39/1.png)

To activate our SQL script daily, we'll need to set it to that.

![activate our SQL script](https://cdn.wayscript.com/blog_img/39/2.png)

There's other options we could select here if we wanted to, including the option to input custom CRON syntax. We'll keep it simple and just select the daily option. Next, we can specify what time of day we want to execute our query.

![specify what time of day](https://cdn.wayscript.com/blog_img/39/3.png)

##Querying our Database
Now that we have the time trigger in place, we need to build our script! Since we're wanting to do a query on a database, we should drag in a SQL module.

![Drag SQL module](https://cdn.wayscript.com/blog_img/39/4.png)

With WayScript, we're able to do anything we could do with our database locally, like reading and writing data. We can add a database to our account by selecting the drop down of "add a database" and providing our database information.

![add a database](https://cdn.wayscript.com/blog_img/39/5.png)

Supplying our database information:

![Supplying our database information](https://cdn.wayscript.com/blog_img/39/6.png)

Once we supply this information, we're able to fully access our database on WayScript. If you get stuck while trying to set up your database, feel free to reference this Youtube tutorial.

Next, we can write SQL directly into WayScript's editor by clicking on edit code:

![Click Edit](https://cdn.wayscript.com/blog_img/39/7.png)

Let's pull data from our database about products we're making:

<pre>SELECT *
FROM order_summary</pre>

which pulls some dummy data that we can import into our workflow:

![Data to import](https://cdn.wayscript.com/blog_img/39/8.png)

##Doing more with our Data
With a simple two minute script, we can automate doing a query on our database. It's pretty easy from here to use this data on WayScript's platform too! Should you want to send emails, add data to google sheets, integrate with forms, build automated bots, WayScript makes it easy.

##Questions?
If there's any questions leave a comment and we'll help you out. Or, feel free to join our Discord channel as well.