Status: Reviewed (deep-dive v1)
Stack note: PowerShell collectors hit instance DBs; boards and merges live in the warehouse. Keep that boundary clean — synonyms (and disciplined three-part names) so usp_* don’t hardcode server.database soup in every proc. Blazor talks only to warehouse procs (SQL-12).
Pairs with: SQL-01/SPIKE-01 (inventory), SQL-19 (merges), SQL-05 (cross-db rights), SQL-09 (linked/AG naming).
Goal: When to use synonyms, how to shape warehouse↔instance access for PS, and what not to do.
| Need | Prefer | Avoid |
|---|---|---|
| Stable name for an object that moves/renames | Synonym in warehouse | Find/replace three-part names everywhere |
| PS collect from many instances | Connect per instance → stage → warehouse merge | One linked-server cursor mega-proc as default |
| Board reads | Warehouse tables only | Blazor querying instance DBs directly |
| Rare admin reach into instance | Controlled linked server / PS remoting | App pool with rights on every prod DB |
| Cross-db same instance | Three-part db.schema.object or synonym |
Dynamic SQL with raw DB names from UI (SQL-14) |
[SQL instances] --PS collectors--> staging / TVP --> [Warehouse] --usp_*--> [Blazor]
| ^
+----- optional synonyms --------+ (local aliases only)
-- In warehouse: alias a table in another DB on same instance
CREATE SYNONYM dbo.LegacyConfig FOR ConfigDB.dbo.AppSetting;
-- Alias via linked server (use sparingly)
CREATE SYNONYM dbo.RemoteProbe FOR LinkedSql01.msdb.dbo.sysjobs;
-- Use like a local object
SELECT * FROM dbo.LegacyConfig;
Notes:
DROP/CREATE to retarget after rename -- env deploy pattern: script sets target
CREATE SYNONYM dbo.RefCalendar FOR $(RefDb).dbo.Calendar;
| Pattern | Use |
|---|---|
Warehouse.dbo.usp_… reading InventoryAux.dbo.T |
Three-part name or synonym |
| Same-instance reporting | Synonym keeps proc text stable if aux DB renamed |
| Permissions | Grant on base objects; test as app/Agent account |
Don’t grant Blazor db_owner on aux DBs “so joins work.”
Prefer PS multi-connect for estate collect:
SqlInstance) usp_*_Merge (SQL-19) Linked servers when:
Checklist if you use them:
RPC/RPC OUT only if required Boards = warehouse. Remediation = ops/PS/Agent with separate rights (SPIKE hard rule).
/sql/warehouse/synonyms/001_ref_synonyms.sql
/sql/warehouse/procs/...
/ps/Collect-SqlInventory.ps1 # connects to instances, writes warehouse
| Principal | Warehouse | Instance DBs |
|---|---|---|
| Blazor app pool | EXECUTE on usp_* (+ TVP types) |
None |
| Agent merge job | Write staging + merge procs | None (data already staged) |
| PS collector | Write staging / exec merge | Read dmvs / needed views per instance (least priv) |
| DBA | Broader | Broader |
Cross-db synonym read: grant SELECT on base table to the executing principal (or use module signing — advanced; document if used).
| Symptom | Likely cause |
|---|---|
| Synonym works for you, fails for app | Missing grants on base object |
| Slow board suddenly | Proc started using linked server path |
| Collector “works in IDE” | Different login mapping |
| Broken after restore/rename | Synonym target stale |
| Security finding | App pool reaching instances |
| # | Topic |
|---|---|
| 18 | Transactions & isolation |
| 19 | MERGE & idempotent upserts |
| 20 | Query Store for procs |
| 21 | TVPs from Blazor/PS |
| 22 | Temporal / history |
| 23 | Synonyms & cross-DB (this note) |
SQL Dude — SQL-23 Synonyms & Cross-DB Access v1