Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

ÀûÓÃsqlÓï¾ä´´½¨job

дÁËÒ»¶ÎÀý×Ó£¬Í¨¹ýsql´´½¨Ò»¸öjob£¬¶¨ÆÚÖ´ÐÐһЩÇå³ý¹¤×÷¡£ÔÚsql2005ÉϲâÊÔͨ¹ý¡£
sql°ïÖúÎĵµÌ«ÁãÉ¢ÁË¡£ÕâÊÇÒ»¸öÍêÕûµÄÁ÷³Ì¡£²»¹ý×¢ÒⶨʱִÐÐʱÐèÒªsql server agent·þÎñÆ÷Æô¶¯µÄ¡£
USE msdb ;
GO
EXEC dbo.sp_add_job
@job_name = N'Clear oldest HB',
@enabled = 1,
@description = N'Clear heartbeating data older than one month',
@notify_level_eventlog = 3;
GO
EXEC sp_add_jobstep
@job_name = N'Clear oldest HB',
@step_name = N'Clear Data',
@database_name = N'HINAMIIS',
@subsystem = N'TSQL',
@command = N'DELETE from dbo.JobTest WHERE DATEDIFF(DAY, dbo.JobTest.inserttime, GETDATE()) >=30',
@retry_attempts = 1,
@retry_interval = 5 ;
GO
EXEC sp_add_schedule
@schedule_name = N'WeeklyClearJobs' ,
@freq_type = 8,
@freq_interval = 1,
@freq_recurrence_factor = 1,
@active_start_time = 100000 ;
GO
EXEC sp_attach_schedule
@job_name = N'Clear oldest HB',
@schedule_name = N'WeeklyClearJobs' ;
GO
EXEC dbo.sp_add_jobserver
@job_name = N'Clear oldest HB'
GO


Ïà¹ØÎĵµ£º

ÄãÖªµÀ¶àÉÙ¹ØÓÚsql select top N?

±³¾°:
sql select top N Óï¾äÊÇÒ»¸ö·Ç³£ÖØÒªµÄÓï¾ä, ÔÚʵÏÖ·ÖÒ³²éѯÖÐÊDz»¿É»òȱµÄ. ÓÉÓÚ·ÖÒ³²éѯͨ³£Éæ¼°º¬ÓдóÁ¿¼Ç¼µÄ±í£¬ ²¢ÇÒÊÇΪ´óÁ¿Óû§·ÖÏíµÄÈÎÎñ£¬Òò´Ë£¬¶ÔÆä½øÐÐÓÅ»¯ÊǺÜÓÐÒâÒåµÄ¡£
ʵÏÖsql top N µÄ¹¦ÄÜÓм¸ÖÖ±äÖÖ£º
1. set rowcount @n; select ... order by somefields
2. select top (@n) .... order by ......

SQL Server°²×°Îļþ¹ÒÆð

SQL Server°²×°Îļþ¹ÒÆð:
ÔÚÖØÐ°²×°Ö÷SQLServer2000ʱ»òÊÇ´ò²¹¶¡Ê±,×ÜÊÇ»áÓöµ½SQLServer°²×°Îļþ¹ÒÆð¡£
ÔÚÔËÐд°¿ÚÊäÈëregedit£¬´ò¿ª×¢²á±í±à¼­Æ÷£¬ÔÚHKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session ManagerÖÐÕÒµ½PendingFileRenameOperations£¬É¾³ý¸Ã¼üÖµ£¨Õâ¸ö¼üÖµÊǰ²×°³ÌÐòÔݹÒÏîÄ¿£¬Ö»ÒªÕÒµ½¶ÔÓ¦µÄÓ¦Óó ......

SQL Server ÃæÊÔÌâ £¨³ÖÐø¸üÐÂÖÐ...£©

3¡£±íÄÚÈÝÈçÏÂ
¡¡¡¡-----------------------------
¡¡¡¡ID LogTime
¡¡¡¡1 2008/10/10 10:00:00
¡¡¡¡1 2008/10/10 10:03:00
¡¡¡¡1 2008/10/10 10:09:00
¡¡¡¡2 2008/10/10 10:10:00
¡¡¡¡2 2008/10/10 10:11:00
¡¡¡¡......
¡¡¡¡-----------------------------
¡¡¡¡ÇëÎʸ÷λ¸ßÊÖ£¬ÈçºÎ²éѯµÇ½ʱ¼ä¼ä¸ô²»³¬ ......

ÍÆ¼ö£ºSQL Serverµ¥ÒýºÅÁ½ÖÖ´¦Àí¼¼ÇÉ


ºÍÊý¾Ý¿â´ò½»µÀҪƵ·±µØÓõ½SQLÓï¾ä£¬³ý·ÇÄãÊÇÈ«²¿Óÿؼþ°ó¶¨µÄ·½Ê½£¬µ«²ÉÓÿؼþ°ó¶¨µÄ·½Ê½´æÔÚ×ÅÁé»îÐԲЧÂʵ͡¢¹¦ÄÜÈõµÈµÈȱµã¡£Òò´Ë£¬´ó¶àÊýµÄ³ÌÐòÔ±¼«ÉÙ»ò½ÏÉÙÓÃÕâÖְ󶨵ķ½Ê½¡£¶ø²ÉÓ÷ǰ󶨷½Ê½Ê±Ðí¶à³ÌÐòÔ±´ó¶¼ºöÂÔÁ˶Ե¥ÒýºÅµÄÌØÊâ´¦Àí£¬Ò»µ©SQLÓï¾äµÄ²éѯÌõ¼þµÄ±äÁ¿Óе¥ÒýºÅ³öÏÖ£¬Êý¾Ý¿âÒýÇæ¾Í»á±¨´íÖ¸³öSQLÓ ......

group_by·ÖÒ³(Sql Server)

×÷Õߣº°½Ê¿Î°
Ò»ÕÅÓÐgroup byºó¿ÉÄܺܶàÖØ¸´ÐУ¬ÕâʱÓÃnot inµÈ»ùÓÚΨһÁеķֲ¼Ëã·¨»á´æÔÚÎÊÌâ¡£
ÎҵĽâ¾ö°ì·¨ÊÇ£º
Ò»ÕűíÓÐÒ»¸öid intµÄÖ÷¼ü£¬¶ÔÆäËüÁнøÐÐgroup by£¬·Öҳ˼ÏëÊÇ£º°Ñmax(id)×ögroup byºóµÄΨһÁУ¬»¹ÊÇÓÃnot inµÄ·Ö²¼Ë¼Ïë¡£
Àý£º
select top 4 sum(int_TZ2_id) as id,dt_TZ2_date,vchar_TZ2_Pin ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ