Use commands to import and export ms SQL data

Source: Internet
Author: User
Title: use commands to import and export ms SQL data

1. Remote Data Import and Export-MSSQL Remote Data Import and Export

Select * into [local database name]... [Table name] from OPENDATASOURCE (
'Sqlodb ',
'Data Source = remote ip address; User ID = sa; Password = password'
). [Database name]. dbo. Table Name
Or
Insert [local database name]... [Table name] select * from OPENDATASOURCE (
'Sqlodb ',
'Data Source = remote ip address; User ID = sa; Password = password'
). [Database name]. dbo. Table Name

2. Use the connection Server:
-- Create a linked server
Declare @ rmtsrvname varchar (64)
Declare @ useself varchar (64)
Declare @ locallogin varchar (64)
Declare @ rmtuser varchar (64)
Declare @ rmtpassword varchar (64)

Exec sp_addmediaserver 'remote service alias ', '', 'msdasql', NULL, NULL, 'driver = {SQL Server}; SERVER = Remote Server IP address; UID = Remote SERVER user name; PWD = Remote Server user password ;'
Exec sp_addlinkedsrvlogin @ rmtsrvname = 'remote service alias ', @ useself = 'false', @ locallogin = 'sa', @ rmtuser = 'remote server username ', @ rmtpassword = 'remote Server user password' GO


Select * from remote service alias. Remote database name. dbo. Name of the remote database table

-- Delete the linked server after processing.
Exec sp_dropserver 'remote service alias ', droplogins

GO

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.