Brand new error - Invalid object name in T-SQL insert statement

  • I've been using SQL Server 2008 R2 for my web development for years and it's been working perfectly. But something strange happened last night that has stopped my development in my tracks.

    Here's some steps in the process:

    -- I create a new database from the Management Studio, named "BloggerTest" (dbo)

    -- I open a query window and paste in a CREATE table sql script for many tables, such as [dbo].[Blog], etc., with the "use [BloggerTest] GO" at the top

    -- I run the script and it runs without errors or messages, and I validate that the tables were created

    -- I open another query window and paste in another script for INSERT statements into some of the tables

    -- Before I run the script I notice that all the INSERT statement objects display the red squigglie lines under them. When I hover my cursor over the table name I get the message, "Invalid object name '[dbo].[Blog]'". The same squiggle is under all the column names also.

    Now here's the part that makes my head explode. I have another table with the same tables and it's a working application, the database is named "BlogApp".

    When I change the name of the "use" value from [BloggerTest] to [BlogApp] at the top of the INSERT sql script T-SQL query, all the red squigglie lines disappear!

    What the heck is going on? The script that is creating the tables for BloggerTest is the same script that created the tables for BlogApp, so why is this a problem? I've also created the database the exact same way.

    And to clarify some things so you don't have to ask questions about it:

    -- this is my local development laptop

    -- no one else is using this machine

    -- the tables exist, in both databases

    I've looked through these Forum posts for answers and have not found one. I've also scoured stackoverflow and other resources and haven't found and answer there either. Does anyone have an understanding of why this occurs, because at the moment, it's preventing me from creating new databases.

    Any help is appreciated. Thanks.

  • That is because your intellisense needs to be refreshed. ctrl+shift+r

    Wait a couple seconds and the "red squigglies" will go away.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Sean, thanks for the response, but that wasn't it.

    I'll keep working on it.

  • This will usually resolve for me if I shut down SSMS and re-open it.

    At any rate, the red squiggles are just for intellisense and the queries should continue to work for you.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • Did you execute a USE statement in SSMS? I have seen many times where that seems to totally confuse intellisense. If however, you use the combobox at the top it seems to keep intellisense in line.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Sean Lange (2/6/2014)


    Did you execute a USE statement in SSMS? I have seen many times where that seems to totally confuse intellisense. If however, you use the combobox at the top it seems to keep intellisense in line.

    I used both and everything and initially the red squiggles persisted, but as mentioned by another poster it did not interfere with it executing.

    But for some reason today when I opened SSMS and pasted in my Insert statements into a query window, the red squiggles were gone! I don't think I did anything different, but I like it anyway.

    Thanks to everyone who helped out with this.

  • Sometimes Intellisense won't work great and can become a PITA.

    I sure like it, but it can get some improvements and bug fixing.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply