How to resolve MSSQL cross-database query _ MySQL

Source: Internet
Author: User
Resolve MSSQL cross-database query implementation method bitsCN.com
-- Create a linked server
Exec sp_addmediaserver 'connection server name', '', 'sqlodb', 'remote server name or IP address'
Exec sp_addmediasrvlogin 'linked server name', 'false', null, 'linked server username ', 'password'

Sp_addmediaserver
[@ Server =] 'server'
[, [@ Srvproduct =] 'product _ name']
[, [@ Provider =] 'provider _ name']
[, [@ Datasrc =] 'data _ source']
[, [@ Location =] 'location']
[, [@ Provstr =] 'provider _ string']
[, [@ Catalog =] 'catalog ']

Parameters (Parameters ):
[@ Server =] 'server'
The name of the linked server to be created. The data type of the server is sysname, with no default value.

[@ Srvproduct =] 'product _ name'
The product name of the ole db data source to be added as the linked server. The data type of product_name is nvarchar (128), and the default value is NULL. If it is SQL Server, you do not need to specify provider_name, data_source, location, provider_string, and catalog.

[@ Provider =] 'provider _ name'
The unique programming identifier (PROGID) of the ole db access interface corresponding to this data source ). Provider_name must be unique for the specified ole db access interface installed on the current computer. The data type of provider_name is nvarchar (128). The default value is NULL. if provider_name is ignored, SQLNCLI is used. SQLNCLI is the SQL local OLE DB access interface. The ole db access interface should be registered in the registry with the specified PROGID.

[@ Datasrc =] 'data _ source'
Name of the data source interpreted by the ole db access interface. The data type of data_source is nvarchar (4000 ). Data_source is passed as the DBPROP_INIT_DATASOURCE attribute to initialize the ole db access interface.

[@ Location =] 'location'
The location of the database explained by the ole db access interface. The data type of location is nvarchar (4000), and the default value is NULL. Location is passed as the DBPROP_INIT_LOCATION attribute to initialize the ole db access interface.

[@ Provstr =] 'provider _ string'
The connection string specified by the ole db access interface. it can identify a unique data source. The data type of provider_string is nvarchar (4000), and the default value is NULL. Provstr can be passed to IDataInitialize or set to DBPROP_INIT_PROVIDERSTRING to initialize the ole db access interface.
After creating a linked SERVER for the ole db access interface of the SQL local client, you can use the SERVER keyword as Server = servername/instancename to specify an instance to specify a specific SQL SERVER instance. Servername is the name of the computer that runs SQL Server, and instancename is the name of the specific SQL Server instance that the user will connect.

[@ Catalog =] 'catalog'
The directory used to establish a connection with the ole db access interface. The data type of catalog is sysname, and the default value is NULL. Catalog is passed as the DBPROP_INIT_CATALOG attribute to initialize the ole db access interface. When you define a linked Server for an SQL Server instance, the directory points to the default database mapped to the linked Server.

Return code value (returnValue ):
(Successful) or 1 (failed)

Permission:
Requires the alter any linked server permission.
---------------------------------------
Sp_add1_srvlogin [@ rmtsrvname =] 'rmtsrvname' [, [@ useself =] 'useself-service '] [, [@ locallogin =] 'locallogin'] [, [@ rmtuser =] 'rmtuser'] [, [@ rmtpassword =] 'rmtpassword'] Note: sp_add1_srvlogin cannot be executed from a user-defined transaction. Parameter (Parameters): [@ rmtsrvname =] 'rmtsrvname' name of the linked server mapped to the application logon. The data type of rmtsrvname is sysname, with no default value. [@ Useself =] 'useself 'determines the login name used to connect to the remote server. The useself data type is varchar (8), and the default value is TRUE. If the value is true, specify your creden to connect to rmtsrvname and ignore the rmtuser and rmtpassword parameters. False indicates that the rmtuser and rmtpassword parameters are used to connect the rmtsrvname of the specified locallogin. If rmtuser and rmtpassword are also set to NULL, the login name or password is not used to connect to the server. [@ Locallogin =] 'locallogin' logon on the local server. The data type of locallogin is sysname, and the default value is NULL. NULL indicates that this option is applied to all local logins connected to the rmtsrvname. If it is not NULL, locallogin can be a SQL Server logon or Windows logon. For Windows Logon, you must grant the SQL Server access permission directly or by using the authorized members of the Windows group. [@ Rmtuser =] 'rmtuser' indicates the user name used to connect to rmtsrvname when useself is set to false. The data type of rmtuser is sysname, and the default value is NULL. [@ Rmtpassword =] password associated with rmtuser. The data type of rmtpassword is sysname, and the default value is NULL. Return code value (returnValue): 0 (successful) or 1 (failed) permission: requires the alter any login permission on the server.
--------------------------------------------- ------------------------------------------------- Query example select * from link server name. database name. dbo. table name
BitsCN.com

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.