Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't see created tables in Object Explorer - Microsoft SQL Management Studio

I am trying to create some tables within a database, however the tables are not appearing in my object explorer view.

my code is as follows:

use testDB
GO

create table dbo.teacher (id varchar(5), name varchar(24));
insert into teacher values ('dm112', 'Magro, Deirdre');
insert into teacher values ('je232', 'Elkner, Jeff');
insert into teacher values ('cm147', 'Meyers, Chris');
insert into teacher values ('kr387', 'Reed, Kevin');


create table dbo.course (
    number varchar(6),
    name varchar(24),
    credits int,
    teacherid varchar(6) 
);
insert into course values ('SDV100', 'College Success Skills', 1, 'dm112');
insert into course values ('ITD110', 'Web Page Design I', 3, 'je232');
insert into course values ('ITP100', 'Software Design', 3, 'je232');
insert into course values ('ITD132', 'Structured Query Language', 3, 'cm147');
insert into course values ('ITP140', 'Client Side Scripting', 4, 'kr378');
insert into course values ('ITP225', 'Web Scripting Languages', 4, 'kr387');


create table dbo.student (id varchar(3), name varchar(24));
insert into student values ('411', 'Perez, Gustavo');
insert into student values ('412', 'Rucker, Imani');
insert into student values ('413', 'Gonzalez, Alexis');
insert into student values ('414', 'Melgar, Lidia');


create table dbo.enrolled (studentId varchar(3), courseNumber varchar(6));
insert into enrolled values ('411', 'SDV100');
insert into enrolled values ('411', 'ITD132');
insert into enrolled values ('411', 'ITP140');
insert into enrolled values ('412', 'ITP100');
insert into enrolled values ('412', 'ITP14p');
insert into enrolled values ('412', 'ITP225');
insert into enrolled values ('413', 'ITD132');
insert into enrolled values ('413', 'ITP225');
insert into enrolled values ('414', 'SDV100');
insert into enrolled values ('414', 'ITD110');

I looked this up before posting and found this exact question:

Creating table with T-SQL - can't see created tables in Object explorer

However, he was using "tempdb", which I am not.

I ran the query

select name, type_desc from testDB.sys.objects

which returned:

name          type_desc
---------------------------
...
teacher       USER_TABLE
course        USER_TABLE 
student       USER_TABLE
enrolled      USER_TABLE
...

I can modify, select, drop, etc. on these tables, but I cannot see them. Am I missing something? Another question brought up the prospect of "test" and "production"? They didn't go into much detail and google did not help me

:(

Thank you for any help you can offer.

Edit: Karl below found the solution! Although clicking refresh (F5) on the object explorer does not update the database view, right clicking on the database and clicking refresh updates the tables.

like image 632
Aserian Avatar asked May 20 '15 15:05

Aserian


People also ask

Why are my tables not showing in SQL?

For those using SQL Server Management Studio 2016 you simply need to hit 'F5' or go to 'View > Refresh' and your recently added tables should appear.

How do I View tables in Object Explorer?

First, you need to enable Object Explorer Details by pressing F7 button or choosing following option from the menu: View > Object Explorer Details. Now, select Tables item from the database you want to search. List of tables should be visible on the right side.

How do I show tables in SQL Server Management Studio?

To show table properties in the Properties window. In Object Explorer, select the table for which you want to show properties. Right-click the table and choose Properties from the shortcut menu. For more information, see Table Properties - SSMS.


2 Answers

This would happen if you have the tables node open in object explorer and don't refresh after running your DDL. It is annoying that SSMS doesn't autorefresh explorer after DDL. Refresh is available via the right-click context menu in object explorer.

like image 172
Karl Kieninger Avatar answered Oct 19 '22 08:10

Karl Kieninger


I had a scenario in which refreshing the folders in Object Explorer did not lead to my missing table appearing in either of the Tables or Views folders. Like the original post, I am able to query the table - but not find it in Object Explorer.

The Microsoft docs on the FROM clause specify that FROM is followed by table_source which is a qualified table_or_view_name which is defined as "Is the name of a table or view". Yet while my FROM clause works, no such table or view name appears in Object Explorer (even after refresh). What's going on here?

The original question had the following query:

select name, type_desc from testDB.sys.objects

which simplifies to:

select name, type_desc from sys.objects;

and this gave me the answer to my scenario, which differed from the original question.

In the original question the missing table's type_desc value was USER_TABLE, but in my case it showed SYNONYM.

There is, in fact, another folder in Object Explorer for Synonyms - and this is where I found the "table" I was querying. (It would be helpful if Microsoft updated their doc to mention the fact that a Synonym name is also a valid value for use with the FROM clause - at least in my case, synonyms are not frequently used).

like image 1
youcantryreachingme Avatar answered Oct 19 '22 09:10

youcantryreachingme