简体   繁体   English

SQL Server 2008使用服务器ID作为默认值

[英]SQL Server 2008 use server id as a default

I have a tables of rows that exists in multiple databases. 我有一个存在于多个数据库中的行表。 I will need to update the rows from one database into the other database and I have a primary key of int. 我需要将行从一个数据库更新到另一个数据库,并且我的主键为int。 So I am looking for a way to uniquely identify the server that added a particular row. 因此,我正在寻找一种唯一标识添加了特定行的服务器的方法。 I could use a uniqueidentifier in a default using the newid() or newseqentialid() but this seems overkill and inefficient. 我可以在默认情况下使用newid()或newseqentialid()来使用一个uniqueidentifier,但这似乎过分且效率低下。

I would like to create a default value on a column of serverid of @@serverid but this doesn't exist, I could use @@servername but this seems too obvious to errors. 我想在@@ serverid的serverid列上创建一个默认值,但是它不存在,我可以使用@@ servername,但这对于错误似乎太明显了。 Is there any way to get back a guid for the server and add it as a default on a column? 有什么方法可以找回服务器的guid并将其作为默认值添加到列中?

Thanks in advance 提前致谢

Phil 菲尔

假设您的服务器数量可能少于2 ^ 31-1,那么您可以简单地为每个服务器分配一个唯一的(32位)整数来标识它。

I'd just use @@SERVERNAME or a tabe based on this. 我只使用@@ SERVERNAME或基于此的标签。

It's unambiguous, human readable and shorter then GUID 它是明确的,人类可读的并且比GUID短

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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