So I have two Access databases, let's call them myDatabase and anotherDatabase. In anotherDatabase there is a crosstab query. I want to get the results that this query produces into myDatabase without making ANY modifications to anotherDatabase or the query itself. I want myDatabase to be enitrely self-sufficient in the sense that the databases it interacts with will not have to be modified.
Could anyone give me advice on how to approach this?
Linking external tables is limited to external tables and won't allow you to get data from queries in another db.
One solution for external queries is to create a local query using the IN predicate:
SELECT * FROM myQuery IN 'c:\test\otherdb.mdb'
Use the Linked Table Manager to link the tables in anotherDatabase to myDatabase. Then you can have the query for anotherDatabase in myDatabase and just use that.
In the External Data tab (in myDatabase), click the button that says Import From Access. Except, instead of importing the table, click the radio button that says "Link to the data source by creating a linked table". Just follow the wizard and you should be all set.
You only need to link the tables that you require from your query. Another option would be to write some vba code in myDatabase that instantiates a connection to anotherDatabase and queries it, but I think that just linking the tables is a better solution with less hassle
Related
I am very new to SQL, MS Access & PostgreSQL. So this might be a very silly question but somehow I can't figure it out. I'm trying to run SQL queries in access and my data is in a PostgreSQL database table which was linked to access by my colleague earlier. When I make this simple query why do I get an error that the table doesn't exist? Is the syntax different for linked database tables? Or is the link not yet established?
You have created a Pass-Through query. This query is executed on the server, not in Access, so you need to use the original table names from the PostgreSQL database.
So it's not FROM public_tb_change but FROM tb_change.
Or maybe FROM public.tb_change, if public isn't the default schema.
I advise to rename your linked tables to the original name (remove public_), that makes things much less confusing. The schema name is automatically added by Access when linking the tables.
I am trying to import a table from SQL into access but I am getting too many indexes in the table error. The table in SQL is indexed to several tables and unfortunately I don't have the rights to modify or change the table anyway. just have read access in the DB. I am trying to import/link the table but I am unable to do so due to too many indexes error being thrown.
Is it possible to only import/link the data and not indexes? I know access has a limit of 32 indexes. I have cleared auto indexes in options too, but I still get the error.
Is there a solution as to how I can import/link this table in access?
Thanks in advance
I did some digging on how to avoid this problem. So the problem is we can't directly link to the SQL database if the table has a lot of indexes and Access will throw an error "too many indexes on the table you are trying to import".
one way to beat this is by putting together a "Pass-through query". Lot of people suggested VBA code. I am not a coder and could not get it to work effectively. However, Access gives you the capability to build it with out VBA and the solution I found was in Microsoft website.
The steps are as follows: you might have to work around it for 2010 due to different naming convention when compared to 2007.
On the Create tab, click Query Design in the Other group.
Click Close in the Show Table dialog box without adding any tables or queries.
Save the query. Open the Query in design mode
On the Design tab, click Pass-Through in the Query Type workgroup.
Click Property Sheet in the Show/Hide workgroup to display the property sheet for the query.
In the query property sheet, place the mouse pointer in the ODBC Connect Str property, and then, click the Build (...) button.
With the ODBC Connect Str property, you specify information about the database to which you want to connect. You can type the connection information, or click Build, and then enter information about the server to which you are connecting.
When you are prompted to save the password in the connection string, click Yes if you want the password and logon name to be stored in the connection string information.
If the query is not the type that returns records, set the ReturnsRecords property to No.
In the SQL Pass-Through Query window, type your pass-through query. For example, the following pass-through query uses the Microsoft SQL Server TOP operator in the SELECT statement to return only the first 25 orders in the Orders table from the sample Northwind database:
SELECT TOP 25 orderid from orders
To run the query, click Run in the Results group on the Design tab. For a SQL pass-through query that returns records, click Datasheet view on the status bar.
If necessary, Microsoft Access prompts you for information about your server database.
This worked for me. If some one is having the same problem you can use these steps.
I am new to access. I am using a tool/access database someone built, and it has an ODBC connection to an Oracle SQL database in it.
There are different queries on the side panel, and some of them are delete queries.
If I run these delete queries will they just modify data in my local access database without modifying the data in the Oracle Database?
Yes these will change something in the database whether its linked with another access database table or oracle table and within the database. To review the query you can open the queries in design view and run a normal select query so you can see what the queries are deleting. You can have a normal table image and or globe with a arrow in front pointing towards the table then its linked. A lot of times when I am testing I just run select queries and then I make a copy of what I will be deleting just in case anything goes wrong.
I've got a database that resides on an SQL server box, and another in a separate mdb file.
Both contain similar data, but I'd like to run a query that checks unmatched records from a field that exists in both.
Is this something that's easy enough to do using ADO (VBA)? If so can you point me in the right direction?
The easiest would be to create a new Access Database or ADP, and link the tables from both the SQL server and the other MDB. That way you've got an interface to both from within the same instance, which allows you to query or join different tables.
When I right click on the database I want to export data from, I only get to select a single table or view, rather than being able to export all of the data. Is there a way to export all of the data?
If this is not possible, could you advise on how I could do the following:
I have two databases, with the same table names, but one has more data than the other
They both have different database names (Table names are identical)
They are both on different servers
I need to get all of the additional data from the larger database, into the smaller database.
Both are MS SQL databases
Being that both are MS SQL Servers, on different hosts... why bother with CSV when you can setup a Linked Server instance so you can access one instance from the other via a SQL statement?
Make sure you have a valid user on the instance you want to retrieve data from - it must have access to the table(s)
Create the Linked Server instance
Reference the name in queries using four name syntax:
INSERT INTO db1.dbo.SmallerTable
SELECT *
FROM linked_server.db.dbo.LargerTable lt
WHERE NOT EXISTS(SELECT NULL
FROM db1.dbo.SmallerTable st
WHERE st.col = lt.col)
Replace WHERE st.col = lt.col with whatever criteria you consider to be duplicate values between the two tables.
There is also a very good tool by Redgate software that syncs data between two databases.
I've also used SQL scripter before to generate a SQL file with insert statements that you can run on the other database to insert the data.
If you right-click on the database, under the Tasks menu, you can use the Generate Scripts option to produce SQL scripts for all the tables and data. See this blog post for details. If you want to sync the second database with the first, then you're better off using something like Redgate as suggested in mpenrow's answer.