How to determine ENUM in SQL Server 2005?

Possible duplicate:
Does SQL Server 2005 have an ENUM data type equivalent for MySql & rsquo?

Is there a way to define ENUM in SQL Server 2005?

I have fixed values ​​that I need to use in procedures and functions.

+5
source share
3 answers

Use one or more scalar UDFs?

One per constant:

  • dbo.CONST_Bicycle returns 1
  • dbo.CONST_Car returns 2

One to list:

  • dbo.CONST_Types('Bicycle') returns 1
  • dbo.CONST_Types('Car') returns 2

Or use a table with an identifier, name for listing

Use client-side enumeration to match this (possibly with checking for table resolution)

, .net( ).

+5

, LuVehicle .

1,Bicycle
2,Car
3,MotorCycle

foriegn Id , .

, LuVehicle. -

select empname, vehicleId, LuVehicle.Name from employees, LuVehicle 
where employees.vehicleId = LuVehicle.Id
+1

SQL Server supports user-defined data types. You might want to do something with CREATE TYPE (Transact-SQL) . But I do not know, even if it is possible through user data types and is not aware of its pros and cons. Maybe someone else will shed more light on him.

0
source

All Articles