This extension provides a tool to generate SQL scripts from SQL Server objects, such as functions, stored procedures, views, and triggers, directly within Visual Studio Code.
Features
SQL Script Generator: Quickly generate SQL scripts for SQL Server objects.
Shortcut customization: The shortcut Ctrl + T invokes the SQL script generator and Ctrl + Shift + T refreshes the object list.
Configurable SQL Server port: Use sqlScriptGenerator.sqlPort to define a default port if it’s missing in the connection string.
Option to include USE DATABASE in generated scripts: Use sqlScriptGenerator.includeUseDatabase to enable or disable this feature.
Requirements
You need to have SQL Server installed and accessible.
Install the mssql extension for Visual Studio Code to allow connection to SQL Server databases. Install mssql extension
Currently, SQL Server Authentication is required to connect to the database server. Windows Authentication is not supported at this time. Please ensure that you select SQL Server Authentication when connecting.
Extension Settings
This extension contributes the following settings:
sqlScriptGenerator.shortcut: Customize the keyboard shortcut for generating SQL scripts. Default: Ctrl + T.
sqlScriptGenerator.refresh: Use Ctrl + Shift + T to refresh the SQL object list.
sqlScriptGenerator.sqlPort: Set the default SQL Server port in case it's not found in the connection string.
sqlScriptGenerator.includeUseDatabase: Set this to true to automatically include USE DATABASE in generated scripts.
sqlScriptGenerator.useAlter: Set this to true to generate script using ALTER instead of CREATE statement.
sqlScriptGenerator.clearConnectionAfterGenerateScript: set this to true to clean up the connection every time a script is generated.
Release Notes
0.0.1
Initial release of the SQL Script Generator extension.
0.1.0
Added functionality to list SQL Server objects (functions, views, procedures, triggers).
Fixed issues related to database connection handling.
The extension icon was added.
0.2.0
A functionality was added to execute the extension with a keyboard shortcut (Ctrl + T).
A functionality was added to allow specifying the SQL Server connection port via configuration, in case it is not set in the connection string or configuration.
0.3.0
The README file was updated with new instructions and added features.
1.0.0
The official version is made.
2.0.0
Fixed SQL connection reset issue: The extension now properly maintains the SQL Server connection, preventing unnecessary reconnections.
Persistent connection: It is no longer necessary to establish the server and database connection every time the extension is invoked. Just search for the object, making the process much faster and more efficient. 🎉
2.1.0
Fixed a bug related to the connection to local servers. The issue caused intermittent connection failures when attempting to connect to local database servers.
Implemented automatic connection to SQL Server before loading objects, ensuring the user has an active session.
Optimized database object loading, including functions, stored procedures, views, and triggers.
Improved the user interface with status messages in the VS Code status bar for a better experience.
Fixed issues related to connection closing and exception handling.
2.2.0
Added configuration to include USE DATABASE in scripts: A new setting sqlScriptGenerator.includeUseDatabase allows users to control whether the generated scripts should include USE DATABASE at the beginning.
2.3.0
Added configuration option sqlScriptGenerator.useAlter to generate scripts using ALTER instead of CREATE. Example: If enabled, CREATE PROCEDURE will be replaced with ALTER PROCEDURE.
2.4.0
Title changes to run the extension by pressing F1
Refresh SQL Objects is now SQL Script Generator | Refresh Connection.
2.4.1
Security patch
2.5.0
Added a setting sqlScriptGenerator.clearConnectionAfterGenerateScript to clean the connection every time a script is generated.