This article shows how to use the mssql extension for Visual Studio Code to develop SQL Server databases. Because Visual Studio Code is cross-platform, you can use mssql extension on Linux, macOS, and Windows.
SQLPro Studio is the premium database management tool for Postgres, MySQL, Microsoft Management Studio, and Oracle databases. Intellisense/SQL auto-completion; Syntax highlighting with customizable themes (including dark) Tab-based interface for an optimal user experience. Popular Alternatives to SQL Server Management Studio for Mac. Explore 13 Mac apps like SQL Server Management Studio, all suggested and ranked by the AlternativeTo user community.
Install and start Visual Studio Code
Visual Studio Code is a cross-platform, graphical code editor that supports extensions.
Download and install Visual Studio Code on your machine.
Start Visual Studio Code.
Note
If Visual Studio Code does not start when you are connected through an xrdp remote desktop session, see VS Code not working on Ubuntu when connected using XRDP.
Install the mssql extension
The mssql extension for Visual Studio Code lets you connect to a SQL Server, query with Transact-SQL (T-SQL), and view the results.
In Visual Studio Code, select View > Command Palette, or press Ctrl+Shift+P, or press F1 to open the Command Palette.
In the Command Palette, select Extensions: Install Extensions from the dropdown.
In the Extensions pane, type mssql.
Select the SQL Server (mssql) extension, and then select Install.
After the installation completes, select Reload to enable the extension.
Create or open a SQL file
The mssql extension enables mssql commands and T-SQL IntelliSense in the code editor when the language mode is set to SQL.
Select File > New File or press Ctrl+N. Visual Studio Code opens a new Plain Text file by default.
Select Plain Text on the lower status bar, or press Ctrl+K > M, and select SQL from the languages dropdown.
Note
If this is the first time you have used the extension, the extension installs supporting SQL Server tools.
If you open an existing file that has a .sql file extension, the language mode is automatically set to SQL.
Connect to SQL Server
Follow these steps to create a connection profile and connect to a SQL Server.
Press Ctrl+Shift+P or F1 to open the Command Palette.
Type sql to display the mssql commands, or type sqlcon, and then select MS SQL: Connect from the dropdown.
Note
A SQL file, such as the empty SQL file you created, must have focus in the code editor before you can execute the mssql commands.
Select the MS SQL: Manage Connection Profiles command.
Then select Create to create a new connection profile for your SQL Server.
Follow the prompts to specify the properties for the new connection profile. After specifying each value, press Enter to continue.
Connection property Description Server name or ADO connection string Specify the SQL Server instance name. Use localhost to connect to a SQL Server instance on your local machine. To connect to a remote SQL Server, enter the name of the target SQL Server, or its IP address. To connect to a SQL Server container, specify the IP address of the container's host machine. If you need to specify a port, use a comma to separate it from the name. For example, for a server listening on port 1401, enter <servername or IP>,1401
.
As an alternative, you can enter the ADO connection string for your database here.Database name (optional) The database that you want to use. To connect to the default database, don't specify a database name here. Authentication Type Choose either Integrated or SQL Login. User name If you selected SQL Login, enter the name of a user with access to a database on the server. Password Enter the password for the specified user. Save Password Press Enter to select Yes and save the password. Select No to be prompted for the password each time the connection profile is used. Profile Name (optional) Type a name for the connection profile, such as localhost profile. After you enter all values and select Enter, Visual Studio Code creates the connection profile and connects to the SQL Server.
Tip
If the connection fails, try to diagnose the problem from the error message in the Output panel in Visual Studio Code. To open the Output panel, select View > Output. Also review the connection troubleshooting recommendations.
Verify your connection in the lower status bar.
As an alternative to the previous steps, you can also create and edit connection profiles in the User Settings file (settings.json). To open the settings file, select File > Preferences > Settings. For more information, see Manage connection profiles.
Create a SQL database
In the new SQL file that you started earlier, type sql to display a list of editable code snippets.
Select sqlCreateDatabase.
In the snippet, type
TutorialDB
to replace 'DatabaseName':Press Ctrl+Shift+E to execute the Transact-SQL commands. View the results in the query window.
Tip
You can customize the shortcut keys for the mssql commands. See Customize shortcuts.
Create a table
Delete the contents of the code editor window.
Press Ctrl+Shift+P or F1 to open the Command Palette.
Type sql to display the mssql commands, or type sqluse, and then select the MS SQL: Use Database command.
Select the new TutorialDB database.
In the code editor, type sql to display the snippets, select sqlCreateTable, and then press Enter.
In the snippet, type
Employees
for the table name.Press Tab to get to the next field, and then type
dbo
for the schema name.Replace the column definitions with the following columns:
Press Ctrl+Shift+E to create the table.
Insert and query
Add the following statements to insert four rows into the Employees table.
While you type, T-SQL IntelliSense helps you to complete the statements:
Tip
The mssql extension also has commands to help create INSERT and SELECT statements. These were not used in the previous example.
Press Ctrl+Shift+E to execute the commands. The two result sets display in the Results window.
View and save the result
Select View > Editor Layout > Flip Layout to switch to a vertical or horizontal split layout.
Select the Results and Messages panel headers to collapse and expand the panels.
Tip
You can customize the default behavior of the mssql extension. See Customize extension options.
Select the maximize grid icon on the second result grid to zoom in to those results.
Note
The maximize icon displays when your T-SQL script produces two or more result grids.
Open the grid context menu by right-clicking on the grid.
Select Select All.
Open the grid context menu again and select Save as JSON to save the result to a .json file.
Specify a file name for the JSON file.
Verify that the JSON file saves and opens in Visual Studio Code.
If you need to save and run SQL scripts later, for administration or a larger development project, save the scripts with a .sql extension.
Next steps
If you're new to T-SQL, see Tutorial: Write Transact-SQL statements and the Transact-SQL Reference (Database Engine).
For more information on using or contributing to the mssql extension, see the mssql extension project wiki.
For more information on using Visual Studio Code, see the Visual Studio Code documentation.
- Advertisement
- Navicat for SQL Server for Mac OS v.9.1An ideal solution for administration and development which lets you create, edit databases, run SQL queries and connect to remote SQLServer in an easier way. It features an intuitive GUI and offers powerful visual tools such as Query Editor with ...
- Devart ODBC Driver for SQL Server v.1.1Devart ODBC Driver for SQLServer provides high-performance and feature-rich connectivity solution for ODBC-based applications to access SQLServer databases from Windows, Linux, MacOS, both 32-bit and 64-bit.
- Actual ODBC Driver for SQL Server v.2.6The Actual SQLServer ODBC Driver lets you access your companys Microsoft SQLServer database from within Microsoft Excel. You can connect to any database you are authorized to use, and work with the data just like your Windows-using co-workers. All ...
- PHP SQL Server (MSSQL) Query Analyzer v.0.43Web based tool written in PHP by Luiz Miguel Axcar to build and run queries on a remote or local MSSQL (Microsoft SQLServer). Support for SQL code highlight (!!!), table browser, field browser, TOP records, most used tables, CSV results export, ...
- JTDS - SQL Server and Sybase JDBC driver v.1.0Open source JDBC 3.0 type 4 driver for Microsoft SQLServer (6.5 up to 2012) and Sybase ASE. jTDS is a complete implementation of the JDBC 3.0 spec and the fastest JDBC driver for MS SQLServer. For more information see http://jtds.sourceforge.net/ ...
- MyDBR Web Reporting v.3. 3. 2000myDBR is an innovative web reporting solution for MySQL and Microsoft SQLServer with support for latest smartphones (Android, iPhone, and Symbian). myDBR reporting solution brings unparalleled speed of authoring even the most complex reports. By ...
- Ranet OLAP v.3.1.741Library of components Ranet.UILibrary.OLAP is intended for creation of full-featured Internet applications (RIA, Rich Internet Application) by business analysts based on platform Microsoft SQLServer Analysis Services.
- PHPico Web Server v.0.1PHPico Web Server 0.1 provides you with a powerful servermanagement tool which is stand alone, single threaded and all code is load only once. The server do only handle the incoming and outgoing HTTP requests, and sets up the super global variables.
- PHP MSSQL Server Admin - Query Analyzer v.0.43Web based tool written in PHP by Luiz Miguel Axcar to build and run queries on a remote or local MSSQL (Microsoft SQLServer). Support for SQL code highlight (!), table browser, field browser, TOP records, most used tables, CSV results export, etc. ...
- Virtual Ticket Developer Professional v.2010Develop team productivity & project management apps.
- DB Solo v.3.0DB Solo is a powerful database development and management tool for developers and DBAs. DB Solo has an intuitive user interface that allows you to explore and manage your database objects as well as execute your own ad-hoc queries. DB Solo supports ...
- DB Solo for Mac OS v.3.8.2A cross-platform database development and management tool for developers and admins. DB Solo supports all major DBMS products available today, including Oracle, SQLServer 2000 and 2005, DB2, Sybase, H2, Postgres, MySQL and Solid.Key Features ...
- SourceAnywhere Standalone v.3.0.1SourceAnywhere Standalone is SQLserver-based version control software with seamless integration with Visual Studio, Eclipse, and other IDEs, cross-platform support, and unique caching mechanism for remote performance. SourceAnywhere Standalone ...
- MyInfoTool v.0.92rc1myInfoTool is a PHP driven, file based database and database management system. You do not need any SQLserver like mySQL. myInfoTool is a god choice for small sites without SQL support. Examples for use: news, guestbooks, FAQ...
- RazorSQL for Mac v.8.3.6SQL editor, database query tool, database browser, and db admin tool. Visually create, edit, alter, drop, and view objects as well as import and export data. Browse objects with the database browser. Supports over 40 databases.
- Apache AxKitApache AxKit is a convenient servermanagement tool which is used for Apache. It provides on-the-fly conversion from XML to any format, such as HTML, WAP or text using either W3C standard techniques, or flexible custom code. AxKit also uses a ...
- FmPro Migrator v.5.98FmPro Migrator quickly and accurately migrates FileMaker Pro database structure and data to MySQL, Oracle, Access, SQLServer, Sybase, DB2, OpenBase, PostgreSQL, FrontBase, SQLite and Valentina. -- Converts Access Forms/Reports, Relationships, Value ...
- SQLAPI++ for Mac OS X v.3.8.2.0SQLAPI++ is a library designed to enable you to access multiple SQL databases (Oracle, SQLServer, DB2, Sybase, InterBase, Informix, SQLBase, MySQL, PostgreSQL and ODBC, SQLite). It uses native APIs of target DBMS so applications developed with ...
- Izenda Ad Hoc - Express Edition v.4.0Izenda Ad Hoc - Agile Business Intelligence for ASP.NETLiberate Your Organization's Relational Data Today!Izenda Ad Hoc empowers business users to directly explore relational data from a web browser. * Intuitive and Completely Web-Based AJAX Report ...
- Consideo Process Modeler for Mac OS v.6.0.2An enhancement of the successful Consideo Modeler. It’s the first easy to use tool to run scenarios (System Dynamics) on constraints (ToC) and the critical chain of processes and projects. Connect to MS-Project, Excel or SQL, create management ...
Sql Management Studio For Windows 10
- PhotoUpLink for iPhoto for Mac OS An iPhoto export plugin that allows users to send images and
- Devart ODBC Driver for SQL Server Devart ODBC Driver for SQL Server provides
- Izenda Ad Hoc - Express Edition Izenda Ad Hoc - Agile Business Intelligence for
- Consideo Process Modeler for Mac OS An enhancement of the successful Consideo Modeler. It’s
- Ranet OLAP Library of components Ranet.UILibrary.OLAP is intended for
- Valentina Studio Pro for Mac OS Fast and powerful visual SQL database creation,
- ByteDesigner ByteDesigner is the emerging enterprise tool for designing
- PHPico Web Server PHPico Web Server 0.1 provides you with a powerful server
- Virtual Ticket Developer Professional Develop team productivity & project management apps.
- MyDBR Web Reporting myDBR is an innovative web reporting solution for MySQL and