An Introduction To Azure Data Studio

In this article, we will see some of the features of the newly introduced Azure Data Studio. This is a cross-platform, lightweight database tool for data professionals and developers who are using the Microsoft family of on-premises and cloud data platforms on Windows, MacOS, and Linux.

Azure Data Studio offers a modern editor experience, code snippets, source control integration, and an integrated terminal. We can say, this might be a full replacement for traditional SSMS (SQL Server Management Studio) in future.
 
Please download Azure Data Studio from this Link.
 
Connect and Query Azure Data Studio.
 
Azure Data Studio 
 
Enter your server details. Here, I am connecting with my SQL Server 2017 instance. I am using my Windows Authentication to connect server.
 
Azure Data Studio 
 
It will show all your database details. I have only one user-defined database in my SQL server. The other four are system databases.
 
Azure Data Studio 
 
It will also show the database size details in a very attractive way.
 
Azure Data Studio 

Using T-SQL Code Snippets in Azure Data Studio

One of the major advantages in Azure Data Studio is its T-SQL Code Snippets. It has many built-in Code Snippets available.

We can use T-SQL Code Snippet to Create a new Database. Please open a new SQL Query window (Ctrl+N) and type “SQL

Azure Data Studio
Please select “sqlCreateDatabase” snippet and press Enter key.
 
Azure Data Studio 
  1. -- Create a new database called 'DatabaseName'  
  2. -- Connect to the 'master' database to run this snippet  
  3. USE master  
  4. GO  
  5. -- Create the new database if it does not exist already  
  6. IF NOT EXISTS (  
  7.     SELECT [name]  
  8.         FROM sys.databases  
  9.         WHERE [name] = N'DatabaseName'  
  10. )  
  11. CREATE DATABASE DatabaseName  
  12. GO  

It will automatically fill the code snippets to the Query editor. You can give a valid name to the Database and execute the Query.

Azure Data Studio 
  1. -- Create a new database called 'DatabaseName'  
  2. -- Connect to the 'master' database to run this snippet  
  3. USE master  
  4. GO  
  5. -- Create the new database if it does not exist already  
  6. IF NOT EXISTS (  
  7.     SELECT [name]  
  8.         FROM sys.databases  
  9.         WHERE [name] = N'SarathDB'  
  10. )  
  11. CREATE DATABASE SarathDB  
  12. GO  

We can create our own T-SQL Code Snippets very easily. Please open Command Pallet (Ctrl+Shift+P) and type “snip”

Azure Data Studio 
 
Choose SQL snippet. (sql.json file)
 
Azure Data Studio 
 
I have added two code snippets in this file. One is for selecting the top 100 records from any table, and the other is for creating a new table. You can add any number for code snippets in this file. Please note that we can define any number for parameters for each code snippet also.
 
Azure Data Studio 
  1. {   "Select top 100": {  
  2.         "prefix""sqlSelectTop100",  
  3.         "body""SELECT TOP 100 * FROM ${1:TableName} ORDER BY ${2:ColumnName}",  
  4.         "description""Select Top 100 Records from a Table"  
  5.     },  
  6.     "Create Table snippet":{  
  7.         "prefix""sqlCreateTableSarath",  
  8.         "body": [  
  9.         "-- Create a new table called '${1:TableName}' in schema '${2:SchemaName}'",  
  10.         "-- Drop the table if it already exists",  
  11.         "IF OBJECT_ID('$2.$1', 'U') IS NOT NULL",  
  12.         "DROP TABLE $2.$1",  
  13.         "GO",  
  14.         "-- Create the table in the specified schema",  
  15.         "CREATE TABLE $2.$1",  
  16.         "(",  
  17.         "   $1Id INT NOT NULL PRIMARY KEY, -- primary key column",  
  18.         "   Column1 [NVARCHAR](50) NOT NULL,",  
  19.         "   Column2 [NVARCHAR](50) NOT NULL",  
  20.         "   -- specify more columns here",  
  21.         ");",  
  22.         "GO"  
  23.         ],  
  24.        "description""User defined snippets: Create a new Table"  
  25.     }  
  26. }  

We can check the new code snippets in Query editor window. Please type “SQL” again

Azure Data Studio 
Please note the newly added two code snippets listed in Query editor. You can choose any of the new code snippets and press the Enter key. Our new code snippet will be loaded successfully.
 
Azure Data Studio 
  1. -- Create a new table called 'TableName' in schema 'SchemaName'  
  2. -- Drop the table if it already exists  
  3. IF OBJECT_ID('SchemaName.TableName''U'IS NOT NULL  
  4. DROP TABLE SchemaName.TableName  
  5. GO  
  6. -- Create the table in the specified schema  
  7. CREATE TABLE SchemaName.TableName  
  8. (  
  9.    TableNameId INT NOT NULL PRIMARY KEY-- primary key column  
  10.    Column1 [NVARCHAR](50) NOT NULL,  
  11.    Column2 [NVARCHAR](50) NOT NULL  
  12.    -- specify more columns here  
  13. );  
  14. GO  

Adding new Extensions to Azure Data Studio

You can add more extensions easily by clicking the “Settings” icon and then clicking “Manage Extensions” button.
 
Azure Data Studio 
 
SQL Server Import is one of the recommended extensions by Azure Data Studio.
 
Azure Data Studio 
 
You can click the “Install” button.
 
Azure Data Studio 
 
After some time, the new extension will be installed successfully.
 
Azure Data Studio 
We can use this SQL Import tool to import data from CSV or JSON file to SQL database.
 
Please right-click the Database and choose “Import Wizard” to start.
 
Azure Data Studio 
 
Please specify the Input Filename.
 
Azure Data Studio 
 
You can Preview the Data here.
 
Azure Data Studio 
 
We can modify the columns if needed.
 
Azure Data Studio 

After making the modifications (if needed) in the columns you can click the “Import” button.

Our Import process will be finished soon.

Azure Data Studio 
 
You can use the SQL Query to select data from a new table.
 
Azure Data Studio 
  1. SELECT * from dbo.employee   
You can see the Query Plan by clicking the “Explain” button.
 
Azure Data Studio
 
It will open a Query Plan tab. You can see the Query plan summary by moving the mouse cursor to “SELECT” area.
 
Azure Data Studio 
 
You can also view the entire index scan details by moving the mouse cursor to “Clustered Index Scan” area.
 
Azure Data Studio


Similar Articles