存储阵列中的SQL Server 2008 [英] Store array in SQL Server 2008

查看:111
本文介绍了存储阵列中的SQL Server 2008的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发使用SQL Server 2008(基于服务的数据库)的联系人管理器应用程序。大部分联系人有多个电子邮件或多个电话号码。那么,有没有存储数组作为SQL Server中的数据类型的方法吗?或者有没有人有这样的选择吗?

I am developing a contact manager application using SQL Server 2008 (service-based database) . Most contacts have several emails or several phone numbers. So is there a way to store an array as a datatype in SQL Server? Or does anyone have an alternative to this way?

推荐答案

您需要创建单独的表,每个联系人号码一行或电子邮件地址。

You'll want to create separate tables, with a row per contact number or email address.

CREATE TABLE Contacts (contactId int, name varchar(128), etc, etc
CREATE TABLE ContactEmail (contactId int, emailAddress varchar(128), etc
CREATE TABLE ContactPhone (contactId int, phoneNumber varchar(128), etc

这将允许你修改个人号码/电子邮件,删除它们,将它们添加等,而不需要外部程序来解压的数组。

This will allow you to modify individual numbers/emails, remove them, add them, etc, without requiring an external program to unpack an array.

但如果你真的要存储它规格化,你可以在阵列转变成分隔的字符串。把每个电子邮件地址之间的分隔符(用适当的法宝,以确保地址尚未包含分隔符),然后它分裂的道路上退了出去。

But if you really want to store it denormalized, you could transform the array into a delimited string. . put a delimiter between each email address (with the appropriate magic to make sure an address doesn't already contain the delimiter) then split it on the way back out.

这篇关于存储阵列中的SQL Server 2008的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆