你会如何​​创建并在SQL数据库存储用户自定义的字段? [英] How would you create and store user-defined custom fields in a SQL database?

查看:438
本文介绍了你会如何​​创建并在SQL数据库存储用户自定义的字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要让用户有新字段添加到记录,例如如果有一个联系人记录,用户可能要添加一个SSN数字字段和一个生日日期/日历字段。他们将通过课程的用户界面做到这一点。

I need to allow users to add new fields to a record, e.g. if there is a Contact record, a user may want to add a "SSN" numeric field and a "Birthdate" date/calendar field. They would do this through the UI of course.

这些字段应该然后可用于条目所有联系人记录。

Those fields should then be available for entry for all contact records.

考虑到我的应用程序对于许多用户同时运行(而不是单个公司的部署等),理论上每个人都可以添加自己的自定义字段,这将是最好的做法,这些信息存储在数据库中,特别是当它需要要搜索的?

Considering that my application runs for many users concurrently (not a single-company deployment etc.) and theoretically everyone could add their own custom fields, what would be the best practice to store this information in a database, especially when it needs to be searchable?

推荐答案

我们几乎添加在我们所有的应用程序/产品的灵活性,给用户更多的属性/现场支持

像我们有一个产品类别,在类别,用户可以定义任何产品的附加属性

我们在做什么在数据库级别为:

分类表有这样的一些附加列:Text1Att,Text2Att ...文本价值支撑,Num1Att,Num2Att ......为数字值的支持,Date1Att,Date2Att ......对于datetime值的支持,ID1Att,ID2Att .. 。从其他表ID的支持喜欢你可以添加下拉列表,列表框,...

这里所有的列具有字符串数据类型。

我们这里保存的是


我们将在这里存储元数据信息,像Text1Att元是

SSN;文本框; 50;真,假,空;

场的字幕;控制类型,最大长度是必填字段,需要自定义验证;自定义验证消息;

出生地;文本; 100;真;真;无效值;

同样的数字字段...

日期元信息会像

出生日期,日历控件;真;真;无效的日期;

标题;是必需的;也可以是其他Calendar控件是自定义验证;自定义验证消息;




什么都在做,在产品表中添加列的相同数量和没有数据类型text1Att ..为varchar,num1Att有数字,有date1Att日期时间,ID1Att是int

We add almost in our all application/products additional attribute/field support for given flexibility to user
Like we have a product category, In the category, customer can define additional attribute of any product
what we are doing in the DB level is:
Category Table have some additional column like: Text1Att, Text2Att...for text value support, Num1Att, Num2Att... for Number value support, Date1Att, Date2Att... for datetime value support, ID1Att, ID2Att... support for ID from other table like you can add dropdown, listbox,...
here all the column have String datatype.
what we store here is

we will store meta information here, like for Text1Att meta is
SSN;textbox;50;true;false;Null;
Caption of field;Control Type;Max length;is Required field;is Custom validation required; Custom Validation message;
birth place;textbox;100;true;true;Invalid Value;
Same for Numeric field ...
for date meta information will look like
birth date;Calendar control;true;true;Invalid Date;
Caption of field; Calendar control or can be other;is required;is Custom Validation; Custom Validation message;


What are doing in product table is add same number of column and have datatype text1Att,.. is varchar, num1Att have numeric, date1Att have datetime, ID1Att have int

我们正在做的GUI一面是:在类别定义页面​​添加这些属性,并在类表运行和存储建立的元信息

,当我们定义类产品。另一方面,元信息将被读取并从类别表遍历和像其他领域的产品定义页面填充。

What we are doing GUI side is : In category definition page add these attribute and build meta information at runtime and store in category table
On the other hand when we define product in category, meta information will be read and traverse from category table and populate in product definition page like other fields.


如果u需要进一步的帮助,我可以为您提供的图像,让您可以更好地理解如何可以做到这一点。

我们的经验和分析,这是非常灵活的方法。


if u need further help, I can provide you images so that you will better understand how can be done this.
we are experience and analyze, this is much flexible approach

这篇关于你会如何​​创建并在SQL数据库存储用户自定义的字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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