SQL Server equivalente a MySQL enum tipo de datos?
¿SQL Server 2008 tiene un tipo de datos como MySQL enum
?
5 answers
No lo hace. Hay un equivalente vago:
mycol VARCHAR(10) NOT NULL CHECK (mycol IN('Useful', 'Useless', 'Unknown'))
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-09-16 17:19:25
La mejor solución que he encontrado en esto es crear una tabla de búsqueda con los valores posibles como clave primaria, y crear una clave foránea para la tabla de búsqueda.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-06-21 12:53:33
Las tablas de búsqueda de IMHO son el camino a seguir, con integridad referencial. Pero solo si evitas "Números Mágicos Malvados" siguiendo un ejemplo como este: Generar enumeración a partir de una tabla de búsqueda de base de datos utilizando T4
Diviértete!
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-08-01 12:36:54
CREATE FUNCTION ActionState_Preassigned()
RETURNS tinyint
AS
BEGIN
RETURN 0
END
GO
CREATE FUNCTION ActionState_Unassigned()
RETURNS tinyint
AS
BEGIN
RETURN 1
END
-- etc...
Donde el rendimiento importa, todavía utilice los valores duros.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-02-23 22:28:08
Encontré este enfoque interesante cuando quise implementar enumeraciones en SQL Server.
El enfoque mencionado a continuación en el enlace es bastante convincente, teniendo en cuenta que todas las necesidades de enumeración de su base de datos podrían satisfacerse con 2 tablas centrales.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-08-27 08:16:54