生成GUID [英] Generating GUID

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

问题描述

我正在考虑在使用SQL Server的.net应用程序中使用GUID.我应该编写一个存储过程,以便在输入的每个记录上生成GUID,还是应该直接从应用程序中生成GUID.

I am thinking to use a GUID in my .net app which uses SQL Server. Should I be writing a stored procedure which generates the GUID on each record entered or should I be directly generating it from the application.

提出问题的原因(如果错了,请在此纠正我):

Reasons for asking the question (If am wrong correct me in this):

我(假设/之前)假设:

I (as/pre)sume:

从数据库生成GUID时,可以假定DB会记住先前生成的GUID,因为应用程序很难记住它.

When generating the GUID from the database, you can assume that the DB remembers the previous generated GUID where as the application remembering it is difficult.

推荐答案

SQL Server具有内置的GUID创建功能.无需为此编写单独的存储过程.

SQL Server has the creation of GUID's built in. There is no need to write a separate stored procedure for this.

您可以使用

  • NEWID()
  • NEWSEQUENTIALID()

这两个过程之间的关键区别在于,如果顺序GUID用于主群集键,则应使用该顺序.

The key difference between both procedures would be that the sequential GUID should be used if it is for a primary clustered key.

我不确定为什么您希望数据库引擎记住先前生成的GUID.

I'm not sure why you would want the database engine to remember the previous generated GUID.

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

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