开发者

variable length field in Database

Is there any way to store variable length list into databa开发者_StackOverflowse in SQL or any other database engine ??

Here list means no. of elements in the array. For e.g. an array of numbers.

But in my actual application things to be stored are objects and hence cannot be stored simply as comma separated list.


Some SQL databases support the ARRAY type as the type of a column. An ARRAY is variable length and can hold objects of the same type. See details below which apply to databases that support the SQL Standard:

http://hsqldb.org/doc/2.0/guide/sqlgeneral-chapt.html#N106FE


One Table:

Id (PK), ListItem varchar(255), ListId (int) - ListId is unique to each list and you use that to grab all items on the list, you could add additional columns for ordering if you wanted.

Two Tables

List (Table) -ListId (pk) -ListTitle varchar(255)

Item (Table) -ItemId (pk) -ListId (fk -> List.ListId) -ItemName varchar(255) -Order (int) - for ordering


How about 2 tables, with linked 1 to many references?

Or if you are refering to a single column in a ro, use seperated (comma) strings?


You can make the use of length function for calculating the length of the variable and the while inserting that variable Insert the length along with it... Thats it.

hAPPY cODING...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜