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.
Related
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.
I have a question. In SQL server, we can access a table or view in a different database by using the dot notation in the table name, so I believe that in SQL server, if we say just 'tablename' it will refer to the table name in the current active DB, but if we say 'DBname'.'Tablename' you can access the table in a different DB on the same server, and if you say 'serverName'.'DBName'.'tableName' we can access a table in a remote DB whose DBName is defined in a connection setting. I believe we can define a connection setting between two SQL server to access a different database. So, instead of copying the data from one DB to other and duplicate the same, it might be better to simply define a view.
Can anyone please help me if we can do so and how?
Using Linked Server you can access two different servers.
use the below link to add the linked server.
http://sqlserverplanet.com/dba/how-to-add-a-linked-server
I am trying to create a SQL Job that sits on what I like to call a Maintenance Server where details about all the other server databases sit. So I have a stored procedure to gather all the required data I have and this stored procedure is now in MaintenanceServer.MaintenanceDB.pr_MyProcedure.
Now what i'd like to do this is. I am creating Linked Servers on my MaintenanceServer which points to all the other Servers I'd like to maintain. Next on my list is to be able to run this procedure pr_MyProcedure against all those LinkedServers. I have over 25 servers to maintain and what i want to do is to run the procedure against them and insert the result to my local MaintenanceDB.
Can someone point me to a good way to do this? Also i'd like to hear the drawbacks of this method.
Thanks and Cheers!
EDIT:
I was also thinking about storing the SP on all the master databases of my other Servers and running them remotely on my Maintenance Server. Then i'll use OPENQUERY() to gather all the results that I need. However, I don't think I want to touch all the master databases on my server list. Please tell me if this would be better than the once I stated above.
The nice way to do it is run the SP on the target server, as that's nicely modular. If you want to query the remote server, it's going to be more painful. I'm not sure whether the undocumented sp_foreachdb deals with linked databases, if not you are down to dynamic sql.
As in build a string and call it with Exec(#somesql), that will need to deal with the results itself, as any variables will only be in scope inside the exec.
Personally I'd consider inverting all this. Have each server call it's own SP and the call an SP on the maintenance box to store the results.
EXEC [RemoteServer] .DatabaseName.DatabaseOwner.StoredProcedureName
‘Params’
Example:
EXEC [RemoteServer] .DatabaseName.DatabaseOwner.StoredProcedureName ’PramValue’
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.
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.