Creating a snapshot database to another SQL Server - sql-server

I'm trying to save the values of several columns of one table to another table on a different server. I am using SQL Server. I would like to do this without running external programs that query from this database and insert the results into the new database. Is there any way to do this from within the SQL Server Management Studio?
This is a recurring event that occurs every hour. I have tried scheduling maintenance tasks that execute custom T-SQL scripts but I'm having trouble getting the connection to the remote server.
Any help would be appreciated.

If you can set up the remote server as a linked server you should be able to configure the SQL Server Agent to execute jobs that contain queries that access tables on both the local and linked server. Remember that you might have to configure the access rights for the account used to run SQL Server Agent so that it has permissions to read/write tables on both servers.
This practice might not be without issues though as this article discusses.

You can use a 4 part name like;
INSERT [InstanceName].[DatabaseName].[SchemaName].[TableName]
SELECT * FROM [SourceInstanceName].[SourceDatabaseName].[SourceSchemaName].[SourceTableName]
But first you will have to set the remote server as a linked server as so;
https://msdn.microsoft.com/en-us/library/aa560998.aspx

Related

Move data between different servers

I'm working on a project where I need to automatically run an insert statement to insert a result set - problem is that I need it to go from a SQL Server over to a DB2 server. I can't create a file or script and then import it or run it on the other side. I need to insert or update the DB2 side from the SQL Server side.
Is this possible? I need this to run all by itself as part of a stored procedure in SQL Server.
You're looking for the linked server feature.
Typically linked servers are configured to enable the Database Engine to execute a Transact-SQL statement that includes tables in another instance of SQL Server, or another database product such as Oracle. Many types OLE DB data sources can be configured as linked servers, including Microsoft Access and Excel. Linked servers offer the following advantages:
The ability to access data from outside of SQL Server.
The ability to issue distributed queries, updates, commands, and transactions on heterogeneous data sources across the enterprise.
The ability to address diverse data sources similarly.
(I believe most of the major RDBMSs have a similar feature)
For the most part, this essentially allows you to treat tables or sources in the other database as if they were part of the SQL Server instance - an INSERT statement should just work "normally".
As mentioned you can use a linked server on the SQL Server side to perform operations between two servers. I haven't done much with running DML on DB2 from SQL Server, but from my experience SSIS performs far better than linked servers for transactions pulling data from DB2 to SQL Server using an OLE DB connection. You can read more about OLE DB connections in SSIS here and you'll want to reference the DB2 documentation for the specific DB2 type (Mainframe, LUW, etc.) that's used for details on setting up the connection there. If you setup the SSIS catalog you can run packages using SQL Server stored procedures, which you can either use directly or execute from an existing user stored procedures.

How to link Access table in SQL Server

I have a SQL database and I want to link an Access table in the SQL database. Most of the online articles and videos show how to link the two databases from Access but not from SQL. I want the access table linked in SQL database so that every time the table gets updated in Access, the table in SQL server gets updated as well. Thanks!
You can do that. It's called a Linked Server and will link your Access database in SQL Server where you typically will create a view to read the Access tables to avoid the DatabaseName..TableName syntax otherwise needed.
However, it will probably not work for you because SQL Server will insist on opening the linked Access database exclusively, meaning that you cannot open it later from your Access application. And if you open it first in Access, an attempted reading from SQL Server will fail because SQL Server cannot get exclusive access.
You may argue, that a shared access should be possible, and connection parameters indicate this, but I haven't found a way to achieve this.
So, as others have mentioned, you may have turn this upside/down, and use, say, ODBC to link the SQL Server tables in your Access application, and then let this take care of the maintenance of the SQL Server tables.
It must be like this (SQL SERVER) => (MS Access)
and yes you are correct, it's called linked tabled in Ms Access. In order to link a table from another database, you must have
Correct drivers installed. (ODBC)
Know the login details of your SQL server and have sufficient permission in SQL server
Go to MS Access -> External data -> ODBC Databse -> link to the data source by creating a linked table ->
Now you can select a DSN file where your sql server credentials are saved, or you can make "new" and follow the steps to get connected to the SQL server.
Once connected, you will be presented with a list of all the tables from SQL server. Select the table you want to link and finish the wizard.
You now have SQL table connected in MS Access and can input data directly.

Automatically update SQL Server database from tables in MS Access

I'm new to SQL Server and trying to automatically update tables in SQL Server from tables in MS Access.
I have an Access database of metadata that must be kept updated for sending records to other groups. I also have a database in SQL Server which also has these same metadata tables. Currently these tables in the SQL Server database get updated manually by exporting the Access tables as Excel files, and then importing them into the SQL Server tables.
It's not the most efficient process and could lead to errors in the SQL Server database if someone forgets to check that they are using the most recent data from Access. So I would like to integrate some of the tables from Access to my database in SQL Server. Ideally I would like for the tables in my SQL Server database to be updated whenever Access is updated or at least update the tables automatically in the SQL Server database when I open it.
Would replicating the Access tables be the best? I am using SQL Server 2014 Developer so I think I have this capability. From my understanding, mirroring is for an entire database not just pieces of it. However, I do not want to be able to alter the metadata from SQL Server and have it reflected in Access. I cannot tell if reflecting the tables would do this...?
I also looked at this post about writing multiple insert statements but was confused (What is the best way to auto-generate INSERT statements for a SQL Server table?). Someone else suggested importing all the data into SQL Server and then using an ODBC driver to connect the two, but I'm also not sure how this would update the database in SQL Server anytime Access is updated.
If you have any suggestion and a link to easy to follow tutorial I would really appreciate it!
Thanks
In Access, go to 'External Data', ODBC Database, and connect to the SQL Server database directly - make sure you select 'Link to the data source by creating a linked table' on the first page of the wizard. Now, this linked table is available in Access, but is actually the SQL Server table.
Get rid of the local Access tables, using the new linked tables in their place in whatever queries, forms, reports, etc that you have in Access.
Now, any changes to the tables you see in this Access db ARE changes to the SQL Server database.

Making backup from database to another server

I have a host on a server and that contains an SQL Server Database.
I have another server in another country and i want have a backup from the database every 5 minutes or after each transaction only insert new row to another database.
After some research i found out i can use linkedservers for this goal.
Is this procedure works for me for doing this operation?
I don't know what the linkedserver will do for you.
You are connected from both server via a vpn?
You are in different network (domain) probably?
If you are using a linked server, it means you will probably create trigger or stored proc. You will have to configure msdtc (for trigger).
You can use :
Replication
Log shipping
Custom replication process
I had to configure 2 times a replications to move the data from a server to another, than manage these data with trigger. It was easier to work on the data localy

Execute 'View' residing in a remote server from a stored procedure

How to get the results (pass parameter also) of a view of a remote server from a stored procedure?
The view is in a separate server from the current server where the stored procedures exist.
Thanks.
You could use the Linked Server feature of SQL Server inside your stored procedure:
A linked server configuration allows
Microsoft SQL Server to execute
commands against OLE DB data sources
on different servers. Linked servers
offer these advantages:
Remote server access
The ability to issue distributed
queries, updates, commands, and
transactions on heterogeneous data
sources across the enterprise.
The ability to address diverse data sources similarly.
You would have to write your query inside your stored procedure this way for example:
SELECT *
FROM MyRemoteServer.MyDB.dbo.MyView
WHERE MyViewColumnX = #ParameterY
Create a linked server on your main SQL Server, creating the link to your remote server.
The fact you have a view on the remote server is good, it provides a layer of abstraction to your data. You can specify a login for the linked server that has permission to read that view only. You could also modify the view in the future (add a "where" clause for example to improve performance) with no front end changes required.
I would also add another view on your main server that selects from the view on your remote server: -
create view vwMain as select col1, col2 from RemoteServer.DB.dbo.RemoteView.
That way you can reference vwMain throughout your code (within many stored procedures) without continually referencing the remote server. This way, should your remote server change or you move the data to your main server, it is one simple change to vwMain and all your code continues to work.

Resources