question

gmax51 avatar image
gmax51 asked

Attached AdventureWorks2012 but master database does not have AdventureWorks2012 objects.

I'm using SQL Server 2012 Developer version. I've attached AdventureWorks2012 and other practice databases using SSMS attach wizard (by right clicking "System Databases"). I can query these attached databases without a problem. But none of the attached databases' object references appear in master database or other system databases. My question is: how do I get the attached database objects to appear in master database?
system-databases
3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

I don't understand the question. AdventureWorks2012 is a user database. Attaching it will create a new user database. The master database will have a reference to the new database in the system view sys.databases. But creating/attaching a user database won't create any new objects in the master database.
0 Likes 0 ·
Note: This is my first time posting a question (on this site) and then responding to the answers. I'd welcome guidance site admins, if I've put this follow-up question in an inconvenient place. Hi Magnus and Grant, I do see the attached objects (AdventureWorks2012) in the Object Explorer. Because I'm using "best practices" in developing new scripts, I'd like to use expressions like: IF object_ID (N'SomeAdventureWorks2012Object') IS NOT NULL / DROP someObjectType SomeAdventureWorkds2012Object. So, how do I get SQL Server to "recognize" these AdventureWork2012 objects with Object_ID function?
0 Likes 0 ·
When responding to a comment or an answer, use the "Add New Comment" button below the comment or the Answer. The "Your answer" box is for posting a possible answer to the question above. If you're going to query for object_id from the master database, then you have to use three part naming, database.schema.object. There are examples here in the object_id entry of the SQL Server documentation: https://msdn.microsoft.com/en-us/library/ms190328.aspx If you are in the AdventureWorks database, you only need to use two part naming, schema.object.
0 Likes 0 ·

1 Answer

·
Grant Fritchey avatar image
Grant Fritchey answered
They won't appear in the master database. If you're not seeing them in SSMS, try doing a refresh. You do this by right clicking on the Database folder in Object Explorer and selecting Refresh from the context menu.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.