sql server invalid object name - but tables are listed in SSMS tables list - sql-server

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)

Try:
Edit -> IntelliSense -> Refresh Local Cache
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.

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.
Rookie mistake but, could help someone.

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

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

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.

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

The solution is:
Click menu Query,
then click 'Change Database'.
Select your appropriate database name.
That's it.

Same problem with me when I used this syntax problem solved.
Syntax:
Use [YourDatabaseName]
Your Query Here

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.

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

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

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.

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.

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

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

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

For me I had rename from
[Database_LS].[schema].[TableView]
to
[Database_LS].[Database].[schema].[TableView]

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

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

Related

why sql server 2008 intellisense showing invalid object name

while typing database name intellisense not showing database. after manually typed its showing invalid object name
e.g
select * from tbl_customer
query executed successfully...
whats wrong ?
In Management Studio, go to "Edit" and then at the bottom you will see "IntelliSense".
There you will see "Refresh Local Cache".
You can also hit Ctrl+Shift+R as a keyboard shortcut.
This happens if you add an object, such as a table after the environment is already loaded.
After you refresh the local cache, the red underline will be gone.
Elad.
Have you just created the table? The SQL intellisense does not shows newly created objects because the cache of the intellisense has not been updated. Press ' Cntrl + Shift + R ' and the cache will be updated and your table will be seen in it and also it wont show invalid object name

Refreshing a table in SQL server management studio

I have opened a table in SQL server management studio express.
How do I update it?
As changes made outside the studio application do not show unless I close and reopen the table. Surely there must be a better way of doing this?
In SSMS (SQL Server Management Studio) press Ctrl + R
In Visual Studio Press Shift + Alt + R
I am not sure if I understand exactly what you want, but if you want to see the changes, the query that loaded the table has to be re-executed. You can do this by clicking on "Execute SQL" (or selecting it from the context menu).
Depending on what you mean with "opening the table" (select top x rows, edit top x rows, etc ) you also might try to hit F5 (works for "Select TOP x Rows") - which simply executes the previous statement.
As a rule, manually editing data in SQL Server is a bad practice.
It's not repeatable. Anything you do is limited to your window and once it's gone it's gone.
It's easy to make mistakes. Click the wrong cell, fat-finger a decimal point, etc.
A much better solution is to create and save insert or update scripts. These are editable, reviewable, and rerunnable.
If you need to recreate your database or replicate something now, you need to manually type in all the same values you typed in before. If you script it out, you just run the script and can have the same data as many times as you can hit F5.
It is much easier if you just create a query referencing on that table. Then create select statement giving all rows from that table.

How can I stop SQL Server Management Studio replacing 'SELECT *' with the column list?

SQL Server Mgmt Studio is driving me crazy.
If I create a view and SELECT '*' from a table, it's all OK and I can save the view.
Looking at the SQL for the view (eg.by scripting a CREATE) reveals that the 'SELECT *' really is saved to the view's SQL.
But as soon as I reopen the view using the GUI (right click > modify), SELECT * is replaced with a column list of all the columns in the table.
How can I stop Management Studio from doing this ? I want my 'SELECT *' to remain just that.
Perhaps it's just the difficulty of googling 'SELECT *' that prevented me from finding anything remotely relevant to this (i did put it in double quotes).
Please, I am highly experienced in Transact-SQL, so please DON'T give me a lecture on why I shouldn't be using SELECT *. I know all the pros and cons and I do use it at times. It's a language feature, and like all language features can be used for good or evil (I emphatically do NOT agree that it is never appropriate to use it).
Edit: I'm giving Marc the answer, since it seems it is not possible to turn this behaviour off. Problem is considered closed. I note that Enterprise Manager did no similar thing.
The workaround is to either edit SQL as text, or go to a product other than Managment Studio. Or constantly edit out the column list and replace the * every time you edit a view. Sigh.
When SQL Server Mgmt Studio creates a view, I assume they're expanding the * to the complete list of columns that are present in the underlying table(s) at that particular time exactly for this reason: what if one of the underlying tables changes? Do you want the new columns to just simply show up in every view that references that table?? Seriously???
I think Microsoft tries to impmenent the "element of least surprise" here - your view will contain those columns that are present at the time the view gets created - and it stays that way, unless you explicitly and knowingly change that.
I for one wouldn't want to have my views suddenly having more columns than before, when an underlying table changes..... do you??
And I don't think there's any setting in Mgmt Studio to turn this behavior off, sorry.
Don't use the GUI editor.
Instead use the T-SQL editor. You get this by selecting "Script View As" -> "ALTER to" -> "New Query Window" from the right-click menu.
Try either of these: they are alternatives to using the GUI and can be setup as snippets with keyboard shortcuts:
select view_definition
from information_schema.views
where table_name = 'viewname'
or
exec sp_helptext 'viewname'
The results will retain the "select *". (Tested)

Data has always changed(SQL Server Management Studio)

I am using SQL Server Management studio and keep getting the same error, and the only way to get rid of it(usually) is to reset the SQL server(which is very annoying, and sometimes impossible from my remote machine)
When I add a row to a table, and then I goto "Edit Top 200 Rows" it all displays and acts fine, and I go to a field I want to change. Then I change something like 0 -> 1 and then I get a nice friendly popup saying "Data has changed since the Results Pane was last retrieved... Optimistic Concurrency Control Error" If from here I say "Yes to commit changes to database anyway" I get "No row updated... The updated row has changed or been deleted since data was last retrieved"
It's a very annoying little thing, cause I don't like having to look up RIDs and then make an update statement(and possibly having to worry about escaping 's by hand)
Is there some way to turn this concurrency checking off or something? I know the row wasn't updated or anything, and I tried completely closing Sql Server Management Studio and reopening to no avail, and also tried refreshing the result pane, or refreshing the column view. Nothing gets rid of this error, but if I do a "update ... set ...=..." then it works, so I'm not really having any concurrency error..
I had exactly the same problem. It looks like this article was pretty good at solving it. Seems all sorts of buggy things in some versions.
See: You may receive an error message when you try to use SQL Server Management Studio to update a row of a table in SQL Server 2005.
The table contains one or more columns of the text or ntext data type. The value of one of these columns contains the following characters.
Percent sign (%)
Underscore (_)
Left bracket ([)
The table does not contain a primary key.
http://social.msdn.microsoft.com/Forums/en-US/sqldatabaseengine/thread/7bf48a75-58a0-41d7-b514-b804a49ae8ff/
it seems to be a bug in SSMS I don't think I have over 4000 characters, but I can confirm this only happens on rows that have more data than others.. there seems to be some abritary limit that I can't quite put my finger on..
So, plainly SSMS is complete crap. I'll be looking for a new SQL manager..
You shouldn't edit a table directly from the table view.. you should use an UPDATE sql command.

Edit data from result grid

I would like to edit data directly from result grid in ssms. eg:
When I execute SELECT TOP 10 * FROM some_table, I want to edit data directly from result grid.
I don't want to open some_table and edit from there.
I know that result grid is read-only, but maybe someone written addin for it.
You can't edit the data from within the result grid. You'd have to go via the "open table" route if you want to edit the data manually instead of using UPDATE/INSERT SQL statements.
Is there a reason you specifically want to use the result grid instead?
You can specify a query when you go via open table to limit the results if that's your reason? There's a "Show SQL Pane" button in the top toolbar you need to select (square box with "SQL" written in it).
I have very large database (70+ GB) with so many tables.
I'm using Red Gate's SQL refactor for intellisense and few other things.
It's so boring to type in update sql statements every time I need to change single field.
It also takes some time to find that table in the Object explorer.
Intellisense doesn't work when I use "Show SQL Pane".
I'm new to SQL Server and have used the Oracle product 'PL/SQL developer' by All Round Automations at a previous job... It would allow you to do a SELECT in the query window and then simply add "FOR UPDATE" to the end of your refined SQL SELECT and 'ta-da' you can now edit the results in a nice grid. No need to Open Table View, click the SQL button, paste in the SQL you you have been working on and then hit execute ;)
EMS SQL Manager for SQL Server allows to update data directly inside a results grid.
This tool is boring for typing new requests (poor intellisense and error management) but fine for this. I always have the two tools opened.
If you right click on the table and choose edit top 200 records, it produces a result screen with an query.
Add to this your query and then you can edit the records in the result screen.
Also you can change the 200 to a number you want (2000).
The "results" pane is not just results.
Results in text
Assorted time and IO statistics
Estimated and actual execution plans
Row counts, Error messages, PRINT output
etc
This is why they are separate.
Feel free to write your own add-in :-) Or here
SQL Server ISN'T Access!
When you run a query and get the results - thats exactly what you are doing, reading the data, not opening the table for editing. Can you imagine the necessary transactional control around allowing the results window to be edited? The locking would probably grind SQL to a halt - I hope no-one ever writes that kind of add-in!

Resources