Yesterday, in SQL Server Management Studio (SSMS) (v17.6) I could write and execute:
select * from MyTable;
Today, I now must write:
Select * from myDbName.dbo.MyTable;
However, the old syntax will recognize that the table is there and pull back the headers, but no content. Also, the intellisense with the older syntax.
Yet, in my VB code, I can still use the initial statement shown above.
Why? And, how do I change it back?
You are likely connected to another database on the instance. This commonly happens when the default database for the login isn't set to something explicitly. It defaults the the master database. You'll need to change it in the drop down for intellisense to pick up your table names, and for you to not have to fully qualify the server.database.schema.table.
Also, in the bottom right of your query window, make sure the query window which you are executing your query from is actually connected to the correct database. Since you aren't getting results back, I'd bet that you are also not connected to the correct database when you run your query, but an older or developmental database (where the data is different).
Related
I have a server called ERP-SERVER, and a server called SQLDEV-SERVER.
They both have a blob instance, but we never copy over the complete blob to the SQLDEV-SERVER as that would be too much data.
So when trying to access a file on our test server, it should first check if that file exists on the SQLDEV-SERVER, and if not check if the file exists on the ERP-SERVER. This is where it goes wrong. This piece of code (SQL) used to work but somewhere along the way it broke. I have narrowed it down to the inter database query just returning completely different results.
so for instance i run this query on the ERP-SERVER instance in SQL management studio:
SELECT count(*)
FROM [erp-server].[Extranet_Blob].[dbo].[FileStorBlob]
this returns 223221 results.
When i run the same query on the SQLDEV-SERVER instance in SQL management studio, it returns 313 results.
It points to the same server and same database, yet a completely different count, which is why it is also not returning the files from the live environment when it is not found on the dev environment.
Any pointers as to where this problem could be situated?
Look very carefully at your linked server definition. When you are running the query on SQLDEV-SERVER it is using the linked server definition of that name rather than necessarily the ERP_Server. Is it possible that someone has fiddled with the definition?
I try to create a pretty complex database on ms Access 2013, so I wanted to type it directly in SQL. It has no errors, as other DBMS can fully build the database from the script I wrote (for example, phpmyadmin imports it with no difficulty).
On this tutorial, it is showed how to write a SQL query in order to build tables. I thought this way matched well with my goal as I could copy-paste my script in the query and run it to create the whole thing.
But when I tried to open/double-click on the query a pop-up appears saying "Select data source", waiting for me to select an ODBC, either from a file or a host, before continuing and executing the query.
I tried other types of queries (creating only one table at time, trying on a blank file, or even SELECT * FROM *), bt this message keeps showing up and I really don't know how to deal with it as I don't want to connect to anything but the infile database.
Does anyone got a hint about what to do in this case?
Or, even better, how could Access import my SQL script in order to create the database?
You should configure the database connection in the ODBC and check whether the connection is established or not. Once the connection is established, you can run the query to fetch the data or create tables as per your requirement.
I am a new database intern working with a access front end and SQL server backend database. The database was custom made for the company. One of my assignments is to take scripts and apply them to make four new tables. I am aware that I need to make a new query for each new table but I don't know if I should make the query in SQL server management studio or the frontend access program. I have tried copying and pasting the given scripts into a new query in access but I get an error message "invalid SQL statement expected 'DELETE', 'INSERT'...". I decided to try to break done the program a little bit and tested the first line
IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id =OBJECT_ID(N'[dbo] .[FK_tblInstrumentInterfaceLog_tlkpInstrument]') AND parent_object_id = OBJECT_ID(N'[dbo].[tblInstrumentInterfaceLog]'))
but the same error message keeps popping up. I even tried just SELECT * FROM sys.foreign_keys, and I got the error message "could not find file...". I am very much a beginner and any guidance would be appreciated.Basically am I supposed to be applying these scripts the server SQL database or on the front end access program?
Are you using a pass-through query? i.e. not just a select query. Access needs to know where to send the query and since you are using TSQL not Access SQL this needs to be executed on the server.
Normally when you query a linked table the information of how to get the data (the connection string) is tied to the table. But for this kind of query you'll probably need to tell Access explicitly. Unless you are using an ADP/ADE, then the connection info travels with the program not the table.
As a general rule, you use SQL management studio (SSMS) to create and run those scripts. So the general accepted approach here is such scripts will not be placed in the front end. As noted such scripts if for some reason must be placed in the front end, then you have to create them as pass-though, but EVEN in this case you want to use the SSMS to create such quires.
So the answer here is you create the new scripts and make table queries in the back end, or in this case using the SQL server management studio.
The syntax checking, query editor etc. in recent versions of SSMS now has auto-complete etc. and you can test/write/update those scripts in SQL server. Once you have such a query or even several of them, then the resulting “several” statements can be pasted into a front end query that been created as pass-though. If you do not use a pass-though query, then you are creating and using and assuming client side SQL (JET (now called ACE)).
The client side has it own version of SQL syntax, and it is NOT 100% compatible with the SERVER SIDE. If you writing SQL in the client that is NOT pass though, then you using a linked table to SQL server. These linked tables thus will use local (JET/ACE) based SQL queries. The ODBC driver thus translates this SQL into server side compatible syntax. However the JET/ACE sql syntax is very limited when compared to SQL server and no server side commands exist in this SQL syntax for the client data engine (JET/ACE)
So for many quires, you will and can simply build such queries using the Access query builder.
However for SQL that needs to run 100% server side then such quires has to be setup as pass-though and are in most cased built + tested using SSMS.
When I am composing a stored procedure in SSMS 2012, I am not getting intellisense.
I am connected using ssms 2012 to a remote instance of sql server 2012. But i am not getting the wonderful intellisense that I was used to in ssms 2008 R2. It doesn't work for any entity type whether table or column.
The intellisense does work if I am doing standalone queries
At least in the case of tables, after i have finished typing if the table is non-existent it complains. But in the case of columns, it says nothing.
So the issue is two fold
There is no intellisense to tell me the possible column names/table names as I am typing
After typing is complete, even if the column name is wrong, the ssms IDE doesnt show any squigglies to tell me i am wrong. I only find if i actually execute the query or try to create a stored proc out of it.
sometimes, it seems like Microsoft operates with the principle of greatest possible surprise.
If you hit Ctrl+shift+R, things should work.
You can also get to this by doing Edit->Intellisense->Refresh local cache.
Hope it helps!
In SQL Server 2008 R2 Management Studio, if I right-click on an object inside a specific database and choose "Select top 1000 rows ..", the database connection for the query window always opens on 'master' while the table name is fully qualified as [database].[dbo].[table]. This makes it impossible to jump in and tweak out this query and insert joins, etc., to the statement without also fully-qualifying everything I add, or add a USE statement, or select the database from the drop-down menu.
Is there a setting or something that will make query windows open with a database connection of the selected object browser's database rather than connect to 'master', and not fully qualify the object's database in the query text? I realize that I can register my SQL connection to default to my database, but we actually go through multiple new databases every week--in a given month I will have touched tens of databases--so it would be difficult to manage multiple database registrations. I would rather it if SSMS just connected to the specified database. Possible and straightforward?
If you are going in via Win Auth, are in a group, are using SA or some other userid, or are in a situation where changing your login is not really the solution, AND if all you wish to do is default to a database in the query editor:
In an existing open query editor, right-click, select Connection, Change Connection.
Click the Options button to expand the options.
In the Connection Properties tab, select the database you wish to connect to.
SSMS will remember your selection for that server. You may have to repeat for other servers, but it does remedy having a default database other than master.
There is no such setting for the SELECT TOP command, but you may be able to do this by changing the default database for your login. This is tedious if you're doing this often for various databases (much like changing the registrations, as I just noticed you already outlined).
Instead of using SELECT TOP 1000 (which in addition to not putting you in the right database context, also puts a TOP in that I assume you're just going to remove as well), you should right-click the table and choose Script Table as > SELECT to > New Query Window. This puts the context in the right DB, adds a USE command, doesn't have a TOP and doesn't database-prefix the table name.
If you want query window connects to some database by default, in SSMS go to the Security -> Logins, select the login that you use to connect to this server, and loock at the properties window. In page 'general' change the default database from 'master' to database you want to connect.
You could just put a USE [database name] at the top of the query window prior to executing a query. You do not need to fully qualify the database names if you do this. If you generate any scripts and version control them, this is a good practice to put at the top anyway. It at least prevents executing the script erroneously against the wrong database (say creation of a stored procedure).
USE MySpecialDatabase
GO
SELECT * FROM MySpecialTable