C# 如何在MS SQL Server 2014中创建新数据类型?
在应用程序的服务器端,我使用MS SQL server 2014 Express。在客户端,我有一个C#WPF应用程序,其中有以下枚举类型:C# 如何在MS SQL Server 2014中创建新数据类型?,c#,sql-server,tsql,C#,Sql Server,Tsql,在应用程序的服务器端,我使用MS SQL server 2014 Express。在客户端,我有一个C#WPF应用程序,其中有以下枚举类型: /// <summary> /// User authorization level. /// </summary> public enum UserAuthorizationLevel { /// <summary> /// Only visual inspection is allowed (the
/// <summary>
/// User authorization level.
/// </summary>
public enum UserAuthorizationLevel
{
/// <summary>
/// Only visual inspection is allowed (the first lower level).
/// </summary>
Inspection,
/// <summary>
/// Some settings in apparatus are allowed (the second level).
/// </summary>
SettingDeviceParametersApplied,
/// <summary>
/// Some more setting in apparatus are allowed than in the second level (the third level).
/// </summary>
Maintenance,
/// <summary>
/// Apparatus manufacturer level - full access is allowed (the highest level).
/// </summary>
Manufacturer
}
//
///用户授权级别。
///
公共枚举用户授权级别
{
///
///仅允许目视检查(第一个较低级别)。
///
检查,
///
///允许在设备中进行某些设置(第二级)。
///
设置设备参数已应用,
///
///与第二级(第三级)相比,允许在设备中进行更多的设置。
///
维修
///
///设备制造商级别-允许完全访问(最高级别)。
///
制造商
}
我是否可以在服务器端(在MS SQL server数据库中)创建此类型,并将此类型用作数据库表中字段的类型?我建议您查看以下内容: 您拥有的是枚举,而不是类型。Enum转换为Int类型。因此您将有如下内容:
/// <summary>
/// User authorization level.
/// </summary>
public enum UserAuthorizationLevel
{
/// <summary>
/// Only visual inspection is allowed (the first lower level).
/// </summary>
Inspection = 0,
/// <summary>
/// Some settings in apparatus are allowed (the second level).
/// </summary>
SettingDeviceParametersApplied = 1,
/// <summary>
/// Some more setting in apparatus are allowed than in the second level (the third level).
/// </summary>
Maintenance = 2,
/// <summary>
/// Apparatus manufacturer level - full access is allowed (the highest level).
/// </summary>
Manufacturer = 3
}
//
///用户授权级别。
///
公共枚举用户授权级别
{
///
///仅允许目视检查(第一个较低级别)。
///
检验=0,
///
///允许在设备中进行某些设置(第二级)。
///
设置设备参数应用=1,
///
///与第二级(第三级)相比,允许在设备中进行更多的设置。
///
维护=2,
///
///设备制造商级别-允许完全访问(最高级别)。
///
制造商=3
}
。SQL Server也有自己的CLR数据类型,如/。其中有关于我的SQL的内容,但我需要如何在MS SQL中实现这一点。正如我前面所说,Enum不是一种类型。可以通过两种方式实现相同的行为:1:创建查找表-和2:创建检查约束: