Sql-server – SQL Continuous Table Updating: Best Practices

sql server

I have a highly "vertical" database, and I've written a dynamic pivot script to build a new time-indexed table that I can actually query on human time scales. Pivoting the table takes a few minutes per hour of data.

I would like to keep the new table up-to-date in an efficient way, and I was thinking of writing a script that executes every minute to pivot data, append to the new table, and delete the original entries. I want to keep the new data forever.

Are there any SQL server 2014 features/pitfalls I should be aware of, and is there a better path than the one I'm about to head down? I've only been scripting in SQL for about 48 hours now…

Thanks everyone.

Original Data:
10:30:00 A 1.0
10:30:01 A 1.1
10:30:02 A 1.2
10:30:00 B 2.1
10:30:01 B 2.3
10:30:02 B 2.5
10:30:00 C 3.4
10:30:01 C 3.3
10:30:02 C 3.2

New table:
           A    B    C
10:30:00  1.0  2.1  3.4
10:30:01  1.1  2.3  3.3
10:30:02  1.2  2.5  3.2

In this example, my question is how to deal with 10:30:03 data efficiently when it arrives.

Best Answer

This is something that I recently did with a table of mine. I used CROSS APPLY and used this page as my guide. Perhaps this can help you?