What Reaches Outside Your Database? sys.dm_db_uncontained_entities
Every database likes to pretend it is self-contained. Then you restore it onto another instance and discover the stored procedure that queries a sister database, the synonym pointing at a linked server, the login-mapped user…