A while ago I wrote a blog post about Azure SQL Data Warehouse and Power BI which I explained how to install a new instance of Azure SQL Data Warehouse and how to visualise your Azure SQL DW data in Power BI. In this post I explain how to query an Azure SQL DW in SSMS and Visual Studio.
Requirements
- SQL Server Data Tools (SSDT) for Visual Studio (2013 or 2015)
- Latest release of SQL Server Management Studio (SSMS) 2016 (Currently 13.0.15600.2)
- An existing instance of an Azure SQL Data Warehouse. If you don’t have an existing one check this out
Querying Azure SQL Data Warehouse from Visual Studio
Prior the latest release of SQL Server Management Studio (SSMS) 2016, the only available tool for querying an Azure SQL Data Warehouse was SQL Server Data Tools (SSDT) for Visual Studio 2013 or 2015. Here is how you can use SSDT 2015 to query an Azure SQL Data Warehouse:
-
Open SQL Server Data Tools 2015
-
Click “SQL Object Explorer” from View menu
-
Click “Add SQL Server”
-
Enter “Server Name”
-
If you don’t recall server name then open a web browser and log into Azure portal
-
Click “SQL databases”
-
Click any desired Azure SQL Data Warehouse you created before. Make sure the database is “Online”
-
Hover over the server name then copy it by clicking on “Copy” icon
-
Switch to Visual Studio and paste the server name
-
Change “Authentication” type to “Sql Server Authentication”
-
Enter “User Name” and “Password”
-
Select the Azure SQL Data Warehouse then click “Connect”
-
You successfully connected to the “Azure SQL Data Warehouse”
-
Expand the Server from “SQL Server Object Explorer” pane
-
Expand “Databases” then expand the database
-
Expand “Tables”
-
You can now see all of your data warehouse tables
-
To query the data warehouse right click on the data warehouse and click “New Query”
-
Write a T-SQL query and click on “Execute” button () or press “Ctrl + Shift + E”
- You can also right click on an object from Object Explorer and script the object.
Note: Drag and drop from SQL Object Explorer to query editor is NOT supported in Visual Studio.
I bet you hate the “Ctrl + Shift + E” key combination as much as I do. To change the above key combination:
-
Click “Tools” menu
-
Expand “Environment” then click “Keyboard”
-
On the “Show commands containing” type “execute”
-
Select “SQL.TSqlEditorExecuteQuery” from the list
-
Click in the “Press shortcut keys” box then press “F5”
-
Click “Assign”
-
You can see the current command that are currently using “F5” as shortcut
Querying Azure SQL Data Warehouse from SQL Server Management Studio (SSMS) 2016
In previous version of SSMS (2008, 2012, 2014, 2016 CTP3) you could connect to an instance of Azure SQL Data Warehouse, you could also execute T-SQL queries after you connected to the database, but, it wasn’t fully functional. For instance, whenever you open a new query editor you get the following message in SSMS 2008, 2012 and 2014:
“Unable to apply connection settings. The detailed error message is: ‘QueryGovernorCostLimit’ is not a recognized option.”
and you get the following error in SSMS 2016 CTP3:
“’HAS_PERMS_BY_NAME’ is not a recognized built-in function name. (Microsoft SQL Server, Error: 104162)”
Another example of issues using prior versions of SSMS with Azure SQL Data Warehouse is that they were unable to show the database tables in “Object Explorer” pane which means you couldn’t right click and script the tables.
The good news is that with the new release of SQL Server Management Studio 2016 (currently 13.0.15600.2) we can easily connect to an Azure SQL Data Warehouse, modify the objects, execute queries and see the tables in Object Explorer. Basically, we can do a lot in Azure SQL DW with SSMS as we used to do with any normal SQL databases.
-
Open SSMS 2016
-
Click “Connect” from Object Explorer
-
Select “Database Engine” for “Server type”
-
Enter Server name
-
Select “SQL Server Authentication” for “Authentication”
-
Enter Login and Password then click OK
-
From Object Explorer, expand databases, expand an existing data warehouse, then expand “Tables”
-
As you can see there is a new icon for an Azure SQL Data Warehouse (). There are also new icons for tables:
-
Tables with “Round robin” distribution method use () icon
-
Tables with “Hash Distributed” distribution method use () icon
-
Note: Check this out to learn more about Azure Data Warehouse distribution methods.
-
We can open a new query editor pressing “Ctrl+N” or by right clicking on the data warehouse and “New Query”
- When we open a new query editor we get the following warning:
- Click an option of your choice then write your SQL script and execute it normally
And, of course, you can drag and drop objects from the Object Explorer to the query editor.
You can also right click on an object from Object Explorer and script the object.