字段的数据类型
我在表中有一个字段,我将在其中存储不同类型的数据,例如:超大、中、小...或者我可能存储:2009 年 3 月 22 日、1 年、2 年、3年...或 06 个月、12 个月、1 年,或者我可能存储:“33-36”、“37-40”...并且该数据不固定,我将来可能需要添加新类别。 ..
数据类型的明显选择是 nvarchar(length),但是还有其他建议吗? 有办法解决这个问题吗?
I have a field in a table that I will be storing different kinds of data in it, Like: X-Large, Medium, Small....or I might store: 22-March-2009, 1 Year, 2 Years, 3 Years...or 06Months, 12 Months, 1 Year, or I might store: "33-36", "37-40"...and that data is not fixed, i might need in the future to add new categories...
The obvious choice of a data type would be an nvarchar(length), but any other suggestions? is there a way to go around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
听起来你正在尝试存储“尺寸”。 也许您需要一个“大小”表,其中包含这些值(超大、中、小、1 年等)以及另一个表中的 ID 字段。
为什么你还想在同一字段中存储日期让我有点困惑。 您确定不应该有两个不同的字段吗?
预计到达时间:
根据您的评论,我建议创建几个附加表:
SizeType - 定义您正在使用的“尺码”类型(例如童装、童鞋、男鞋、女鞋、男衬衫、男裤子、女衬衫、女裤等)。 将有两列 - ID 和描述。
尺码 - 定义各个尺码(例如“尺码 5”、XL、33-34、0-6 个月等)。 将具有三列 - ID、描述以及 SizeType 中相应的 SizeType id。
现在,您可以在产品表中放置尺寸表中的 ID。 这为您在添加新尺寸、确定哪些尺寸适合哪种类型的产品等方面提供了一定的灵活性。您也可以进一步分解它以使设计变得更好,但我不想在这里让事情变得过于复杂。
Sounds like you're trying to store a "size". Maybe you need a "Size" table with those values in it (X-Large, Medium, Small, 1 Year, etc.) and an ID field that goes in the other table.
Why you would also want to store a date in the same field is a bit confusing to me. Are you sure you shouldn't have two different fields there?
ETA:
Based on your comment, I would suggest creating a couple additional tables:
SizeType - Would define the type of "size" you were working with (e.g. childrens clothing, childrens shoes, mens shoes, womens shoes, mens shirts, mens pants, womens shirts, womens pants, etc.). Would have two columns - an ID and a Description.
Size - Would define the individual sizes (e.g. "Size 5", XL, 33-34, 0-6 Months, etc.). Would have three columns - and ID, a Description, and the corresponding SizeType id from SizeType.
Now on your product table, you would put the ID from the size table. This gives you some flexibility in terms of adding new sizes, figuring out which sizes go with which type of products, etc. You could break it down further as well to make the design even better, but I don't want to overcomplicate things here.
不管你做什么,这样的数据库设计看起来都不太好。
不过,您可以使用 BLOB 数据类型将任何数据存储在列中,或者使用文本类型(如果是文本)(这样搜索会更好,了解大小写等)。
No matter what you do, such database design does not look good.
Still, you can use BLOB data type to just store any data in a column, or a Text type if it’s text (this way search will work better, understanding upper and lower case and such).
nvarchar(max) 可以工作。 否则,您可能有多个列,每种可能的类型都有一个。 这将阻止您将双精度数字等内容转换为字符串并返回。
nvarchar(max) would work. Otherwise, you might have multiple columns, one of each possible type. That would keep you from converting things like double-precision numbers into strings and back.
限制为小于的字符串
2GB。
超过 2Gb 的字符串。
二进制数据。
restricted to strings of less than
2Gb.
strings of more than 2Gb.
binary data.