• This is what I posted on the MS forum for SQL Server in response to this column:

     

    I think enums would be a great feature to add to SQL. I would think they would work best like a custom datatype.

    Something like this:

    exec sp_addenum 'Visa', 0, 'PaymentType'

    exce sp_addenum 'MasterCard', 1, 'PaymentType'

    exec sp_addenum 'Amex', 5, 'PaymentType'

    Then you would use it in a table as:

    create table Orders (

    OrderID bigint not null identity(1,1),

    CustomerID bigint not null,

    PaymentMethod PaymentType not null

    )

    The underlying datatype should be a bigint - allowable to be compared to other integer values so that they could be passed in from other sources.

    Then in queries like suggested:

    select * from Orders where PaymentMethod in (PaymentType.Visa, PaymentType.MasterCard)

    The question would be is something like this allowed?

    select * from Orders where PaymentMethod = Shipping.UPS

    I think it should be prohibited. Either a constant (PaymentMethod = 1) or a valid enum type (PaymentMethod = PaymentType.Visa) or a variable (PaymentMethod = @PaymentType) should be accepted.

    This would hopefully at least prevent people from writing the PaymentMethod = Shipping.UPS code.

    Ad maiorem Dei gloriam