消息208,级别16,状态1,第62行无效的对象表名称

时间:2018-09-18 16:23:02

标签: sql-server

如何修复无效的对象表名称?

SELECT Proc_Code
FROM ClinicProcedures
WHERE Proc_Code NOT IN (SELECT Proc_Code FROM Patient)

2 个答案:

答案 0 :(得分:0)

Make sure you are in the correct database that has those objects. Most likely, you are in the master database.

Lookup the "USE {database}" command in the documentation. Alternatively, you can use the full naming convention of objects, and execute in any database:

SELECT Proc_Code FROM MyDatabase.myschema.ClinicProcedures WHERE Proc_Code NOT IN (SELECT Proc_Code FROM MyDatabase.myschema.Patient);

答案 1 :(得分:0)

此错误通常是由于数据库上下文不匹配而发生的。用户打开SSMS时,不会注意到默认数据库设置为master。您只需要将数据库上下文更改为当前对象的数据库即可。