Stored views​

Powerful way to streamline the information stored in your cloud database in an organized modular way

What is a stored view?

A stored view is a virtual collection defined by a query. It doesn’t contain it’s own data, instead it displays the contents of other collections. As queries grow more complex and difficult to understand, stored views help to break them down into smaller modular parts.

Creating a stored view

In the following example, we have a large database of users, however most of them are no longer active and we don’t want to consider them in our reports. Unfortunately, filtering out inactive users is not that straight forward, we first have to check what is the last time they logged in.

SELECT * FROM emulated.users
WHERE DATEDIFF(lastLogin, GETDATE()) < 30

This query filters out all users who logged in within the last 30 days. This is obviously bad database design, it would be useful to have a boolean flag isActive and update it periodically. In that way we would not need to run the query as emulated, which would be more resource optimized.

Instead of copying this condition every time we want to work with active users only, we save this query as a view activeUsers. The save view icon is located in vertical bar between the query editor and code generator. Now we can reference it in all our queries as:

SELECT * FROM activeUsers