简体   繁体   中英

How to create new datatype in MS SQL Server 2014?

On the server side of my application I use MS SQL Server 2014 Express. On client side I have C# WPF application and I have the following enum type there:

/// <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
}

Can I create this type on server side (in MS SQL Server database) and use this type as type for fields in database tables?

I suggest you to take a look at this: Best method to store Enum in Database

What you have is an Enum, not a type. Enum translates to the type Int. So you will have something like this:

/// <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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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