edgarmtze
edgarmtze

Reputation: 25048

Store table efficiently in array SQL Server 2008

I have a table like

a1 a2 a3 a4
-----------
1  11 21 31
2  12 22 32
3  13 23 33
4  14 24 34
5  15 25 35
6  16 26 36
7  17 27 37
8  18 28 38 
9  19 29 39
10 20 30 40

What is it the best way to store it in a c sharp array, as i am reading from sql server 2008 in a stored procedure, in COLUM MAJOR ORDER?

array = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,......40

is it better to store it like ROW MAJOR ORDER?, Which one is more efficent?

array = 1, 11, 21, 31,2,12,22,32,3,13,23,24,....10,20,30,40 

I am using

SqlDataReader rdr = null;
// create a connection object
SqlConnection conn = new SqlConnection(
"Data Source=(local);Initial Catalog=Northwind;Integrated Security=SSPI");
// create a command object
SqlCommand cmd  = new SqlCommand("select * from a1,a2,a3,a4", conn);

Upvotes: 0

Views: 369

Answers (1)

D Stanley
D Stanley

Reputation: 152566

Row major order would be easier to code since records are processed row-by-row. To store it in column major order you'd have to load all of the records into a data structure in memory (DataTable?) and loop over it for each column.

However, without knowing the purpose of storing in on one vector, if the values are in the order you show of it it's just dummy data, etc. it's hard to give a definitibe answer on what's more "efficient".

Upvotes: 1

Related Questions