在对象资源管理器中看不到创建的表 - Microsoft SQL Management Studio

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30354372/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 03:39:15  来源:igfitidea点击:

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

sqlsql-servertsql

提问by Aserian

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

使用 T-SQL 创建表 - 在对象资源管理器中看不到创建的表

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

但是,他使用的是“tempdb”,而我不是。

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.

编辑:下面的卡尔找到了解决方案!尽管在对象资源管理器上单击刷新 (F5) 不会更新数据库视图,但右键单击数据库并单击刷新会更新表。

回答by Karl Kieninger

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.

如果您在对象资源管理器中打开了表节点并且在运行 DDL 后不刷新,则会发生这种情况。令人讨厌的是,SSMS 在 DDL 后不会自动刷新资源管理器。可通过对象资源管理器中的右键单击上下文菜单进行刷新。

回答by youcantryreachingme

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 clausespecify 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?

关于FROM 子句Microsoft 文档指定FROM 后跟table_source,它是一个限定的table_or_view_name,它被定义为“是表或视图的名称”。然而,虽然我的 FROM 子句有效,但对象资源管理器中没有出现这样的表或视图名称(即使在刷新后)。这里发生了什么?

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.

在原始问题中,缺失表的 type_desc 值是 USER_TABLE,但在我的情况下,它显示了 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).

事实上,对象资源管理器中有另一个同义词文件夹 - 这是我找到我正在查询的“表”的地方。(如果 Microsoft 更新他们的文档以提及同义词名称也是与 FROM 子句一起使用的有效值这一事实,那将会很有帮助 - 至少在我的情况下,不经常使用同义词)。

回答by goran

I think you have to update table in DB. if you used visual studio you would easy do it. when you create table you can see button "update" in the left corner of window. enter image description here

我认为您必须更新数据库中的表。如果您使用visual studio,您会很容易做到。创建表格时,您可以在窗口左角看到“更新”按钮。 在此处输入图片说明