In an earlier story, I walked through installing and testing Azure’s Data Studio connection to Azure SQL Database.
In this follow-up, I go through how to change the output type of queries or stored procedures into JSON. I also show how to get started with Azure’s data insights (really cool visualizations).
How to change your output to JSON
Reminder: In this stored procedure, we fetch all the data for any customer with the input customer id.
Now, let’s aim to store the output in a JSON file. You just add this command after your query:
FOR JSON PATH et voilà!
Let’s see how the output looks like below. You can even add this command after any query and the output will be in JSON format.
PS: Even if the command has a squiggly line underneath it — it still works, trust me, I tried it :)
How to create COOL visualizations
This is huge — I am super excited that Azure Data Studio lets you create your own mini visualizations instead of just a table. You can even add it to a dashboard that constantly refreshes (can become handy in query performance, PSI calculations or literally anything).
Let’s get started already!
Create an insight
- Write a small query just to try this out:
SELECT title as Titles, count(*) as Count
GROUP by Title
This query will fetch all the different titles for the customers, and then groups them and returns the count of each title.
2. Instead of the tabulated results, you can click on the plot icon on the right.
3. This will show you a bar plot that represents our data. Don’t forget to click Use First Column as row label in the bar plot’s settings. The actual plot is so cool, it shows you a clear legend with a tooltip functionality to check the actual counts.
How to turn this into a dashboard widget
- Click on Create Insight on the plots top left corner
- This will take you to a new file contains some widget settings (check image below)
3. Select all the widget settings, hit right-click and select Format Document. This will help you see it a bit more clearly :)
4. Hit CMD+comma (like this comma
, ). This will open the dashboard settings where we want the widget to be. Just look at the image below, you can already see where our widget will be located.
5. Search for dashboard.database.widgets
6. Click on the tiny pencil next to dashboard.database.widgets. and select Copy to settings.
You can see a new yellow part shows up on the right hand side of your screen.
7. Now let’s focus a bit: remember the widget settings that we fixed the format for earlier? — in step 3 above — go back and copy those settings.
8. Where to paste them?
Look at Image Look at Me below. JSON is precise science, so you need to focus on this one.
9. Paste your settings after the last
} before the
] . See that comma, don’t forget to add it right before your pasted settings.
10. We’re almost done, I promise!
Hit Save, and go to your server homepage.
11. Double-click on sql-test-medium (or your server’s name).
Et voilà! See, that wasn’t so hard.
I hope you enjoyed my quick walkthrough of Azure Data Studio!