考试网 >> IT认证 >> 水平 >> 系统工程师 >> 小议数据库主键选取策略

小议数据库主键选取策略

发布时间:2006-06-28 02:23     点击:
分页:上一页  1 2 3 4 [5] 



/**//// <summary>

/// 从 SQL SERVER 返回的 GUID 中生成时间信息

/// </summary>

/// <param name="guid">包含时间信息的 COMB </param>

/// <returns>时间</returns>

public static DateTime GetDateFromComb(System.Guid guid)

{

DateTime baseDate = new DateTime(1900,1,1);

byte[] daysArray = new byte[4];

byte[] msecsArray = new byte[4];

byte[] guidArray = guid.ToByteArray();

// Copy the date parts of the guid to the respective byte arrays.

Array.Copy(guidArray, guidArray.Length - 6, daysArray, 2, 2);

Array.Copy(guidArray, guidArray.Length - 4, msecsArray, 0, 4);

// Reverse the arrays to put them into the appropriate order

Array.Reverse(daysArray);

Array.Reverse(msecsArray);

// Convert the bytes to ints

int days = BitConverter.ToInt32(daysArray, 0);

int msecs = BitConverter.ToInt32(msecsArray, 0);

DateTime date = baseDate.AddDays(days);

date = date.AddMilliseconds(msecs * 3.333333);

return date;

}



  结语

  数据库主键在数据库中占有重要地位。主键的选取策略决定了系统是否高效、易用。本文比较了四种主键选取策略的优缺点,并提供了相应的代码解决方案,希望对大家有所帮助。

分页:上一页  1 2 3 4 [5] 
版权申明:未经书面授权请勿转载本站信息!!作品版权归所属媒体与作者所有!!
发表评论: 匿名发表 用户名: 查看评论
您将承担一切因您的行为、言论而直接或间接导致的民事或刑事法律责任
留言板管理人员有权保留或删除其管辖留言中的任意内容
本站提醒:不要进行人身攻击。谢谢配合。
在本站搜索相关信息
2003-2005 Ksw123.com All Rights Reserved. - TOP
Copyright © 2006 Ksw123.com. All rights reserved.中国考题网 版权所有