1

Anyone knows how to store array or vector in ms sql server 2005? There is way to store array in oracle db but I don't know about sql server.

eg:

st_id [1234]
st_mk [(12),(34),(67),(45)]

st_id [3456]
st_mk [(12),(34)]

Like above st_mk (the vector size) is not same.

Please help me...!!

1 Answer 1

2

In a separate child table?

create table Vector(st_id int primary key)

create table VectorElement
(
    st_id int references Vector(st_id),
    element int
)

create index IX_VectorElement_st_id on VectorElement(st_id)

insert Vector
values(1234)

insert VectorElement
select 1234, 12 union all
select 1234, 34 union all
select 1234, 67 union all
select 1234, 45

Another option to store it as a string (varchar), but this is less efficient and you would need to parse it.

Another option is to use XML type column.

Sign up to request clarification or add additional context in comments.

1 Comment

I think VectorElement needs an ordinal column to maintain the order of the list elements.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.