question

ChaitanyaKiranBuduguru-7986 avatar image
0 Votes"
ChaitanyaKiranBuduguru-7986 asked Dayneko-7677 published

"Invalid object name" error.

I have a table that exists in the database. When I run "Select * from tablename" , it executes successfully .But when I am running "Insert into tablename values()", it is giving me the below error:

"Invalid object name tablename"

The table exists in the database, but getting "Invalid object name" error.

For Select query, it executes successfully. But for Insert query it is giving "Invalid object name" error.

Please help on resolving this issue.

sql-server-general
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Please post a screenshot that demonstrates the issue. Else this will only be a guessing game.

0 Votes 0 ·

Can you insert some rows manually by right-clicking the table in Object Explorer, then “Edit Top 200 Rows”?

0 Votes 0 ·

I tried manually sir, but it is giving me the same error.

0 Votes 0 ·
Viorel-1 avatar image
0 Votes"
Viorel-1 answered ChaitanyaKiranBuduguru-7986 commented

Maybe start your scripts in Management Studio with a statement like 'use MyDatabase' statement, to make sure that you deal with the right database.

Also make sure that the names are typed correctly. If required, specify the schema, for example: 'insert into dbo.tablename...'.

Probably sometimes you must also have the required access rights.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I I have already used 'use databasename'.I checked and the names are typed correctly. I tried with schema also, but it did not work. Permissions are set properly.

0 Votes 0 ·
DanGuzman avatar image
0 Votes"
DanGuzman answered DanGuzman commented

It seems you are referring to an IntelliSense error in SSMS. Press SHIFT+CTRL+R to refresh the IntelliSense cache and the error in the SSMS query window should go away.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Dan,

Tried and giving same error


103692-inserterror.jpg



!


0 Votes 0 ·
inserterror.jpg (50.3 KiB)
SeeyaXi-msft avatar image
0 Votes"
SeeyaXi-msft answered ErlandSommarskog commented

Hi @ChaitanyaKiranBuduguru-7986,

I have compiled two solutions:
1.Click menu Query, then click 'Change Database'. Select your appropriate database name.
Also, you can run this:
Use [YourDatabaseName]
Then, It can be debugged like this:

 insert into [database name].[dbo].[table name] values('value1','value2',……)
 go

2.Once a new SQL Server object is created, the newly created object will not be updated in the IntelliSence Local Cache.
You may also need to refresh the IntelliSense cache.
This can be done by following the menu route: Edit -> IntelliSense -> Refresh Local Cache OR pressing Ctrl+Shift+R

Best regards,
Seeya


If the response is helpful, please click "Accept Answer" and upvote it, as this could help other community members looking for similar queries.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 18
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,
Tried but still getting same error103704-inserterror.jpg


0 Votes 0 ·
inserterror.jpg (50.3 KiB)
Viorel-1 avatar image Viorel-1 ChaitanyaKiranBuduguru-7986 ·

Show the image of SELECT that works.

0 Votes 0 ·
Viorel-1 avatar image Viorel-1 ChaitanyaKiranBuduguru-7986 ·

What suggestions did you try? For example, did you start the script with a valid use MyDatabase statement? From the images it is not clear if the recommendations were considered.

0 Votes 0 ·
SeeyaXi-msft avatar image SeeyaXi-msft ChaitanyaKiranBuduguru-7986 ·

Hi @ChaitanyaKiranBuduguru-7986,

Is your IntelliSense enabled? From the screenshot, I can see that IntelliSense is not turned on. Make sure it is enabled, then refreshing the IntelliSense cache can work.
This can be done by following: Query->IntelliSense Enabled
103744-s1.png
Note: If it is enabled, there will be a yellow frame outside it and a red wavy line under the invalid object.

Best regards,
Seeya


Did the reply could help you? If the response helped, do "Accept Answer". If it is not work, please let us know the progress. By doing so, it will benefit all community members who are having this similar issue. Your contribution is highly appreciated.


0 Votes 0 ·
s1.png (26.8 KiB)

I can see intellisense enabled. 103761-intellisense.jpg


0 Votes 0 ·
intellisense.jpg (63.4 KiB)
Show more comments
OlafHelper-2800 avatar image
0 Votes"
OlafHelper-2800 answered ChaitanyaKiranBuduguru-7986 commented

The table name works with SELECT but not with INSERT.
So my guess: There is a faulty trigger on the table causing the error.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

There is no trigger on that table

0 Votes 0 ·
SeeyaXi-msft avatar image
1 Vote"
SeeyaXi-msft answered SeeyaXi-msft commented

Hi @ChaitanyaKiranBuduguru-7986,

First of all, like the trigger problem mentioned by Olaf, you can check it with the following statement:

 use [DatabaseName]
 go
 select * from sysobjects where xtype='TR'

Secondly, I suspect it is the problem of the owner of the table.
You can try adding ‘’dbo‘’ between the database and the table name.

Best regards,
Seeya


If the response is helpful, please click "Accept Answer" and upvote it, as this could help other community members looking for similar queries.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Seeya,

I checked, and there is no trigger on the table. Also, I tried adding dbo, but its still failing. Please help to resolve this issue

0 Votes 0 ·
SeeyaXi-msft avatar image SeeyaXi-msft ChaitanyaKiranBuduguru-7986 ·

Hi ChaitanyaKiranBuduguru-7986,

Added what ErlandSommarskog said,Dynamic SQL creates a new "context" where variables and tables in the calling code block may not be available.
It is not at all surprising that inserted is not available. The simple solution is not to use dynamic SQL.

0 Votes 0 ·
ScottDonalson-0967 avatar image
0 Votes"
ScottDonalson-0967 answered

I was having that problem when I was connected to two separate servers. I had to disconnect specifically from each one, restart SSMS, and then it worked. I guess make sure you are only connected to 1 server.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Dayneko-7677 avatar image
0 Votes"
Dayneko-7677 answered Dayneko-7677 published

I also encountered this problem, and as it turned out, after updating the DEV stand. The table is gone, but I have it displayed. It was necessary to restart the DBMS

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.