SQL Server×Ô¶¯ÒìµØ±¸·Ý·½·¨ (¾«Ñ¡)
SQL×Ô¶¯ÒìµØ±¸·Ý·½·¨
·½·¨Ò»£º
mssqlÊý¾Ý¿âÔ¶³Ì±¸·ÝµÄjob
/*ÔÚÔ¶³Ì»úÆ÷²Ù×÷ϵͳµÄ¼ÆËã»ú¹ÜÀíÀィÁ¢Ò»¸öÓû§ÃûΪkyleµÄÓû§£¬ÃÜÂëΪ1234£¬Í¬Ê±ÔÚÄÇ̨»úÆ÷µÄ·ÇϵͳÅÌÀィһ¸öÃûΪbackupµÄ¹²ÏíÎļþ¼Ð£¬ÎªÁË°²È«ÁíÍâÉèÖÃÕâ¸öÎļþ¼ÐÖ»ÓÐÕâ¸ökyleÓû§¿ÉÒÔ·ÃÎÊ¡£*/
declare @sql varchar(500)
select @sql='\\10.2.0.12\backup\dbname'+'_db_'+convert(varchar(10),getdate(),112) +
substring(convert(varchar(10),getdate(),108),1,2) +'.bak'
exec master..xp_cmdshell 'net use \\10.2.0.12\backup 1234 /user:remotehost\kyle'
backup database dbname to disk=@sql --±¸·ÝÊý¾Ý¿â£¬ÕâÀïµÄ10.2.0.12ΪԶ³Ì»úÆ÷µÄip£¬remotehostΪԶ³Ì»úÆ÷µÄ»úÆ÷Ãû£¬dbnameΪ±¾µØsqlserver·þÎñÆ÷Òª±¸·ÝµÄÊý¾Ý¿â
go
declare @sql varchar(500)
select @sql='del '+'\\10.2.0.12\backup\dbname'+'_db_'+convert(varchar(10),dateadd(day,-7,getdate()),112) +
substring(convert(varchar(10),dateadd(day,-7,getdate()),108),1,2) +'.bak'
exec master..xp_cmdshell @sql --ɾ³ý7ÌìÇ°µÄ±¸·Ý£¬Ò²¾ÍÊÇÖ»±£Áô7¸ö×îб¸·Ý
go
·½·¨¶þ£º
ÓÃSQL×Ô´øµÄschedule¶¨Ê±°ÑÊý¾Ý¿âbackupÉúÎļþ£¬ÓÃwindowsµÄ¼Æ»®ÈÎÎñ¶¨Ê±copyÎļþµ½ÆäËü»úÆ÷£¬ÔÙÓÃSQL×Ô´øµÄschedule¶¨Ê±°ÑÎļþrestore³ÉÊý¾Ý¿â¡£
Èç¹û´ÓÊý¾ÝÔ´»úÆ÷µÄEnterprise ManagerÖпÉÒÔ¿´µ½»òÌí¼Ó×¢²áÄ¿±êÊý¾Ý¿âµÄ»°£¨¼´¿ª·ÅÁË1433¶Ë¿Ú£©£¬¿ÉÒÔÑ¡ÔñÓõ¼³ö¹¦ÄÜ£¬ÔÚDTS wizardÖÐÑ¡ºÃÔ´Êý¾Ý¿âºÍÄ¿±êÊý¾Ý¿â£¬Ñ¡ÖÐÔ´Êý¾Ý¿âÖÐËùÓÐ±í£¬²¢¼ÇµÃÅäÖÃÿ¸ö±íµÄtransformÏîΪ“Çå¿ÕÄ¿±ê±í”£¬ÓÐ×ÔÔö³¤×ֶεĻ°ÒªÑ¡“ÔÊÐíÌí¼Ó×ÔÔö³¤×ֶΔ£¬½ÓÏÂÀ´ÒªÑ¡¶¨ÆÚÖ´Ðв¢Ñ¡ºÃ¼Æ»®£¬¾ÍOKÁË¡£
all taskÖÐÑ¡backupµÄʱºò£¬×îÏÂÃæÓÐÒ»Ïî¾ÍÊÇschedule
ÓÒ¼üµã»÷ÄãÒª±¸·ÝµÄÊý¾Ý¿â£¬µ¯³ö²Ëµ¥ÖÐÑ¡“ËùÓÐÈÎÎñ”Öеē±¸·ÝÊý¾Ý¿â”£¬×îÏÂÃæÑ¡ÖГ¼Æ»®±í”È»ºó¾Í¿ÉÒÔÉèÖö¨ÆÚÔËÐеģ¬Èç¹ûÄãµÄÊý¾Ý¿âÓõÄÊÇȱʡµÄÍêÈ«»Ö¸´Ä£Ê½£¬Ñ¡²îÒ챸·ÝÓ¦¸ÃÊDZȽϺÏÀíµÄÑ¡Ôñ£¬ÕâÑù±¸·ÝËÙ¶È×î¿ì¡£
·½·¨Èý£º
ÏÈ˵һÏÂ˼·£¬¾ÍÊÇÔÚ·þÎñÆ÷Éϱ¸·ÝÉú³ÉÎļþºó£¬ÔÙͨ¹ýDOSÃüÁ´ËÎļþCOPYµ½Áíһ̨µçÄÔ¡£
ÏÈÔÚ·þÎñÆ÷ÉÏÔËÐÐÊý¾Ý¿â±¸·Ý¡£
È»ºóÔÚÒìµØ»úÉϹ²ÏíÒ»¸öÎļþ¼Ð£¬×öΪ·þÎñÆ÷ÉϵÄÒ»¸öÓ³ÉäÍøÂçÇý¶¯Æ÷¡£
½«ÎļþCOPYµ½Õâ¸öÎļþ¼Ð¾ÍËãÍêÊÂÁË£¬µ«ÊÇÒªÔõôʵÏÖ×Ô¶¯²¢ÇÒ¶¨Ê±COPYÄØ£¿
¾ÍÓÃDOSÃüÁîÀ´ÊµÏÖ×
Ïà¹ØÎĵµ£º
ÎÊÌâÃèÊö£ºÓÐÒÔÏÂ2ÕÅ±í£¬
±íA
0_id 0_name 0_Salary
Y2007001 ´ï¸ç &nbs ......
Create PROCEDURE [dbo].[ChangeObjectOwner]
@OldOwner as NVARCHAR(128),
@NewOwner as NVARCHAR(128)
AS
DECLARE @Name as NVARCHAR(128)
DECLARE @Owner as NVARCHAR(128)
DECLARE @OwnerName as NVARCHAR(128)
DECLARE curObject CURSOR FOR
select 'Name' = name,
'Owner'&n ......
SQL Server ÒÑ·â鎖Ôª¼þ 'xp_cmdshell' µÄ ³ÌÐò 'sys.xp_cmdshell'
Ö®´æÈ¡£¬Òò為´ËÔª¼þÒÑ經ÓÉ´ËËÅ·þÆ÷µÄ°²È«ÐÔ組態關閉¡£Ïµ統¹ÜÀí員¿ÉÒÔʹÓà sp_configure 來啟Óà 'xp_cmdshell'
µÄʹÓá£ÈçÐèÓÐ關啟Óà 'xp_cmdshell' µÄ詳಄ ......
Ò»¡¢ÈçºÎ´ÓselectµÄ²éѯ½á¹ûÖÐÔÙ´ÎÔËË㣿
µÚÒ»²½£º
´Ö²éѯ¡£Ê×ÏÈÐèÒª½«µÚÒ»²ã²éѯŪ¶Ô£¬¹ØϵŪÇå³þ¡£
select sum(quantity) total ,price_water,price_pollute from pay_water where time_pay >='2010-02-01 00:00:00.000' and time_pay <'2010-02-28 23:59:59.000'
group by price_water,price_pollute
µÚ¶þ²½ ......
1¡¢SessionÓÐʲôÖØ´óBUG£¬Î¢ÈíÌá³öÁËʲô·½·¨¼ÓÒÔ½â¾ö£¿
´ð£ºÊÇiisÖÐÓÉÓÚÓнø³Ì»ØÊÕ»úÖÆ£¬ÏµÍ³·±Ã¦µÄ»°Session»á¶ªÊ§£¬¿ÉÒÔÓÃSate server»òSQL ServerÊý¾Ý
¿âµÄ·½Ê½´æ´¢Session²»¹ýÕâÖÖ·½Ê½±È½ÏÂý£¬¶øÇÒÎÞ·¨²¶»ñSessionµÄENDʼþ¡£
2.²úÉúÒ»¸öintÊý×飬³¤¶ÈΪ100£¬²¢ÏòÆäÖÐËæ»ú²åÈë1-100£¬²¢ÇÒ²»ÄÜÖظ´¡£
C# ......