ÀûÓÃ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
Ïà¹ØÎĵµ£º
֮ǰʹÓÃPLSQL£¬¶¼ÊÇÒÔдÈëÄÚÈÝΪÖ÷£¬Ð´ÈëÖÐÎÄÄÚÈÝżÓÐÂÒÂ룬µ«ÊÇÖ»ÔÚÏÔʾÉϲ¢Î´Ó°Ïì´æÈ¡£¬ËùÒÔûÓÐÔÚÒâ¡£
½ñÌìÔÚÐÞ¸ÄÒ»¸öÊÓͼʱ£¬ÐèÒª½«ÐÞ¸ÄÄÚÈݼǼÏÂÀ´£¬so,Ïëд¸öÐ޸ļǼ£¬¾Í°ÑÊÓͼÄÚÈÝ¿½±´Á˳öÏÖ£¬·¢ÏÖ¿½±´³öÏÖµÄÖÐÎÄÄÚÈݳöÏÖÂÒÂë¡£
²¢Î´ÍêÈ«ÔÚÒ⣬ÒÔΪֻҪÔÑù·Å»Øplsql¾Í»áºÃµÄ£¬µ«ÊDZ£´æÔÙÈ¡³ö·Åµ½plsqlÖз¢ÏÖÈÔ ......
ÔÚ¼ÆËã»úÖÐÊý¾ÝÓÐÁ½ÖÖÌØÕ÷£ºÀàÐͺͳ¤¶È¡£ËùνÊý¾ÝÀàÐ;ÍÊÇÒÔÊý¾ÝµÄ±íÏÖ·½Ê½ºÍ´æ´¢·½Ê½À´»®·ÖµÄÊý¾ÝµÄÖÖÀà¡£
ÔÚSQL Server ÖÐÿ¸ö±äÁ¿¡¢²ÎÊý¡¢±í´ïʽµÈ¶¼ÓÐÊý¾ÝÀàÐÍ¡£ÏµÍ³ÌṩµÄÊý¾ÝÀàÐÍ·ÖΪ¼¸´óÀ࣬Èç±í4-2 Ëùʾ¡£
ÆäÖУ¬BIGINT¡¢ SQL_VARIANT ºÍTABLE ÊÇSQL Server 2000 ÖÐÐ ......
ºÍÊý¾Ý¿â´ò½»µÀҪƵ·±µØÓõ½SQLÓï¾ä£¬³ý·ÇÄãÊÇÈ«²¿Óÿؼþ°ó¶¨µÄ·½Ê½£¬µ«²ÉÓÿؼþ°ó¶¨µÄ·½Ê½´æÔÚ×ÅÁé»îÐԲЧÂʵ͡¢¹¦ÄÜÈõµÈµÈȱµã¡£Òò´Ë£¬´ó¶àÊýµÄ³ÌÐòÔ±¼«ÉÙ»ò½ÏÉÙÓÃÕâÖְ󶨵ķ½Ê½¡£¶ø²ÉÓ÷ǰ󶨷½Ê½Ê±Ðí¶à³ÌÐòÔ±´ó¶¼ºöÂÔÁ˶Ե¥ÒýºÅµÄÌØÊâ´¦Àí£¬Ò»µ©SQLÓï¾äµÄ²éѯÌõ¼þµÄ±äÁ¿Óе¥ÒýºÅ³öÏÖ£¬Êý¾Ý¿âÒýÇæ¾Í»á±¨´íÖ¸³öSQLÓ ......
×Ó±í²éѯ£¬¸¸±íÒ»¶¨Òª¼Ó±ðÃû£¬·ñÔòÊý¾Ý»áÓÐÎÊÌ⣬²»±¨±àÒë´í
select * from table1 a where exist(select 1 from table2 where a.id=b.id)
´æ´¢¹ý³Ì½á¹û¼¯²åÈëµ½ÏÖÓбí
insert into table1 exec procname args
ÁªºÏÒÑÓÐ±í£¬½ô¸úÔÚºóÃæ£¬¶Ô»ã×ܺÜÓÐÓÃ
select a from table1 union all select 'ºÏ¼Æ'
½á¹û¼¯ÀïµÄij ......
ÊÓͼ¿ÉÒÔ±»¿´³ÉÊÇÐéÄâ±í»ò´æ´¢²éѯ¡£¿Éͨ¹ýÊÓͼ·ÃÎʵÄÊý¾Ý²»×÷Ϊ¶ÀÌØµÄ¶ÔÏó´æ´¢ÔÚÊý¾Ý¿âÄÚ¡£Êý¾Ý¿âÄÚ´æ´¢µÄÊÇ SELECT Óï¾ä¡£SELECT Óï¾äµÄ½á¹û¼¯¹¹³ÉÊÓͼËù·µ»ØµÄÐéÄâ±í¡£Óû§¿ÉÒÔÓÃÒýÓñíʱËùʹÓõķ½·¨£¬ÔÚ Transact-SQL Óï¾äÖÐͨ¹ýÒýÓÃÊÓͼÃû³ÆÀ´Ê¹ÓÃÐéÄâ±í¡£Ê¹ÓÃÊÓͼ¿ÉÒÔʵÏÖÏÂÁÐÈÎÒ»»òËùÓй¦ÄÜ£º
¡¡¡¡½«Óû§ÏÞ¶¨ÔÚ±í ......