Author |
Topic |
raysefo
Constraint Violating Yak Guru
260 Posts |
Posted - 2006-08-02 : 15:35:05
|
Hi,I wanna know if there is an option (I m using MS SQL Server 2000) to tell the server, run the transaction using RAM?thanks |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-08-02 : 15:43:38
|
SQL Server will handle this for you. What is the query that you have in mind?Tara Kizer |
 |
|
raysefo
Constraint Violating Yak Guru
260 Posts |
Posted - 2006-08-02 : 15:54:07
|
Hi,I have a several tables, each have approx. 40000000 row of datas. When i do some select, insert and update (in a single SP) it takes too much time, 3-4 hours. and i think its using hard disk instead of RAM, thats why it takes too long. Sometimes, it gives error, there is no disk space. Is there a way to make it much more faster? Any suggestions...thanks |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-08-02 : 15:56:12
|
You'd have to post your queries, SQL Server 2000 service pack level, and your hardware config in order for us to help you make it faster.Tara Kizer |
 |
|
raysefo
Constraint Violating Yak Guru
260 Posts |
Posted - 2006-08-02 : 16:15:21
|
hi,How do i get the service pack level? |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-08-02 : 16:19:54
|
SELECT @@VERSIONTara Kizer |
 |
|
raysefo
Constraint Violating Yak Guru
260 Posts |
Posted - 2006-08-02 : 16:38:29
|
Hi,Here is my SP. What i wanna do here is, i have a huge table as i mentioned before. There is a date time field fTime, but seconds are missing, thats why there are duplicate datas. I wanna add seconds to fTime column. heres my code below;ALTER Procedure Addseconds ASdeclare @time datetimedeclare @SQL_INS varchar(1000)SELECT @SQL_INS = 'CREATE TABLE [TEMP1] ('SELECT @SQL_INS = @SQL_INS + '[xID] [int] NULL , [fTime] [datetime] NULL ) ON [PRIMARY]'Exec (@SQL_INS)DECLARE table_create CURSOR FORselect DISTINCT(fTime) from [USD/BEF1] order by fTime ASCDECLARE @ftime datetimeDECLARE @xid intDECLARE @diff intDECLARE @interval intDECLARE @intervalms intDECLARE @count intDECLARE @temp intDECLARE @x intSET @count = 1OPEN table_createFETCH NEXT FROM table_create into @timeWHILE @@FETCH_STATUS = 0BEGIN DECLARE time_count CURSOR FOR select fTime,xID from [USD/BEF1] where fTime =@time group by fTime,xID OPEN time_count FETCH NEXT FROM time_count INTO @ftime,@xid WHILE @@FETCH_STATUS = 0 BEGIN INSERT INTO [TEMP1] VALUES (@xid,@ftime) FETCH NEXT FROM time_count INTO @ftime,@xid END CLOSE time_count DEALLOCATE time_count SET @temp = (SELECT count(xID) FROM [TEMP1]) DECLARE rep_count CURSOR FOR select fTime,xID from [USD/BEF1] where fTime =@time group by fTime,xID OPEN rep_count FETCH NEXT FROM rep_count INTO @ftime,@xid SET @diff = @temp - 2 IF (@diff > 0 ) BEGIN SET @intervalms = 60000/(@temp) SET @interval = 1 SET @x = @intervalms END WHILE @@FETCH_STATUS = 0 BEGIN IF(@temp=2) BEGIN IF(@count = 1) BEGIN UPDATE [USD/BEF1] SET fTime = @ftime WHERE xID = @xid END ELSE IF(@count > 1) BEGIN UPDATE [USD/BEF1] SET fTime = (SELECT DATEADD(ss,59,@ftime)) WHERE xID = @xid END SET @count = @count +1 END IF(@temp>2) BEGIN IF(@count = 1) BEGIN UPDATE [USD/BEF1] SET fTime = @ftime WHERE xID = @xid END ELSE IF(@count > 1 AND @count < @temp) BEGIN UPDATE [USD/BEF1] SET fTime = (SELECT DATEADD(ss,@interval,@ftime)) WHERE xID = @xid UPDATE [USD/BEF1] SET fTime = (SELECT DATEADD(ms,@intervalms,@ftime)) WHERE xID = @xid SET @intervalms = @intervalms + @x END ELSE IF(@count = @temp) BEGIN UPDATE [USD/BEF1] SET fTime = (SELECT DATEADD(ss,59,@ftime)) WHERE xID = @xid END SET @count = @count +1 IF (@intervalms >= 1000) SET @interval = @interval + 1 END FETCH NEXT FROM rep_count INTO @ftime,@xid END CLOSE rep_count DEALLOCATE rep_count SET @count = 1 DELETE [TEMP1] FETCH NEXT FROM table_create INTO @timeENDDROP TABLE [TEMP1]CLOSE table_createDEALLOCATE table_create |
 |
|
raysefo
Constraint Violating Yak Guru
260 Posts |
Posted - 2006-08-02 : 16:39:10
|
Microsoft SQL Server 2000 - 8.00.760 (Intel X86) Dec 17 2002 14:22:05 Copyright (c) 1988-2003 Microsoft Corporation Desktop Engine on Windows NT 5.1 (Build 2600: Service Pack 2) |
 |
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2006-08-03 : 04:26:44
|
Would you mind wrapping your procedure with [ code ] [ /code ] tags plz...--Lumbago"Real programmers don't document, if it was hard to write it should be hard to understand" |
 |
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2006-08-03 : 05:01:59
|
Never mind...I'm quite bored at work today so I did it myself. And I must say that I'm not the least bit surprised that this takes 3-4 hours. Cursors by themselves are considered horrible for performance and having several nested cursors will just kill you server running on a table with 40 mill records. You should really read up on set based programming...consider these two pieces of code:UPDATE mytable SET mydatefield = DATEADD(ss, 3, mydatefield)DECLARE mycursor CURSOR FOR SELECT ID FROM mytableOPEN mycursorFETCH NEXT FROM mycursor INTO @IDWHILE @@FETCH_STATUS = 0 BEGIN UPDATE mytable SET mydatefield = DATEADD(ss, 3, mydatefield) WHERE ID = @ID FETCH NEXT FROM mycursor INTO @ID END These two statements do *exactly* the same thing however the first one performs so much better you wouldn't belive it. The main difference is that the first one does everything in one go at the same time, while the other one updates the table one row at a time. This is a very important consept to grasp and it will take you some time to master it but by spending a few active months here on sqlteam you'll get quite far! We have all been there...some of the pro's here just don't want to admit it. --Lumbago"Real programmers don't document, if it was hard to write it should be hard to understand" |
 |
|
Lumbago
Norsk Yak Master
3271 Posts |
|
raysefo
Constraint Violating Yak Guru
260 Posts |
Posted - 2006-08-03 : 08:25:04
|
Well,thanks for replies. But what i m trying to do is, distribute the seconds and miliseconds evenly into those duplicate datetime fields based on 1 minute. Shortly, the first datetime value should get 00:000 and the last duplicate datetime should get 59:000 value. Between those 2 values, there gonna be evenly distributed seconds and mili seconds.sample which was done with the code i sent earlier above.2005-09-22 07:38:00.000 33.2200 12005-09-22 07:38:00.847 33.2000 22005-09-22 07:38:01.690 33.2000 32005-09-22 07:38:02.537 33.2000 42005-09-22 07:38:03.380 33.2100 52005-09-22 07:38:04.227 33.2000 62005-09-22 07:38:05.070 33.2200 72005-09-22 07:38:05.917 33.2100 82005-09-22 07:38:06.760 33.2200 92005-09-22 07:38:07.607 33.2100 102005-09-22 07:38:08.450 33.2100 112005-09-22 07:38:09.297 33.2000 122005-09-22 07:38:10.140 33.2200 132005-09-22 07:38:10.987 33.2100 142005-09-22 07:38:11.830 33.1900 152005-09-22 07:38:12.677 33.2100 162005-09-22 07:38:13.520 33.1900 172005-09-22 07:38:14.367 33.2200 182005-09-22 07:38:15.210 33.2100 192005-09-22 07:38:16.057 33.2200 202005-09-22 07:38:16.900 33.2100 212005-09-22 07:38:17.747 33.1900 222005-09-22 07:38:18.590 33.2100 232005-09-22 07:38:19.437 33.2200 242005-09-22 07:38:20.280 33.2200 252005-09-22 07:38:21.127 33.2100 262005-09-22 07:38:21.970 33.2300 272005-09-22 07:38:22.817 33.2100 282005-09-22 07:38:23.660 33.2200 292005-09-22 07:38:24.507 33.2300 302005-09-22 07:38:25.350 33.2100 312005-09-22 07:38:26.197 33.2000 322005-09-22 07:38:27.040 33.2100 332005-09-22 07:38:27.887 33.2100 342005-09-22 07:38:28.730 33.2200 352005-09-22 07:38:29.577 33.2100 362005-09-22 07:38:30.420 33.2000 372005-09-22 07:38:31.267 33.2200 382005-09-22 07:38:32.110 33.2200 392005-09-22 07:38:32.957 33.2200 402005-09-22 07:38:33.800 33.2100 412005-09-22 07:38:34.647 33.2100 422005-09-22 07:38:35.490 33.2100 432005-09-22 07:38:36.337 33.2000 442005-09-22 07:38:37.180 33.1900 452005-09-22 07:38:38.027 33.2200 462005-09-22 07:38:38.870 33.2000 472005-09-22 07:38:39.717 33.2100 482005-09-22 07:38:40.560 33.2200 492005-09-22 07:38:41.407 33.2100 502005-09-22 07:38:42.250 33.2000 512005-09-22 07:38:43.097 33.2100 522005-09-22 07:38:43.940 33.2000 532005-09-22 07:38:44.787 33.2100 542005-09-22 07:38:45.630 33.2000 552005-09-22 07:38:46.477 33.2100 562005-09-22 07:38:47.320 33.2100 572005-09-22 07:38:48.167 33.2100 582005-09-22 07:38:49.010 33.2300 592005-09-22 07:38:49.857 33.2100 602005-09-22 07:38:50.700 33.2100 612005-09-22 07:38:51.547 33.2100 622005-09-22 07:38:52.390 33.2200 632005-09-22 07:38:53.237 33.2100 642005-09-22 07:38:54.080 33.2100 652005-09-22 07:38:54.927 33.2200 662005-09-22 07:38:55.770 33.2000 672005-09-22 07:38:56.617 33.2000 682005-09-22 07:38:57.460 33.2200 692005-09-22 07:38:58.307 33.2000 702005-09-22 07:38:59.000 33.2000 71As you see, there were 71 duplicate datetime datas. I exactly wanna do this algorithm much more faster. |
 |
|
|