简体   繁体   中英

transform rows into columns in a sql table

Supose I would like to store a table with 440 rows and 138,672 columns, as SQL limit is 1024 columns I would like to transform rows into columns, I mean to convert the 440 rows and 138,672 columns to 138,672 rows and 440 columns.

Is this possible?

SQL Server limit is actually 30000 columns, see Sparse Columns .

But creating a query that returns 30k columns (not to mention +138k) will be basically uncontrollable, the sheer size of the metadata on each query result would halt the client to a crawl. One simply does not design databases like that. Go back to the drawing board, when you reach 10 columns stop and think, when you reach 100 column erase the board and start anew.

And read this: Best Practices for Semantic Data Modeling for Performance and Scalability .

The description of the data is as follows....

Each attribute describes the measurement of the occupancy rate (between 0 and 1) of a captor location as recorded by a measuring station, at a given timestamp in time during the day. The ID of each station is given in the stations_list text file.

For more information on the location (GPS, Highway, Direction) of each station please refer to the PEMS website.

There are 963 (stations) x 144 (timestamps) = 138,672 attributes for each record.

This is perfect for normalision.

You can have a stations table and a measurements table. Two nice long thin tables.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM