sql server 无效的对象名称 - 但表列在 SSMS 表列表中

发布于 2024-08-03 02:22:14 字数 362 浏览 5 评论 0原文

我正在尝试为新创建的数据库创建一个存储过程。但是,SSMS 智能感知无法识别已创建的一半以上的表。

例如,在表下的左侧列中,我有一个表 dbo.Room,当我在新查询窗口中键入“dbo.”时,该表未列出,实际上 37 个表中只列出了 17 个。

我看不出智能感知列出的表格与未列出的表格之间没有任何区别。如果我手动输入 dbo.Room,它会带有下划线,错误为

无效的对象名称“dbo.Room”..

我在设置表格时是否遗漏了某些内容?

更新:我尝试刷新表列表(几次)

I am attempting to create a Stored Procedure for a newly created database. However the SSMS intellisense does not recognize more than half of the tables which have been created.

For example whilst in the left hand column under tables I have a table dbo.Room, when I type "dbo." in the new query window, that table is not listed, in fact only 17 out of 37 tables are listed.

I can see no difference between the tables listed by intellisense and those not. If I manually type dbo.Room, it is underlined, with an error of

Invalid Object Name 'dbo.Room'..

Have I missed something in setting up the tables?

UPDATE: I have tried refresh of the tables list (several times)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(21

不醒的梦 2024-08-10 02:22:14

尝试:

编辑 -> 智能感知 -> 刷新本地缓存
或使用热键
CTRL+SHIFT+R

这应该刷新 Intellisense 缓存的数据,以提供预输入支持和预执行错误检测。

注意:您的光标必须位于查询编辑器中才能看到 IntelliSense 菜单。

SSMS 菜单条目:编辑-智能感知-刷新本地缓存

Try:

Edit -> IntelliSense -> Refresh Local Cache
or use the hotkey
CTRL+SHIFT+R

This should refresh the data cached by Intellisense to provide typeahead support and pre-execution error detection.

NOTE: Your cursor must be in the query editor for the IntelliSense menu to be visible.

SSMS Menu Entry: Edit - Intellisense - Refresh Local Cache

缪败 2024-08-10 02:22:14

确保所选数据库是该表所在的数据库。我在 Master 上运行脚本。就我而言,我必须切换到 hr_db

输入图像描述这里

菜鸟错误,但是可以帮助别人。

Make sure that the selected DB is the one where the table is. I was running the Script on Master. In my case, I had to switch to hr_db.

enter image description here

Rookie mistake but, could help someone.

漆黑的白昼 2024-08-10 02:22:14

Ctrl + Shift + R 也会刷新 Management Studio 2008 中的智能感知。

Ctrl + Shift + R refreshes intellisense in management studio 2008 as well.

盛装女皇 2024-08-10 02:22:14

创建新的 SQL Server 对象后,新创建的对象不会在 IntelliSence 本地缓存中更新,因此,它会在该对象下方显示红线。因此,您只需刷新 SSMS IntelliSence 本地缓存,刷新后,IntelliSence 会自动将新创建的对象添加到缓存中,红线就会消失。试试这个

编辑->智能感知 ->刷新本地缓存Ctrl + Shift + R

在此处输入图像描述

once you create a new SQL Server object, your newly created object does not get updated in the IntelliSence Local Cache and due to this, it shows red line underneath that object. So you just need to refresh SSMS IntelliSence Local Cache and once you refresh it, IntelliSence will automatically add newly created object in the cache and the red line will disappear. try this

Edit -> IntelliSense -> Refresh Local Cache or Ctrl + Shift + R

enter image description here

静水深流 2024-08-10 02:22:14

就我而言,IntelliSense 缓存列出了完全不同的数据库的对象信息。如果我单击 SSMS 中的“新查询”按钮,它将打开对服务器上默认目录的查询,并且该查询编辑器将始终仅使用该数据库。刷新缓存并没有改变任何东西。重新启动 SSMS 没有改变任何东西。更改数据库并没有改变任何东西。

我最终通过右键单击我实际想要使用的数据库并从该上下文菜单中选择“新查询”来创建查询。 现在 SSMS 使用正确的对象进行 IntelliSense。

In my case, the IntelliSense cache was listing object information for an entirely different database. If I clicked the "New Query" button in SSMS, it would open a query to my default catalog on the server and that query editor would always only use that database. Refreshing the cache didn't change anything. Restarting SSMS didn't change anything. Changing the database didn't change anything.

I ended up creating a query by right-clicking on the database I actually wanted to use and choosing "New Query" from that context menu. Now SSMS uses the correct objects for IntelliSense.

甜味超标? 2024-08-10 02:22:14

您确定有问题的表存在吗?

您是否刷新了对象资源管理器中的表视图?这可以通过右键单击“tables”文件夹并按 F5 键来完成。

您可能还需要重新刷新 Intellisense 缓存。

这可以通过以下菜单路线来完成:编辑 ->智能感知 ->刷新本地缓存

Are you certain that the table in question exists?

Have you refreshed the table view in the Object Explorer? This can be done by right clicking the "tables" folder and pressing the F5 key.

You may also need to reresh the Intellisense cache.

This can be done by following the menu route: Edit -> IntelliSense -> Refresh Local Cache

假装爱人 2024-08-10 02:22:14

解决方案是:

  • 单击菜单“查询”,
  • 然后单击“更改数据库”。
  • 选择适当的数据库名称。

就是这样。

The solution is:

  • Click menu Query,
  • then click 'Change Database'.
  • Select your appropriate database name.

That's it.

她比我温柔 2024-08-10 02:22:14

当我使用这个语法问题时,与我有同样的问题解决了。

句法:

Use [YourDatabaseName]
Your Query Here

Same problem with me when I used this syntax problem solved.

Syntax:

Use [YourDatabaseName]
Your Query Here
一江春梦 2024-08-10 02:22:14

即使在将 SP3 安装到 SQL Server 2008 Enterprise 后,这仍然是一个“问题”。 Ctrl+Shift+R 就像每个人都说的那样为我解决了这个问题。

Even after installing SP3 to SQL Server 2008 Enterprise this is still an "issue." Ctrl+Shift+R like everyone has been saying solved this problem for me.

太傻旳人生 2024-08-10 02:22:14

在azure data studio中按“cmd+shift+p”并输入“intellisense”,然后您将看到刷新intellisense缓存的选项。

In azure data studio press "cmd+shift+p" and type "intellisense", then you will see an option to refresh intellisense cache.

相权↑美人 2024-08-10 02:22:14

我意识到这个问题已经得到解答,但是,我有一个不同的解决方案:

如果您正在编写一个脚本,在其中删除表而不重新创建它们,那么如果您稍后尝试引用它们,这些表将显示为丢失。

注意:对于不断运行的脚本来说,这种情况不会发生,但有时使用带有查询的脚本来重新引用比每次都键入查询更容易。

I realize this question has already been answered, however, I had a different solution:

If you are writing a script where you drop the tables without recreating them, those tables will show as missing if you try to reference them later on.

Note: This isn't going to happen with a script that is constantly ran, but sometimes it's easier to have a script with queries to reerence than to type them everytime.

往事随风而去 2024-08-10 02:22:14

SSMS 2016 已解决。

有类似的问题,但 Intellisense 不在编辑菜单中。

似乎解决这个问题的办法是打开和关闭 Intellisens,右键单击 SQL 编辑器,然后单击“Intellisense Enabled”。再次右键单击“Intellisense Enabled”将其重新打开。 Ctr Q,我也这样做。

这解决了问题,而且我知道在“编辑”菜单上获得“智能感知”。

Solved for SSMS 2016.

Had a similar problem, but Intellisense was not in Edit menu.

What seemed to fix it was turning Intellisens on and off, right click on the SQL editor and click 'Intellisense Enabled'. Right click again on 'Intellisense Enabled' to turn it back on again. Ctr Q, I also does this.

This solved the problem, and also I know get the Intellisense on the Edit menu.

锦欢 2024-08-10 02:22:14

您是否尝试过:右键单击数据库,然后单击“刷新”

did you try: right click the database, and click "refresh"

游魂 2024-08-10 02:22:14

我只需关闭 SMSS 并重新打开它即可。我尝试过刷新本地缓存,但没有成功。

I just had to close SMSS and reopen it. I tried Refresh Local Cache and that didn't work.

诗化ㄋ丶相逢 2024-08-10 02:22:14

我遇到了以下问题:
ODBC 和 ODBC 中的 SQL Server 身份验证

Firedac 连接

解决方​​案:
我必须将 Param MetaDefSchema 设置为 sqlserver 用户名:
FDConnection1.Params.AddPair('MetaDefSchema', self.FDConnection1.Params.UserName);

维基文档说:
MetaDefSchema=默认模式名称。设计时间代码>>排除<< !!对象 SQL-Server-Authenticatoinname 中的架构名称(如果它等于 MetaDefSchema)。

如果没有设置,自动编码器会创建:
数据库名.用户名.表名->无效的对象名称

将 MetaDefSchema 设置为 sqlserver-username :
dbname.表名->有效!

另请参阅 embarcadero-doc:
http://docwiki.embarcadero.com/RADStudio/Rio/en/Connect_to_Microsoft_SQL_Server_ (FireDAC)

希望,它对其他人有帮助..

问候,Lutz

I ran into the problem with :
ODBC and SQL-Server-Authentication in ODBC
and
Firedac-Connection

Solution :
I had to set the Param MetaDefSchema to sqlserver username :
FDConnection1.Params.AddPair('MetaDefSchema', self.FDConnection1.Params.UserName);

The wikidoc sais :
MetaDefSchema=Default schema name. The Design time code >>excludes<< !! the schema name from the object SQL-Server-Authenticatoinname if it is equal to MetaDefSchema.

without setting, the automatic coder creates :
dbname.username.tablename -> invalid object name

With setting MetaDefSchema to sqlserver-username :
dbname.tablename -> works !

See also the embarcadero-doc at :
http://docwiki.embarcadero.com/RADStudio/Rio/en/Connect_to_Microsoft_SQL_Server_(FireDAC)

Hope, it helps someone else..

regards, Lutz

呆头 2024-08-10 02:22:14

不要忘记在编写模型后创建迁移

Don't forget to create your migrations after writing the models

橘寄 2024-08-10 02:22:14

对我来说,我已经重命名

[Database_LS].[schema].[TableView]

[Database_LS].[Database].[schema].[TableView]

For me I had rename from

[Database_LS].[schema].[TableView]

to

[Database_LS].[Database].[schema].[TableView]
哀由 2024-08-10 02:22:14

我当时在 Azure SQL Server 上工作。为了存储数据,我使用了表值参数
就像

DECLARE @INTERMEDIATE_TABLE3 TABLE { 
     x int;
 }

我发现在查询中写入错误一样

SELECT
    *
FROM 
    [@INTERMEDIATE_TABLE3]
WHERE 
    [@INTERMEDIATE_TABLE3].[ConsentDefinitionId] = 3

,在查询列时,可以用大括号将其括起来,例如 [@INTERMEDIATE_TABLE3].[ConsentDefinitionId] 但是当仅引用表值参数时,应该有没有参数。所以它应该用作 @INTERMEDIATE_TABLE3

所以现在的代码必须更改为

SELECT
    *
FROM 
    @INTERMEDIATE_TABLE3
WHERE 
    [@INTERMEDIATE_TABLE3].[ConsentDefinitionId] = 3

I was working on Azure SQL Server. For storing the data I used table values param
like

DECLARE @INTERMEDIATE_TABLE3 TABLE { 
     x int;
 }

I discovered the error in writing on the queries

SELECT
    *
FROM 
    [@INTERMEDIATE_TABLE3]
WHERE 
    [@INTERMEDIATE_TABLE3].[ConsentDefinitionId] = 3

While querying the columns, it's okay to wrap it with braces like [@INTERMEDIATE_TABLE3].[ConsentDefinitionId] but when referring to just the table valued param, there should be no params. So it should be used as @INTERMEDIATE_TABLE3

So the code now must be changed to

SELECT
    *
FROM 
    @INTERMEDIATE_TABLE3
WHERE 
    [@INTERMEDIATE_TABLE3].[ConsentDefinitionId] = 3
幸福%小乖 2024-08-10 02:22:14

就我而言,我试图更改数据库中不存在的存储过程,在创建它并刷新本地缓存后,它起作用了

In my case, I was trying to alter a stored procedure that didn't exist in the database, after creating it and refreshing local cache, it worked

捎一片雪花 2024-08-10 02:22:14

就我而言,解决方案变成了更改我尝试查询它的用户/角色,因为我的角色无权访问它。

附带说明:通过 cdc 进行复制期间遇到了错误消息。

In my case, the solution turned to be changing the user/role that I was trying to query it with, because my role didn't have access to it.

As a side note: the error message was encountered during the replication through cdc.

燃情 2024-08-10 02:22:14

确保您运行的是 CREATE PROCEDURE 查询,而不是 ALTER PROCEDURE 查询。在复制/粘贴的情况下,这种情况在我身上发生过多次。

当您尝试ALTER一个不存在的存储过程时,您最终会遇到与该提问者遇到的相同错误。

简单的例子,如下:

右:

CREATE PROCEDURE [dbo].[ReportWidgetGetSubmissionsForExport]

AS
BEGIN

SELECT * 
FROM [dbo].ReportWidgets
ORDER BY CreatedDate

END

错误:

ALTER PROCEDURE [dbo].[ReportWidgetGetSubmissionsForExport]

AS
开始

SELECT * 
FROM [dbo].ReportWidgets
ORDER BY CreatedDate

结束

Make sure you're running a CREATE PROCEDURE query as opposed to an ALTER PROCEDURE query. This has happened to me multiple times in copy/paste situations.

When you try to ALTER a Stored Procedure that doesn't exist, you end up with the same error this question asker encountered.

Simple example, below:

Right:

CREATE PROCEDURE [dbo].[ReportWidgetGetSubmissionsForExport]

AS
BEGIN

SELECT * 
FROM [dbo].ReportWidgets
ORDER BY CreatedDate

END

Wrong:

ALTER PROCEDURE [dbo].[ReportWidgetGetSubmissionsForExport]

AS
BEGIN

SELECT * 
FROM [dbo].ReportWidgets
ORDER BY CreatedDate

END

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文