How to create table from remote DB in SQL Server? - sql-server

I want to create some tables from a remote SQL Server in my own sandbox, can anyone tell me how to get that done?
For example, I know there is a way called database link can implement this function, but can I do in SQL Server?

Easiest way is on the Remote SQL server is get the table design.
Right click on it and use Create To. Copy Pasta the code and use in your database.
Just need to modify the database name
After that you will only need to merge the data in if that is what you are also hoping to do.

Related

Update Linked Server Tables Using Synonyms

I have a server in a remote location and Its now connected to my local server through Linked Server. How can I update a table at remote location without using stored procedures.
Would SQL Synonyms be any kind of help?
Does user need to have Write permission on the Remote Server?
Thanks in advance
You would use an update statement. Not sure why the requirement to not use a stored procedure comes from. I am concerned that you believe that somehow a stored procedure would make this easier in some way.
1) Synonyms are not going to help or hinder this process. They are simply a way to shorthand an object name.
2) Of course the user for the linked server connection must have write permission to write data.

Oracle DB Table to SQL Server DB Table

I am wondering if there is a way to replicate an oracle table over to a sql server table. Both servers are on the same network. I would like to have this automated perhaps using a stored procedure on the sql instance. Is there any way to do this automatically? Or can anyone point me to a good sql script to connect to an oracle db server and export a table file?
You could use an Oracle linked server on SQL-Server. In this way you would use the Oracle data directly from SQL-server.
Take a look at this tutorial: http://blogs.msdn.com/b/dbrowne/archive/2013/10/02/creating-a-linked-server-for-oracle-in-64bit-sql-server.aspx
You can use the Import Data function located under Tasks when you right click on a database in SQL Server Management Studio. It will walk you through picking the Source, the Destination, and how the columns map to each other.
Look at this:
http://www.microsoft.com/en-us/download/details.aspx?id=28766
Maybe it should help you

Keep Sql server table updated from Access table

I am attempting to keep a table in Sql server updated from an access table. Any time a change is made in the access table I would like that change reflected in the sql server table. The two tables can be identical. I have created an ODBC connection from access to sql server and can export the table to sql server; I just don’t know what must be done to keep that table updated. Any suggestions are appreciated.
Should this be implemented from within Access or within sql server?
Can you just add the SQL Server table to the Access database as a linked table? (Useful article on how to add linked tables)? That way users (let's hope there's not many!) of the Access database are in effect editing the SQL Server table directly.
If this isn't desirable then how about creating another table in the SQL Server database, and adding this to the Access database as a linked table. Then, add a trigger so that when an insert/update/delete is made to this table the same operation is done on your main table.
I think setting up a Linked Server in SQL Server could be easier to implement than an automatic export of data from Access.
According to the MSDN page,
Many types OLE DB data sources can be configured as linked servers, including Microsoft Access and Excel.
Server-on-SQL-2005-Server/
Access has no "event" that occurs when a row is updated/inserted/deleted that I know of. as JeffO points out data macros that could do what you want.
You could also periodically synch them. There are several techniques to periodically do the synch task (SQL Server Agent, Windows Service, Windows Scheduler, a timer in an application etc.), but still have to deal with all the problems that exist with synchronization if both tables can be modified, the worst being data conflict resolution. There is no easy solution for that.
Perhaps if you explained the problem you have that you are solving with synching data in SQL server and Access someone might be able to point you in the direction of a solution that doesn't have these problems.

Move data from SQL Server to MS Access mdb

I need to transfer certain information out of our SQL Server database into an MS Access database. I've already got the access table structure setup. I'm looking for a pure sql solution; something I could run straight from ssms and not have to code anything in c# or vb.
I know this is possible if I were to setup an odbc datasource first. I'm wondering if this is possible to do without the odbc datasource?
If you want a 'pure' SQL solution, my proposal would be to connect from your SQL server to your Access database making use of OPENDATASOURCE.
You can then write your INSERT instructions using T-SQL. It will look like:
INSERT INTO OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0','Data Source=myDatabaseName.mdb')...[myTableName] (insert instructions here)
The complexity of your INSERTs will depend on the differences between SQL and ACCESS databases. If tables and fields have the same names, it will be very easy. If models are different, you might have to build specific queries in order to 'shape' your data, before being able to insert it into your MS-Access tables and fields. But even if it gets complex, it can be treated through 'pure SQL'.
Consider setting up your Access db as a linked server in SQL Server. I found instructions and posted them in an answer to another SO question. I haven't tried them myself, so don't know what challenges you may encounter.
But if you can link the Access db, I think you may then be able to execute an insert statement from within SQL Server to add your selected SQL Server data to the Access table.
Here's a nice solution for ur question
http://www.codeproject.com/Articles/13128/Exporting-Data-from-SQL-to-Access-in-Mdb-File

Function like USE to point to a SQL database on a different server?

In SQL Server, you can apply the use function to point a query to another database. For example:
USE databasename
GO;
Is there a function that allows you to point to a different database server and use a database on that server? I would expect this to work, but no luck:
USE [servername].databasename
GO;
I know I could just point the query to the database on the other server, but when I am dealing with production versus staging environments, it's more efficient to declare the server and database in the beginning of the query.
Thanks
USE does not span across to another server, you need to define a linked server on your local instance and then you can access data from that server.
I use Linked Servers to accomplish this. I don't know if this will meet your needs, however.
http://msdn.microsoft.com/en-us/library/ms188279.aspx
In Management Studio, this is available under Database/Server Objects/Linked Servers.
You can refer to objects on this server like this:
[Server].database.schema.object
I just realized this isn't what you want. JonH has it right, you can't specify a dabase on another server at the beginning of your query.

Resources