主键的UniqueIdentifier [英] UniqueIdentifier to Primary key

查看:129
本文介绍了主键的UniqueIdentifier的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在
中将UniqueIdentifier转换为主键整数
SQL Server 2008

How to convert UniqueIdentifier to Primary key integer in

Sql server 2008

推荐答案


UniqueIdentifier是Guid,不能转换为int.但是,如果您添加新列INT并将其设置为主键并且具有身份标识,则数据库将为所有行提供新的ID(int),并且您可以保留UniqueIdentifier列,也可以只删除它..(除非它具有很多关系) ...)
UniqueIdentifier is a Guid and cannot be convertet to an int. But if you add a new column INT and set it as primary key and is identity the database will give all rows a new id (int) And you can keep you UniqueIdentifier column or just delete it.. (unless it has a lot of relations...)


Uniqueidentifier用于生成代理密钥 [ ^ ],它同时包含字符和数字,因此无法转换为任何数字数据类型.

如果要将其转换为某些内容,则可以使用字符数据类型,例如nvarchar.但是,您通常不需要将其转换为任何特殊的内容,因为唯一标识符的唯一目的是识别单个记录.

如果要查找参数的.Net等效数据类型,则可以使用SqlDbType.UniqueIdentifier.请参阅: SqlDbType枚举 [
Uniqueidentifier is used to generate a surrogate key[^] and it contains both characters and numbers so it cannot be converted to any number data type.

If you want to convert it to something, you can use character datatypes, for example nvarchar. However, you normally shouldn''t need to convert it to anything special since the only purpose of unique identifier is to identify a single record.

If you''re looking for the .Net equivalent data type for parameters, you can use SqlDbType.UniqueIdentifier. See: SqlDbType Enumeration[^]

In my opinion keeping the primary key as an uniqueidentifier is an excellent choice, especially if replication is involved.


这篇关于主键的UniqueIdentifier的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆