How do I link a table from one connection to another in SQL? - sql

I need to link data from a table in one sql connection to a table in another sql connection, and combine them to make one table (inner join).
How could I achieve it?

If you are trying to connect databases in two different servers,You can add of them as linked server.
Then you can access the data from that server, for example if you are adding server1,then you can access the table using the following query.
SELECT *
FROM server1.YourDatabaseName.YourSchemaName.YourTableName
If you wanted to access from a different Database of the same server.Then use the following code for accaeeing the table data.
SELECT *
FROM YourDatabaseName.YourSchemaName.YourTableName

Related

How to make queries for two different table placed in 2 different server

I just have two servers [sm33ooo.net] and [sm22ooo.net] , i would like to make query between two different tables (tbl_doc) in server [sm33ooo.net] and (tbl_archive) in [sm22ooo.net] using oracle sql developer ,any idea ?
you should be able to create a DBLINK on one of the databases which will allow you to query a table on that database from the other database. I'm not sure of your setup from your post so you might need to look into the difference between private and public dblinks to decide what is relevant to you.
For example if you add your link to server sm33ooo.net called dblink then on server sm22ooo.net you will be able to write select * from tbl_doc#dblink;

Access Pass Through & Access table

I need to use a pass through query using an ODBC connection, however I need to further refine the SQL using another tables within the same Access database.
How do I reference the Access table? Access keeps thinking I am looking for a table via the ODBC connection rather than the database itself.
First, you create a Linked Table in access, using the ODBC connection. Then, you just write a query against the Access database using whatever name you give your Linked Table, and the names of the access tables.
Be warned: if the linked table contains a large number of rows, Linked Tables can be very inefficient.

how can i copy table and data from one database to another using oracle

I'm using Oracle PL/SQL developer. I have two databases live and dummy.
I have been using the dummy database for development and now i need to add all the new tables and data into the live database without effecting the data currently stored in it.
I also need to copy over all the new sequences and triggers.
I've tried exporting a table but had no luck and using the SQL view i only get the SQL for the creation of the data and not the data it contains.
I also found this SQL code
COPY FROM test#DUMMY - CREATE test -USING SELECT * FROM test;
But it asks me for a name and password of which I dont know and then fails after 3 attempts. It then goes on to say there is a syntax error as well.
I'm still fairly new to using Oracle and any help would be appreciated.
You can do that using datapump.
or if you want to copy from schema to schema
create table shecma2.old_table
as
select * from schema1.old_table
or using oracle sql developer - here is link.
Try:
CREATE TABLE NEWTABLE AS SELECT * FROM OLDTABLE;

How do you transfer all tables between databases using SQL Management Studio?

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.

How to create views based on tables from different server?

How to create a view from table A from server 1 and table B from server 2, based on a same column named as col? They use different credentials. The servers are SQL Server 2005
Without knowing details, I'm not sure this is the best idea - but this would work for you. It requires four part naming and linked servers.
Here is the syntax for the view.
Create VIEW [dbo].[vw_CrossServer]
AS
SELECT *
FROM Server1.DatabaseName.Schema.tableA TA
INNER JOIN Server2.DatabaseName.Schema.tableB TB ON TA.col = TB.col
GO
For this to work, you'll need to setup a linked server between the databases. Linked Server
Link also contains examples and other resources.