microsoft / microsoft/vscode-mssql
[Feature Request]: Add option to include USE [database] header when scripting from "Search Database Objects"
- Dominant language
- TypeScript
- Stars
- 1.9k
- Forks
- 610
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 97
Description
### Feature Description
The "Search Database Objects" feature is a great addition for quickly scripting Procedures, Functions, and other objects. However, the generated scripts currently start directly with the object definition.
In environments where we manage multiple databases with identical schemas (such as multi-tenant systems, or Dev/QA/Prod mirrors), this poses a significant operational risk. If a user has an active connection to "Database_A" but scripts an object from "Database_B," executing that script without manually changing the context will accidentally modify "Database_A."
Relying on manual intervention to add a USE statement is error-prone. Automating this context-setting header would prevent accidental executions in the wrong database and streamline the workflow for DBAs managing complex environments.
### Problem and Motivation
I propose adding a new setting to the extension to automatically prepend the database context to any script generated via the "Search Database Objects" panel.
- **Suggested Setting Name**: _mssql.search.includeUseDatabaseHeader_
- **Proposed Behavior**: When this setting is enabled, every script generated should begin with:
```
USE [Target_Database_Name]
GO
```
- **Goal**: This ensures that the script is bound to its source database, regardless of the current active connection in the VS Code editor, providing a "safety net" for batch updates across multiple environments.
### Related Area
- [ ] Connection dialog (SQL Server | Azure browse/Fabric browse)
- [ ] Query editor
- [ ] Query results panel
- [ ] Object Explorer
- [ ] GitHub Copilot integration
- [ ] Preview/Edit data
- [ ] Table Designer
- [ ] Schema Designer
- [ ] Schema Compare
- [ ] Local SQL Server Container provisioning
- [ ] SQL database in Fabric provisioning
- [ ] DACPAC/BACPAC export/import
- [ ] SQL Database projects
- [ ] Query Plan Visualizer
- [x] Other (please describe below)
### If you selected "Other", please describe the area
The new feature **Search Database Objects**
### Confirmation
- [x] I have searched existing feature requests and couldn't find a match
- [ ] I want to help implement this feature
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by locating the Search Database Objects entry point and the code that generates its scripts, then inspect how extension settings are declared and read. Add the proposed mssql.search.includeUseDatabaseHeader option and verify that enabling it prepends the target database context to generated scripts without changing the existing output when disabled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- sql, typescript, vscode
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100