ɾ³ýsql serverÊý¾Ý¿âÖÐËùÓÐÊý¾Ý
Æäʵɾ³ýÊý¾Ý¿âÖÐÊý¾ÝµÄ·½·¨²¢²»¸´ÔÓ£¬ÎªÊ²Ã´ÎÒ»¹Òª¶à´ËÒ»¾ÙÄØ£¬Ò»ÊÇÎÒÕâÀï½éÉܵÄÊÇɾ³ýÊý¾Ý¿âµÄËùÓÐÊý¾Ý£¬ÒòΪÊý¾ÝÖ®¼ä¿ÉÄÜÐγÉÏ໥ԼÊø¹Øϵ£¬É¾³ý²Ù×÷¿ÉÄÜÏÝÈëËÀÑ»·£¬¶þÊÇÕâÀïʹÓÃÁË΢ÈíδÕýʽ¹«¿ªµÄsp_MSForEachTable´æ´¢¹ý³Ì¡£
Ò²ÐíºÜ¶à¶ÁÕßÅóÓѶ¼¾Àú¹ýÕâÑùµÄÊÂÇ飺ҪÔÚ¿ª·¢Êý¾Ý¿â»ù´¡ÉÏÇåÀíÒ»¸ö¿Õ¿â£¬µ«ÓÉÓÚ¶ÔÊý¾Ý¿â½á¹¹È±·¦ÕûÌåÁ˽⣬ÔÚɾ³ýÒ»¸ö±íµÄ¼Ç¼ʱ£¬É¾³ý²»ÁË£¬ÒòΪ¿ÉÄÜÓÐÍâ¼üÔ¼Êø£¬Ò»¸ö³£¼ûµÄÊý¾Ý¿â½á¹¹ÊÇÒ»¸öÖ÷±í£¬Ò»¸ö×Ó±í£¬ÕâÖÖÇé¿öÏÂÒ»°ã¶¼µÃÏÈɾ³ý×Ó±í¼Ç¼£¬ÔÙɾ³ýÖ÷±í¼Ç¼¡£
˵µÀɾ³ýÊý¾Ý¼Ç¼£¬ÍùÍùÂíÉÏ»áÏëµ½µÄÊÇdeleteºÍtruncateÓï¾ä£¬µ«ÔÚÓöµ½ÔÚÁ½¸ö»ò¶à¸ö±íÖ®¼ä´æÔÚÔ¼ÊøµÄ»°£¬ÕâÁ½¸öÓï¾ä¿ÉÄܶ¼»áʧЧ£¬¶øÇÒ×îÒªÃüµÄÊÇÕâÁ½¸öÃüÁֻÄÜÒ»´Î²Ù×÷Ò»¸ö±í¡£ÄÇôÕæÕýÓöµ½ÒªÉ¾³ýSQL ServerÊý¾Ý¿âÖÐËùÓмǼʱ£¬¸ÃÔõô°ìÄØ£¿ÓÐÁ½¸öÑ¡Ôñ£º
1.°´ÕÕÏȺó˳ÐòÖð¸öɾ³ý£¬Õâ¸ö·½·¨ÔÚ±í·Ç³£¶àµÄÇé¿öÏÂÏԵúܲ»ÏÖʵ£¬¼´±ãÊDZíÊýÁ¿²»¶à£¬µ«Ô¼Êø±È½Ï¶àʱ£¬Ä㻹ÊÇÒª»¨·Ñ´óÁ¿µÄʱ¼äºÍ¾«Á¦È¥Ñо¿Æä¼äµÄÔ¼Êø¹Øϵ£¬È»ºóÕÒ³öÏÈɾÄĸö±í£¬ÔÙɾÄĸö±í£¬×îºóÓÖɾÄĸö±í¡£
2.½ûÓÃËùÓÐÔ¼Êø£¬É¾³ýËùÓÐÊý¾Ý£¬×îºóÔÙÆôÓÃÔ¼Êø£¬ÕâÑù¾Í²»Óû¨Ê±¼äºÍ¾«Á¦È¥Ñо¿Ê²Ã´Ô¼ÊøÁË£¬Ö»ÐèÒª±àдһ¸ö¼òµ¥µÄ´æ´¢¹ý³Ì¾Í¿ÉÒÔ×Ô¶¯Íê³ÉÕâ¸öÈÎÎñ¡£
´ÓÕâÁ½¸öÑ¡ÔñÖв»ÄÑ¿´³öµÚ¶þ¸öÑ¡ÔñÊÇ×î¼òµ¥ÓÐЧµÄÁË£¬ÄÇôÔÚʹÓõڶþ¸öÑ¡Ôñʱ£¬¾ßÌå¸ÃÔõôʵʩÄØ£¿
Ê×Ïȵñàд´úÂëÑ»·¼ì²éËùÓÐµÄ±í£¬ÕâÀïÎÒÍƼöÒ»¸ö´æ´¢¹ý³Ìsp_MSForEachTable£¬ÒòΪÔÚ΢ÈíµÄ¹Ù·½ÎĵµÖÐûÓжÔÕâ¸ö´æ´¢¹ý³ÌÓÐÃèÊö£¬ºÜ¶à¿ª·¢ÈËÔ±Ò²Ðí¶¼»¹Î´ÔøÌý˵£¬ËùÒÔÄãÔÚ»¥ÁªÍøÉÏËÑË÷µÃµ½µÄ½â¾ö°ì·¨´ó¶àºÜ¸´ÔÓ£¬Ò²ÐíÓеÄÈË»áÈÏΪ£¬¼ÈȻûÓйٷ½Îĵµ£¬Õâ¸ö´æ´¢¹ý³Ì¿ÉÄܻ᲻Îȶ¨£¬´òÐÄÀíÉÏ»áÅųâËü£¬µ«ÊÂʵ²¢·ÇÈç´Ë¡£ÏÂÃæÀ´ÏÈ¿´Ò»¸öÍêÕûµÄ½Å±¾£º
CREATE PROCEDURE sp_DeleteAllData
AS
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
EXEC sp_MSForEachTable 'ALTER TABLE ? DISABLE TRIGGER ALL'
EXEC sp_MSForEachTable 'DELETE from ?'
EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
EXEC sp_MSForEachTable 'ALTER TABLE ? ENABLE TRIGGER ALL'
EXEC sp_MSFOREACHTABLE 'SELECT * from ?'
GO
Õâ¸ö½Å±¾´´½¨ÁËÒ»¸öÃüÃûΪsp_DeleteAllDataµÄ´æ´¢¹ý³Ì£¬Ç°ÃæÁ½ÐÐÓï¾ä·Ö±ð½ûÓÃÔ¼ÊøºÍ´¥·¢Æ÷£¬µÚÈýÌõÓï¾ä²ÅÊÇÕæÕýµØɾ³ýËùÓÐÊý¾Ý£¬½ÓÏÂÀïµÄÓï¾ä·Ö±ð»¹ÔÔ¼ÊøºÍ´¥·¢Æ÷£¬×îºóÒ»ÌõÓï¾äÊÇÏÔʾ
Ïà¹ØÎĵµ£º
ʹÓÃSQLÓï¾ä
SQLÓïÑÔ°üÀ¨Êý¾Ý²éѯÓïÑÔ(SELECT)¡¢Êý¾Ý²Ù×ÝÓïÑÔ(INSERT¡¢UPDATE¡¢DELETE)¡¢ÊÂÎñ¿ØÖÆÓïÑÔ(COMMIT¡¢ROLLBACK¡¢SAVEPOINT)¡¢Êý¾Ý¶¨ÒåÓïÑÔ(CREATE TABLE¡¢ALTER TABLE¡¢DROP)¡¢Êý¾Ý¿ØÖÆÓïÑÔ(GRANT¡¢REVOKE)µÈÎå¸ö²¿·Ö¡£
µ±±àдPL/SQLÓ¦ÓóÌÐòʱ£¬Ö»ÄÜÖ±½ÓǶÈëSELECT ......
C# Êý¾Ý¿âÖ®ÂÃ……
¼ÌÐø½ø¹¥²ã³ö²»ÇîµÄproblems
ÔÚÉÏһƪÄÚÈݵĻù´¡ÉÏ£¬ÎÒÓÖ×÷ÒԸĽø£¬ÏÖÔÚµÄÇé¿öÊÇÕâÑùµÄ£º
//In Browseuser form
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System ......
¿´¿´ÒÔÏÂSQLÓï¾ä£º
select row_number() over(partition by xs.xsbh, xs.kch order by coalesce(xs.bkxnxqh, xs.xnxqh) desc) rn
row_number()£º´ú±íÁÐ
partition by ´ú±í°´Ê²Ã´½øÐзÖ×é
order by¶Ôÿһ×éÐÅÏ¢½øÐÐÅÅÐò
coalesce()ÊÇÌæ»»µÄÒâ˼ ÀýÈ磺ÉÏÃæµÄSQLÓï¾äµÄÒâ˼ÊÇ£¬Èç¹ûbkxnxqhΪ¿Õ£¬ÄÇô¾ÍÈ¥xnx ......
²Ù×÷ϵͳµÄÖ§³Ö °æ±¾ºÍ·¢Ðаæ ʵÀý¡¢Êý¾Ý¿âºÍ±í¿Õ¼ä ʵÀýÃûºÍSID ϵͳÊý¾Ý¿âºÍϵͳ±í¿Õ¼ä
Ò»°ãµÄ¹«Ë¾Í¨³£»áÔÚËûÃǵÄÐÅϢϵͳ¼Ü¹¹ÖÐÒýÈë¶àÖÖÊý¾Ý¿âƽ̨£¬Í¬Ê±ÒýÈëÈýµ½ËÄÖÖ²»Í¬µÄRDBMS½â¾ö·½°¸µÄÖдóÐ͹«Ë¾Ò²²¢²»ÉÙ¼û£¬µ±È»ÕâЩ¹«Ë¾ÀïÃæµÄDBAÃÇͨ³£Ò²ÐèҪͬʱӵÓйÜÀí¶àÖÖ²»Í¬Æ½Ì¨µÄ¼¼ÄÜÁË¡£
Ö»ÔÚÒ»ÖÖƽ̨ÉÏÕ¹¿ª¹¤×÷µÄÊý¾Ý ......
Êý¾Ý¿âʵÀý½á¹¹ ÊÂÎñÒ»ÖÂÐÔ(Transactional Consistency)ºÍ»ùÓÚʱ¼äµãµÄ»Ö¸´(Point-in-time Recovery) ϵͳԪÊý¾Ý
topÊý¾Ý¿âʵÀý½á¹¹
µ±OracleʵÀýÆô¶¯Ö®ºó£¬Ëù¿´µ½µÄ¾ÍÊÇÔÚ·þÎñÆ÷ÄÚ´æÉϵÄÒ»¸ö¸ö²»Í¬ÄÚ´æ¿é¼ÓÉϲúÉúµÄÓëÕâЩÄÚ´æ½»»¥µÄºǫ́½ø³Ì¡£OracleÎĵµ½«ÕâЩÄÚ´æ½á¹¹ºÍ½ø³ÌÊյĺÜÏêϸ¡£
ÓÉOracleʵÀýËùÕ¼ÓõÄÄÚ´æ¿é³ ......