Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Ali Reza Pooneh
Starting Member
14 Posts |
Posted - 2009-11-09 : 01:26:29
|
Hi all,I have a table that insert records in it about 10 per second! One of columns is in DateTime format and another is Value that change more and more per second.--------------------------------------1.If I want to get last n records(10 or 100 or 1000) from this table,Which is better? order DateTime column and get TOP(n); or add Id column that is Identity column and add automatically and select TOP(n) records by order Id column?Notice that inserting data and get them perform more and more in a second!---------------------------------------2.I want to sample data from this table by proccess Time section of DateTime column. An example for explain more:Id DateTime Value============================================512 2009.1.1-05:29:52 2.24513 2009.1.1-05:29:59 2.53514 2009.1.1-05:30:01 2.44515 2009.1.1-05:30:02 2.68516 2009.1.1-05:30:05 2.86...522 2009.1.1-05:59:59 2.44523 2009.1.1-06:00:00 2.53524 2009.1.1-06:00:00 4.23525 2009.1.1-06:00:01 2.68526 2009.1.1-06:00:02 4.86...536 2009.1.1-06:00:58 4.86537 2009.1.1-06:01:02 4.86I want to sample first record that insert in per hour, per half an hour, per minute, and ...In example and run in half an hour, select must be return records:514 and 523.If run it for per hour, return only record:523.and If run for per minute, return:514,523,537.For more, I want to get first record that inserted in defined timeframe(1Min,30Min,60Min,...)Hope to explain simple to understand all.-------------------------------------------3.Can you help me for more performance and speed in this table? Another definition or indexing or ... that insert and select run by best performance.-------------------------------------------4. Thanks more! |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-11-09 : 10:37:51
|
1. i think former is better2.something likeCREATE PROC SampleData@Interval intASSELECT columnsFROM (SELECT ROW_NUMBER OVER(PARTITION BY DATEADD(mi,(DATEDIFF(mi,0,DateTime)/@Interval) * @Interval,0) ORDER BY DateTime) AS Seq,*FROM YourTable)tWHERE t.Seq=1GOthen execute asEXEC SampleData 1 for minuteEXEC SampleData 30 for halfhourEXEC SampleData 60 for hour,... |
 |
|
|
|
|
|
|
|