简体   繁体   中英

How to insert data from prod server to dev server in SQL Server

I would like to insert data from prod server to dev server for a particular table.

I am using insert into SQL query and fully qualified name. That is I am specifying server name, databsename, schema name and table name.

insert into ServerADev.[ING_DB].dbo.[Table1] 
    select * 
    from ServerAProd.[ING_DB].dbo.[Table1] 
    where ID = '08914'

ID is the column in Table1.

For above query I am getting an error:

Cannot find ServerAProd in sys.servers. Verify that the correct server name was specified. If necessary, execute the stored procedure sp_addlinkedserver to add the server to sys.servers.

When I EXEC sp_addlinkedserver @server='ServerAProd' , I am getting:

User does not have permission to perform this action.

Do I need to make a request to DBA (database admin) to grant permission to perform this query?

You need to set up a linked server to query a foreign server. So, either:

  1. ServerAProd is not what you named the linked server

or

  1. You didn't create a linked server yet. You can use the sp_addlinkedserver from the error message, or browse to "server objects" in the object explorer then right-click -> new on "Linked Servers". See the link above for more details.

For your edit... yes this requires permissions:

When using Transact-SQL statements, requires ALTER ANY LINKED SERVER permission on the server or membership in the setupadmin fixed server role. When using Management Studio requires CONTROL SERVER permission or membership in the sysadmin fixed server role.

1. create linked server for the dev server on production server, 2. use this openquery() to insert data, so that you can insert large data very quickly.

INSERT OPENQUERY (devservername, 'SELECT * FROM devservar_database..dev_server_table_name')
select * from production_table_database_name..production_table_table_name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM