SQL Server 2005是否具有等同于MySql的ENUM数据类型? [英] Does SQL Server 2005 have an equivalent to MySql's ENUM data type?
问题描述
我正在处理一个项目,我想在表中存储一些容易枚举的信息。 MySql的枚举数据类型完全符合我的需要: http://dev.mysql .com / doc / refman / 5.0 / en / enum.html 。在SQL Server 2005中有一个等价的方法吗?
我知道我可以在一个类型表中存储键值,但我不想链接回到它的描述。我们的数据库标准不允许我们链接到非整数或唯一标识符字段,因此将可能的键存储为字符。
这对你有用吗?
从 http://blechie.com/wtilton/archive/2007/08/24/303.aspx
创建表...
MySQL:
ColumnName ENUM('upload','open','close','delete','edit','add')
/ pre>
DEFAULT'open'
SQL Server:
ColumnName varchar(10)
CHECK(ColumnName IN('upload','open','close','delete','edit','add'))
DEFAULT'open'
I'm working on a project and I want to store some easily enumerated information in a table. MySql's enum data type does exactly what I want: http://dev.mysql.com/doc/refman/5.0/en/enum.html . Is there an equivalent in SQL Server 2005?
I know I could store the possible values in a type table with a key, but I'd rather not have to link back to it for descriptions. Our database standards don't allow us to link on non-integer or uniqueidentifier fields, so storing the possible keys as characters is out as well.
解决方案Does this work for you?
From http://blechie.com/wtilton/archive/2007/08/24/303.aspx
Create table...
MySQL:
ColumnName ENUM('upload', 'open', 'close', 'delete', 'edit', 'add') DEFAULT 'open'
SQL Server:
ColumnName varchar(10) CHECK(ColumnName IN ('upload', 'open', 'close', 'delete', 'edit', 'add')) DEFAULT 'open'
这篇关于SQL Server 2005是否具有等同于MySql的ENUM数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!