SqlServer2008 数据库同步的两种方式(Sql JOB)
数据库同步是一种比较常用的功能。以下结合我自己的体会整理的,如果有理解不完全或者有误的地方望大牛不理赐教。下面介绍的就是数据库同步的两种方式: 1、SQL JOB的方式 sql Job的方式同步数据库就是通过SQL语句,将一个数据源中的数据同步到目标数据库中
数据库同步是一种比较常用的功能。以下结合我自己的体会整理的,如果有理解不完全或者有误的地方望大牛不理赐教。下面介绍的就是数据库同步的两种方式:
1、SQL JOB的方式
sql Job的方式同步数据库就是通过SQL语句,将一个数据源中的数据同步到目标数据库中。特点是它可以灵活的通过SQL的方式进行数据库之间的同步操作。可 以在制定的时间时间作为任务计划自动执行。缺点是需要写SQL来进行操作。既然是数据库之间的同步就涉及到数据库之间的连接。建立连接是同步的第一步。 SQL Server建立连接可以通过系统存储过程建立【是否还有其他方式,我还不清楚】。存储过程有以下几个:sp_droplinkedsrvlogin、 sp_dropserver、sp_addlinkedserver、sp_addlinkedsrvlogin。前面两个是删除数据库之间连接的,后两 个是建立数据库之间连接的。
删除连接存储过程参数用法如下:
a)sp_droplinkedsrvlogin
语法
<b>sp_addlinkedsrvlogin</b> [ <b>@rmtsrvname = </b>] <b>'</b><i>rmtsrvname</i><b>'</b>
[ <b>, </b>[ <b>@useself = </b>] <b>'</b><i>useself</i><b>' </b>]
[ , [ <b>@locallogin</b> <b>= </b>] <b>'</b><i>locallogin</i><b>' </b>]
[ <b>, </b>[ <b>@rmtuser = </b>] <b>'</b><i>rmtuser</i><b>' </b>]
[ <b>, </b>[ <b>@rmtpassword = </b>] <b>'</b><i>rmtpassword</i><b>' </b>]
参数
[@rmtsrvname =] 'rmtsrvname'
是应用登录映射的链接服务器名称。rmtsrvname 的数据类型为 sysname,没有默认设置。
[@useself =] 'useself'
决定用于连接到远程服务器的登录名称。useself 的数据类型为 varchar(8),默认设置为 TRUE。true 值指定 SQL Server 验证的登录使用其自己的凭据以连接到 rmtsrvname,而忽略 rmtuser 和 rmtpassword 参数。false 值指定 rmtuser 和 rmtpassword 参数用来连接到特定 locallogin 的 rmtsrvname。如果 rmtuser 和 rmtpassword 也设置为 NULL,则连接链接服务器不需使用任何登录或密码。对于 Windows NT 身份验证登录而言,useself 为 true 则无效,除非 Microsoft Windows NT® 环境支持安全帐户委托,并且,提供程序支持 Windows 身份验证(此时不再需要创建值为 true 的映射,不过创建仍然有效)。
[ @locallogin =] 'locallogin'
本地服务器上的登录。locallogin 的数据类型为 sysname,默认设置为 NULL。NULL 值指定此条目将应用于所有连接到 rmtsrvname 的本地登录。如果值不为 NULL,则 locallogin 可以是一个 SQL Server 登录或 Windows NT 用户。必须授予 Windows NT 用户直接访问 SQL Server 或通过其作为已授予访问权限的组的成员来访问 SQL Server 的权限。
[@rmtuser =] 'rmtuser'
当 useself 为 false 时,用来连接 rmtsrvname 的用户名,rmtuser 的数据类型为 sysname,默认设置为 NULL。
[@rmtpassword =] 'rmtpassword'
与 rmtuser 相关的密码。rmtpassword 的数据类型为 sysname,默认设置为 NULL。
返回代码值
0(成功)或 1(失败)
注释:
当用户登录到本地服务器并执行分布式查询,以访问链接服务器上的表时,本地服务器必须登录链接服务器上,代表该用户访问该表。使用 sp_addlinkedsrvlogin 来指定本地服务器登录链接服务器的登录凭据。
本地服务器上所有登录和链接服务器上的远程登录之间的默认映射通过执行 sp_addlinkedserver 自动创建。默认映射说明连接到链接服务器代表的登录时,SQL Server 使用本地登录的用户凭据(等同于将链接服务器的 @useself 设置为 true 时执行 sp_addlinkedsrvlogin)。使用 sp_addlinkedsrvlogin 只可以更改特定的本地服务器的默认映射或添加新映射。若要删除默认映射或任何其它映射,请使用 sp_droplinkedsrvlogin。
当所有下列条件存在时,SQL Server 可以自动地使用正在发出查询的用户的 Windows NT 安全凭据(Windows NT 用户名称和密码),以连接到链接服务器,而不是必须使用 sp_addlinkedsrvlogin 创建一个预设的登录映射。
用法示例:
EXEC sp_droplinkedsrvlogin 'DBLink',Null
b)sp_dropserver
从本地 Microsoft® SQL Server™ 上的已知远程和链接服务器列表中删除服务器。
语法
sp_dropserver [ @server = ] 'server'
[ , [ @droplogins = ] { 'droplogins' | NULL} ]
参数
[@server =] 'server'
将被删除的服务器。server 的数据类型为 sysname,没有默认值。server 必须已经存在。
[@droplogins =] 'droplogins' | NULL
指明如果指定了 droplogins,那么对于 server,那些相关的远程及链接服务器登录也将被删除。@droplogins 的数据类型为 char(10),带有默认值 NULL。
返回代码值
0(成功)或 1(失败)
注释
如果某个服务器有相关的远程及链接服务器登录条目,当在该服务器上运行 sp_dropserver 时,会导致一条错误信息,该消息说明:在删除远程或链接服务器之前,必须先删除相关的登录。当删除服务器时,为了删除服务器的所有远程及链接服务器登录,请使用 droplogins 参数。
不能在用户定义的事务内执行 sp_dropserver。
权限
只有 sysadmin 或 setupadmin 固定服务器角色的成员才可以执行 sp_dropserver。
用法示例:
EXEC sp_dropserver 'DBLink'
建立连接存储过程参数用法如下:
a)sp_addlinkedserver
创建一个链接的服务器,使其允许对分布式的、针对 OLE DB 数据源的异类查询进行访问。在使用 sp_addlinkedserver 创建链接的服务器之后,此服务器就可以执行分布式查询。如果链接服务器定义为 Microsoft® SQL Server™,则可执行远程存储过程。
语法
<b>sp_addlinkedserver </b>[ <b>@server</b> <b>= </b>] <b>'</b><i>server</i><b>'</b>
[ <b>, </b>[ <b>@srvproduct</b> <b>= </b>] <b>'</b><i>product_name</i><b>' </b>]
[ <b>, </b>[ <b>@provider</b> <b>= </b>] <b>'</b><i>provider_name</i><b>' </b>]
[ <b>, </b>[ <b>@datasrc</b> <b>= </b>] <b>'</b><i>data_source</i><b>' </b>]
[ <b>, </b>[ <b>@location</b> <b>= </b>] <b>'</b><i>location</i><b>' </b>]
[ <b>, </b>[ <b>@provstr</b> <b>= </b>] <b>'</b><i>provider_string</i><b>' </b>]
[ <b>, </b>[ <b>@catalog</b> <b>= </b>] <b>'</b><i>catalog</i><b>' </b>]
参数
[ @server = ] 'server'
要创建的链接服务器的本地名称,server 的数据类型为 sysname,没有默认设置。
如果有多个 SQL Server 实例,server 可以为 servername\instancename。此链接的服务器可能会被引用为下面示例的数据源:
<span><code>SELECT *FROM [servername\instancename.]pubs.dbo.authors. </code></span>
如果未指定 data_source,则服务器为该实例的实际名称。
[ @srvproduct = ] 'product_name'
要添加为链接服务器的 OLE DB 数据源的产品名称。product_name 的数据类型为 nvarchar(128),默认设置为 NULL。如果是 SQL Server,则不需要指定 provider_name、data_source、location、provider_string 以及目录。
[ @provider = ] 'provider_name'
与此数据源相对应的 OLE DB 提供程序的唯一程序标识符 (PROGID)。provider_name 对于安装在当前计算机上指定的 OLE DB 提供程序必须是唯一的。provider_name 的数据类型为nvarchar(128),默认设置为 NULL。OLE DB 提供程序应该用给定的 PROGID 在注册表中注册。
[ @datasrc = ] 'data_source'
由 OLE DB 提供程序解释的数据源名称。data_source 的数据类型为 nvarchar(4000),默认设置为 NULL。data_source 被当作 DBPROP_INIT_DATASOURCE 属性传递以便初始化 OLE DB 提供程序。
当链接的服务器针对于 SQL Server OLE DB 提供程序创建时,可以按照 servername\instancename 的形式指定 data_source,它可以用来连接到运行于特定计算机上的 SQL Server 的特定实例上。servername 是运行 SQL Server 的计算机名称,instancename 是用户将被连接到的特定 SQL Server 实例的名称。
[ @location = ] 'location'
OLE DB 提供程序所解释的数据库的位置。location 的数据类型为 nvarchar(4000),默认设置为 NULL。location 作为 DBPROP_INIT_LOCATION 属性传递以便初始化 OLE DB 提供程序。
[ @provstr = ] 'provider_string'
OLE DB 提供程序特定的连接字符串,它可标识唯一的数据源。provider_string 的数据类型为 nvarchar(4000),默认设置为 NULL。Provstr 作为 DBPROP_INIT_PROVIDERSTRING 属性传递以便初始化 OLE DB 提供程序。
当针对 Server OLE DB 提供程序提供了链接服务器后,可将 SERVER 关键字用作 SERVER=servername\instancename 来指定实例,以指定特定的 SQL Server 实例。servername 是 SQL Server 在其上运行的计算机名称,instancename 是用户连接到的特定的 SQL Server 实例名称。
[ @catalog = ] 'catalog'
建立 OLE DB 提供程序的连接时所使用的目录。catalog 的数据类型为sysname,默认设置为 NULL。catalog 作为 DBPROP_INIT_CATALOG 属性传递以便初始化 OLE DB 提供程序。
返回代码值
0(成功)或 1(失败)
结果集
如果没有指定参数,则 sp_addlinkedserver 返回此消息:
<span><code>Procedure 'sp_addlinkedserver' expects parameter '@server', which was not supplied. </code></span>
使用适当 OLE DB 提供程序和参数的 sp_addlinkedserver 返回此消息:
<span><code>Server added. <br>用法示例:<br></code>EXEC sp_addlinkedserver 'DBLink', ' ', 'SQLOLEDB', "10.0.222.12"</span><br><br><span>b)sp_addlinkedsrvlogin</span>
创建或更新本地 Microsoft® SQL Server™ 实例上的登录与链接服务器上远程登录之间的映射。
语法
<b>sp_addlinkedsrvlogin</b> [ <b>@rmtsrvname = </b>] <b>'</b><i>rmtsrvname</i><b>'</b>
[ <b>, </b>[ <b>@useself = </b>] <b>'</b><i>useself</i><b>' </b>]
[ , [ <b>@locallogin</b> <b>= </b>] <b>'</b><i>locallogin</i><b>' </b>]
[ <b>, </b>[ <b>@rmtuser = </b>] <b>'</b><i>rmtuser</i><b>' </b>]
[ <b>, </b>[ <b>@rmtpassword = </b>] <b>'</b><i>rmtpassword</i><b>' </b>]
参数
[@rmtsrvname =] 'rmtsrvname'
是应用登录映射的链接服务器名称。rmtsrvname 的数据类型为 sysname,没有默认设置。
[@useself =] 'useself'
决定用于连接到远程服务器的登录名称。useself 的数据类型为 varchar(8),默认设置为 TRUE。true 值指定 SQL Server 验证的登录使用其自己的凭据以连接到
rmtsrvname,而忽略 rmtuser 和 rmtpassword 参数。false 值指定 rmtuser 和 rmtpassword 参数用来连接到特定 locallogin 的 rmtsrvname。
如果 rmtuser 和 rmtpassword 也设置为 NULL,则连接链接服务器不需使用任何登录或密码。对于 Windows NT 身份验证登录而言,useself 为 true 则无效,
除非 Microsoft Windows NT® 环境支持安全帐户委托,并且,提供程序支持 Windows 身份验证(此时不再需要创建值为 true 的映射,不过创建仍然有效)。
[ @locallogin =] 'locallogin'
本地服务器上的登录。locallogin 的数据类型为 sysname,默认设置为 NULL。NULL 值指定此条目将应用于所有连接到 rmtsrvname 的本地登录。如果值不为 NULL,
则 locallogin 可以是一个 SQL Server 登录或 Windows NT 用户。必须授予 Windows NT 用户直接访问 SQL Server 或通过其作为已授予访问权限的组的成员来访问
SQL Server 的权限。
[@rmtuser =] 'rmtuser'
当 useself 为 false 时,用来连接 rmtsrvname 的用户名,rmtuser 的数据类型为 sysname,默认设置为 NULL。
[@rmtpassword =] 'rmtpassword'
与 rmtuser 相关的密码。rmtpassword 的数据类型为 sysname,默认设置为 NULL。
返回代码值
0(成功)或 1(失败)
注释
当用户登录到本地服务器并执行分布式查询,以访问链接服务器上的表时,本地服务器必须登录链接服务器上,代表该用户访问该表。使用 sp_addlinkedsrvlogin 来指定本地服
务器登录链接服务器的登录凭据。
本地服务器上所有登录和链接服务器上的远程登录之间的默认映射通过执行 sp_addlinkedserver 自动创建。默认映射说明连接到链接服务器代表的登录时,SQL Server
使用本地登录的用户凭据(等同于将链接服务器的 @useself 设置为 true 时执行 sp_addlinkedsrvlogin)。使用 sp_addlinkedsrvlogin 只可以更改特定的本地服务器
的默认映射或添加新映射。若要删除默认映射或任何其它映射,请使用 sp_droplinkedsrvlogin。
当所有下列条件存在时,SQL Server 可以自动地使用正在发出查询的用户的 Windows NT 安全凭据(Windows NT 用户名称和密码),以连接到链接服务器,而不是必须使用
sp_addlinkedsrvlogin 创建一个预设的登录映射。
- 使用 Windows 身份验证模式,用户连接到 SQL Server。<br><br>
- 在客户端和发送服务器上安全帐户委托是可用的。<br><br>
- 提供程序支持 Windows 身份验证模式(例如,运行于 Windows NT 上的 SQL Server)。
使用映射(此映射通过在本地 SQL Server 上执行 sp_addlinkedsrvlogin 定义)的链接服务器执行身份验证后,远程数据库中单独对象的权限由链接服务器决定,
而不是由本地服务器决定。
不能从用户定义的事务中执行 sp_addlinkedsrvlogin。
权限
只有 sysadmin 和 securityadmin 固定服务器角色的成员才可以执行 sp_addlinkedsrvlogin。
用法示例
<span>EXEC sp_addlinkedsrvlogin 'DBLink', 'false',null, 'ILM', '111111</span><br><br><span>介绍完建立连接的方式</span>,下面正式介绍SQL JOB的开发。直接用步骤介绍了。<br>a)新建作业。如下图:
a、 新建作业。如下图:
b、 点击【新建作业】对话框的【常规】选项卡,填写 SQL JOB的名称。如下图
c、 点击【新建作业】对话框的【步骤】选项卡,填写 步骤名称。
<br><br>
d、 进行作业的第一个步骤------建立数据库连接操作。如下图:
e、 进行作业的第下一个步骤。如下图:
e、设置作业执行计划
f、点击确定,完成SQL JOB的开发。
g、完成后作业下面就多了刚开发的作业。如下:
<br>h、作业制作完成后,可以立即让它执行。如果不让它执行,它也会在按照制定频率执行。测试作业:
<br><br>
<br><br>
2、发布、订阅。
发布订阅下节再介绍吧。这节东西有点多了。哈哈
其中几个存储过程的参数参照了资料。有兴趣了解更多的可以参考下面的地址:
参考:
http://www.yesky.com/imagesnew/software/tsql/ts_sp_drop_9c1e.htm
http://www.yesky.com/imagesnew/software/tsql/ts_sp_drop_59v2.htm
http://www.yesky.com/imagesnew/software/tsql/ts_sp_adda_8gqa.htm
http://www.yesky.com/imagesnew/software/tsql/ts_sp_adda_6e26.htm

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

HQL and SQL are compared in the Hibernate framework: HQL (1. Object-oriented syntax, 2. Database-independent queries, 3. Type safety), while SQL directly operates the database (1. Database-independent standards, 2. Complex executable queries and data manipulation).

Go language is an efficient, concise and easy-to-learn programming language. It is favored by developers because of its advantages in concurrent programming and network programming. In actual development, database operations are an indispensable part. This article will introduce how to use Go language to implement database addition, deletion, modification and query operations. In Go language, we usually use third-party libraries to operate databases, such as commonly used sql packages, gorm, etc. Here we take the sql package as an example to introduce how to implement the addition, deletion, modification and query operations of the database. Assume we are using a MySQL database.

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

HTML cannot read the database directly, but it can be achieved through JavaScript and AJAX. The steps include establishing a database connection, sending a query, processing the response, and updating the page. This article provides a practical example of using JavaScript, AJAX and PHP to read data from a MySQL database, showing how to dynamically display query results in an HTML page. This example uses XMLHttpRequest to establish a database connection, send a query and process the response, thereby filling data into page elements and realizing the function of HTML reading the database.

1. Open DingTalk on your mobile phone and first select the avatar in the upper left corner. 2. Click Settings at the bottom of the pop-up page. 3. Then click on the settings on the page. 4. Open the calendar settings on the settings page. 5. Click on it and find the synchronized mobile schedule on the page. . 6. Then turn on the synchronization of mobile phone schedules.

PHP is a back-end programming language widely used in website development. It has powerful database operation functions and is often used to interact with databases such as MySQL. However, due to the complexity of Chinese character encoding, problems often arise when dealing with Chinese garbled characters in the database. This article will introduce the skills and practices of PHP in handling Chinese garbled characters in databases, including common causes of garbled characters, solutions and specific code examples. Common reasons for garbled characters are incorrect database character set settings: the correct character set needs to be selected when creating the database, such as utf8 or u
