sp_addserver (Transact-SQL)sp_addserver (Transact-SQL)

适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) 适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions)

SQL ServerSQL Server定义 本地实例的名称。Defines the name of the local instance of SQL ServerSQL Server. 重命名宿主计算机后 SQL ServerSQL Server ,使用 sp_addserver 通知 SQL Server 数据库引擎SQL Server Database Engine 新计算机名称的实例。When the computer hosting SQL ServerSQL Server is renamed, use sp_addserver to inform the instance of the SQL Server 数据库引擎SQL Server Database Engine of the new computer name. 数据库引擎Database Engine 必须在该计算机承载的所有实例上执行此过程。This procedure must be executed on all instances of the 数据库引擎Database Engine hosted on the computer. 数据库引擎Database Engine 无法更改的实例名称。The instance name of the 数据库引擎Database Engine cannot be changed. 若要更改命名实例的实例名称,安装具有所需名称的新实例、从旧实例中分离数据库文件、将数据库附加到新实例并删除旧实例。To change the instance name of a named instance, install a new instance with the desired name, detach the database files from old instance, attach the databases to the new instance and drop the old instance. 或者,你可以在客户端计算机上创建客户端别名名称,无需更改服务器计算机上的实例名称即可将连接重定向到其他服务器和实例名称或 服务器:端口 组合。Alternatively, you can create a client alias name on the client computer, redirecting the connection to different server and instance name or server:port combination without changing the name of the instance on the server computer.

主题链接图标 Transact-SQL 语法约定Topic link icon Transact-SQL Syntax Conventions

语法Syntax


sp_addserver [ @server = ] 'server' ,
     [ @local = ] 'local' 
     [ , [ @duplicate_ok = ] 'duplicate_OK' ]

参数Arguments

[ @server = ] 'server' 服务器的名称。[ @server = ] 'server' Is the name of the server. MicrosoftMicrosoft 服务器名称必须唯一且必须符合 Windows 计算机名称的规则,但不允许包含空格。Server names must be unique and follow the rules for MicrosoftMicrosoft Windows computer names, although spaces are not allowed. server 的数据类型为 sysname,无默认值。server is sysname, with no default.

SQL ServerSQL Server 如果计算机上安装了多个 实例,则实例将如同在一个独立服务器上运行。When multiple instances of SQL ServerSQL Server are installed on a computer, an instance operates as if it is on a separate server. 通过将 服务器 作为 servername\instancename引用来指定命名实例。Specify a named instance by referring to server as servername\instancename.

[ @local = ] 'LOCAL' 指定要添加为本地服务器的服务器。[ @local = ] 'LOCAL' Specifies that the server that is being added as a local server. ** @ localvarchar (10) **,默认值为 NULL。@local is varchar(10), with a default of NULL. 将** @ local指定为 local 会 @ server*定义为本地服务器的名称,并使 @ @SERVERNAME 函数返回server*的值。Specifying @local as LOCAL defines @server as the name of the local server and causes the @@SERVERNAME function to return the value of server.

安装程序会在安装过程中将此变量设置为计算机名称。SQL ServerSQL Server Setup sets this variable to the computer name during installation. SQL ServerSQL Server 默认情况下,用户可通过计算机名连接到 的实例而无需额外的配置。By default, the computer name is the way users connect to an instance of SQL ServerSQL Server without requiring additional configuration.

数据库引擎Database Engine 只有重新启动后,本地的定义才会生效。The local definition takes effect only after the 数据库引擎Database Engine is restarted. 数据库引擎Database Engine每个实例中只能定义一个本地服务器。Only one local server can be defined in each instance of the 数据库引擎Database Engine.

[ @duplicate_ok = ] 'duplicate_OK' 指定是否允许重复的服务器名称。[ @duplicate_ok = ] 'duplicate_OK' Specifies whether a duplicate server name is allowed. ** @ duplicate_OKvarchar (13) **,默认值为 NULL。@duplicate_OK is varchar(13), with a default of NULL. ** @ duplicate_OK的值只能duplicate_OK**或 NULL。@duplicate_OK can only have the value duplicate_OK or NULL. 如果指定 duplicate_OK 并且要添加的服务器名称已存在,则不会引发错误。If duplicate_OK is specified and the server name that is being added already exists, no error is raised. 如果未使用命名参数,则必须指定** @ local** 。If named parameters are not used, @local must be specified.

返回代码值Return Code Values

0(成功)或 1(失败)0 (success) or 1 (failure)

备注Remarks

若要设置或清除服务器选项,请使用 sp_serveroptionTo set or clear server options, use sp_serveroption.

不能在用户定义的事务内使用sp_addserversp_addserver cannot be used inside a user-defined transaction.

使用 sp_addserver 添加远程服务器已停止使用。Using sp_addserver to add a remote server is discontinued. 改用 sp_addlinkedserverUse sp_addlinkedserver instead.

权限Permissions

**** 要求具有 setupadmin 固定服务器角色的成员身份。Requires membership in the setupadmin fixed server role.

示例Examples

数据库引擎Database Engine 下面的示例将承载 SQL ServerSQL Server 的计算机名称的 ACCOUNTS条目更改为 。The following example changes the 数据库引擎Database Engine entry for the name of the computer hosting SQL ServerSQL Server to ACCOUNTS.

sp_addserver 'ACCOUNTS', 'local';

另请参阅See Also

将承载 SQL Server sp_addlinkedserver 的独立实例的计算机重命名 (transact-sql) sp_dropserver (Transact-sql) sp_helpserver transact-sql (系统存储过程)transact-sql (安全存储过程)transact-sql (Rename a Computer that Hosts a Stand-Alone Instance of SQL Server sp_addlinkedserver (Transact-SQL) sp_dropserver (Transact-SQL) sp_helpserver (Transact-SQL) System Stored Procedures (Transact-SQL) Security Stored Procedures (Transact-SQL)