use master
declare @dbname varchar(200)
select @dbname = 'zhengzhou_xinyinxiang'
declare @sql nvarchar(500)     
declare @spid nvarchar(20) 
declare #tb cursor   for 
select spid = cast(spid as varchar(20)) from master..sysprocesses where dbid = db_id(@dbname) 
open #tb 
fetch next from #tb into @spid 
while @@fetch_status=0 
begin     
    exec( 'kill   '+@spid) 
    fetch next from #tb into @spid 
end     
close #tb 
deallocate #tb  



SELECT * FROM TMemberCourse WHERE FTransId = 3472331387795668992
--WHERE FId NOT IN (SELECT FId FROM ZhengZhou_XinYinXiang..TMemberCourse)
WHERE FPurchaseDate >= '2015-11-12'

SELECT * FROM ZhengZhou_XinYinXiang..TMemberSaleBill WHERE FBillTime > '2015-11-12'

SELECT * FROM TUser

SELECT * FROM TMemberCardAccount WHERE FMemid = 5731815342174461721




    BACKUP LOG ZhengZhou_XinYinXiang TO disk= N'E:\ZhengZhou_XinYinXiang_Log.Bak' WITH NORECOVERY
    RESTORE DATABASE ZhengZhou_XinYinXiang FROM DISK = N'E:\SaiDao_Data_Bak\ZhengZhou_XinYinXiang\ZhengZhou_XinYinXiang_backup_201511120200.bak' WITH NORECOVERY,  REPLACE

    RESTORE LOG ZhengZhou_XinYinXiang
     FROM  DISK = N'E:\ZhengZhou_XinYinXiang_Log.Bak' 
     WITH   STOPAT = N'2015-11-12 17:25:00' , RECOVERY
     
     SELECT TOP 111 * FROM ZhengZhou_XinYinXiang_new..TBizLog WHERE FTime > '2015-11-12 17:30:55'
     ORDER BY FTime DESC
     
      SELECT TOP 111 * FROM ZhengZhou_XinYinXiang_new..TConsumeBill WHERE FBillTime > '2015-11-12 17:25:00'
     ORDER BY FBillTime DESC
 
       SELECT TOP 111 * FROM ZhengZhou_XinYinXiang_new..TMemberSaleBill WHERE FBillTime > '2015-11-12 17:25:00'
     ORDER BY FBillTime DESC

   
    INSERT TConsumeBill
    SELECT * FROM  ZhengZhou_XinYinXiang_new..TConsumeBill
    WHERE FBIllId NOT IN(SELECT FBillId FROM TConsumeBill)
    
    INSERT TConsumeItem
    SELECT * FROM  ZhengZhou_XinYinXiang_new..TConsumeItem
    WHERE FBIllId NOT IN(SELECT FBillId FROM TConsumeItem)


    INSERT TConsumeItemEmployee
    SELECT * FROM  ZhengZhou_XinYinXiang_new..TConsumeItemEmployee
    WHERE FId NOT IN(SELECT FId FROM TConsumeItemEmployee)

    INSERT TConsumeItemPayment
    SELECT * FROM  ZhengZhou_XinYinXiang_new..TConsumeItemPayment
    WHERE FId NOT IN(SELECT FId FROM TConsumeItemPayment)

    INSERT TConsumeGoods
    SELECT * FROM  ZhengZhou_XinYinXiang_new..TConsumeGoods
    WHERE FId NOT IN(SELECT FId FROM TConsumeGoods)
    
    INSERT TConsumeGoodsEmployee
    SELECT * FROM  ZhengZhou_XinYinXiang_new..TConsumeGoodsEmployee
    WHERE FId NOT IN(SELECT FId FROM TConsumeGoodsEmployee)
    
     INSERT TConsumeGoodsPayment
    SELECT * FROM  ZhengZhou_XinYinXiang_new..TConsumeGoodsPayment
    WHERE FId NOT IN(SELECT FId FROM TConsumeGoodsPayment)
   
   
    INSERT TMemberSaleBill
    SELECT * FROM  ZhengZhou_XinYinXiang_new..TMemberSaleBill
    WHERE FBillId NOT IN(SELECT FBillId FROM TMemberSaleBill)
   
    INSERT TMemberSalePayment
    SELECT * FROM  ZhengZhou_XinYinXiang_new..TMemberSalePayment
    WHERE FId NOT IN(SELECT FId FROM TMemberSalePayment)
    
    INSERT TMemberSaleEmployee
    SELECT * FROM  ZhengZhou_XinYinXiang_new..TMemberSaleEmployee
    WHERE FId NOT IN(SELECT FId FROM TMemberSaleEmployee)
    
    INSERT TMemberSaleCard
    SELECT * FROM  ZhengZhou_XinYinXiang_new..TMemberSaleCard
    WHERE FBillId NOT IN(SELECT FBillId FROM TMemberSaleCard)
    
     INSERT TMemberSaleFreeItem
    SELECT * FROM  ZhengZhou_XinYinXiang_new..TMemberSaleFreeItem
    WHERE FBillId NOT IN(SELECT FBillId FROM TMemberSaleFreeItem)   
    
     INSERT TMemberSaleDetailPayment
    SELECT * FROM  ZhengZhou_XinYinXiang_new..TMemberSaleDetailPayment
    WHERE FBillId NOT IN(SELECT FBillId FROM TMemberSaleDetailPayment)   
    
    
    INSERT TMemberCourseHist
    SELECT * FROM  ZhengZhou_XinYinXiang_new..TMemberCourseHist
    WHERE FId NOT IN(SELECT FId FROM TMemberCourseHist)   

    INSERT TMemberPointHist
    SELECT * FROM  ZhengZhou_XinYinXiang_new..TMemberPointHist
    WHERE FId NOT IN(SELECT FId FROM TMemberPointHist)   
    
    INSERT TMemberTransHist
    SELECT * FROM  ZhengZhou_XinYinXiang_new..TMemberTransHist
    WHERE FId NOT IN(SELECT FId FROM TMemberTransHist)   
    
    INSERT TMemberCardAcctHist
    SELECT * FROM  ZhengZhou_XinYinXiang_new..TMemberCardAcctHist
    WHERE FId NOT IN(SELECT FId FROM TMemberCardAcctHist)   

    INSERT TMember(FMemId,FMemNo,FName,FBriefCode,FCompId,FTypeId,FIsVisitor,FCreateDate,FGender,FBirthdayType,FBirthday,FTelephone,FMobilePhone,FQQ,FWeChat,FIdCard,FEmail,FAddress,FProId,FCPW,FQPW,FChargeEmpId,FPoint,FRecvConsSMS,FRecvBulkSMS,FMemo,FCustom1,FCustom2,FCustom3,FCustom4,FCustom5,FDeleted)
    SELECT FMemId,FMemNo,FName,FBriefCode,FCompId,FTypeId,FIsVisitor,FCreateDate,FGender,FBirthdayType,FBirthday,FTelephone,FMobilePhone,FQQ,FWeChat,FIdCard,FEmail,FAddress,FProId,FCPW,FQPW,FChargeEmpId,FPoint,FRecvConsSMS,FRecvBulkSMS,FMemo,FCustom1,FCustom2,FCustom3,FCustom4,FCustom5,FDeleted
    FROM  ZhengZhou_XinYinXiang_new..TMember
    WHERE FMemId NOT IN(SELECT FMemId FROM TMember)   
    
    INSERT TMemberCard(FCardId,FCardNo,FCardFaceNo,FTypeId,FValueType,FCompId,FMemId,FState,FCreateDate,FExpiredDate,FTotalTimes,FUsedTimes,FSaleCompId,FSaleBillId,FPaySmsFee,FMemo,FDeleted)
    SELECT FCardId,FCardNo,FCardFaceNo,FTypeId,FValueType,FCompId,FMemId,FState,FCreateDate,FExpiredDate,FTotalTimes,FUsedTimes,FSaleCompId,FSaleBillId,FPaySmsFee,FMemo,FDeleted
     FROM  ZhengZhou_XinYinXiang_new..TMemberCard
    WHERE FCardId NOT IN(SELECT FCardId FROM TMemberCard)   

    INSERT TMemberCardAccount
    SELECT * FROM  ZhengZhou_XinYinXiang_new..TMemberCardAccount
    WHERE FId NOT IN(SELECT FId FROM TMemberCardAccount)   
    
     INSERT TMemberTransHistPayment
    SELECT * FROM  ZhengZhou_XinYinXiang_new..TMemberTransHistPayment AS A
    WHERE NOT EXISTS(SELECT 1 FROM TMemberTransHistPayment AS B WHERE A.FMemId = B.FMemId AND A.FCardId = B.FCardId AND A.FTransId = B.FTransId)   
   
     INSERT TMemberTransHist
    SELECT * FROM  ZhengZhou_XinYinXiang_new..TMemberTransHist
    WHERE FId NOT IN(SELECT FId FROM TMemberTransHist)   

     INSERT TLoginSession(FSessionId,FUserType,FUserId,FCompId,FLoginTime,FLogoutTime,FLogoutType,FIPAddress,FMachineName,FClientVersion)
    SELECT FSessionId,FUserType,FUserId,FCompId,FLoginTime,FLogoutTime,FLogoutType,FIPAddress,FMachineName,FClientVersion
 FROM  ZhengZhou_XinYinXiang_new..TLoginSession
    WHERE FSessionId NOT IN(SELECT FSessionId FROM TLoginSession)   


     INSERT TBizLog(FId,FTime,FCompId,FCompNo,FUserId,FUserNo,FUserName,FFunction,FOperation,FDescription,FContentType,FContent,FIPAddress,FMachineCode,FVersion)
    SELECT FId,FTime,FCompId,FCompNo,FUserId,FUserNo,FUserName,FFunction,FOperation,FDescription,FContentType,FContent,FIPAddress,FMachineCode,FVersion
 FROM  ZhengZhou_XinYinXiang_new..TBizLog
    WHERE FId NOT IN(SELECT FId FROM TBizLog)   

     INSERT TBizLogIndex
    SELECT * FROM  ZhengZhou_XinYinXiang_new..TBizLogIndex
    WHERE FLogId NOT IN(SELECT FLogId FROM TBizLogIndex)   


  SELECT * FROM TBizLogIndex
  
  set IDENTITY_INSERT TBizLog on
   
         SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name 
     
     
     
     SELECT * FROM TMemberCardType WHERE FNo = '1209'
     
     UPDATE TMemberCardType SET FMaterial = 2 WHERE FNo = '1209'
     
     UPDATE TMemberCardAccount 
     SET FBalance = 982 
     WHERE FCardId = (SELECT FCardId FROM TMemberCard WHERE FCardNO = '60328588')
     
     SELECT * FROM TMember WHERE FMemNo = '20195988'
     SELECT * FROM TMemberCourse WHERE FMemId = 5919204463616842582
     UPDATE TMemberCourse SET FUsedPurTimes = 15  WHERE FId = 7145749179773569428
     
     SELECT * FROM TMemberCourseHist WHERE FMemId = 4718930616320664303
     
     SELECT * FROM TBKCOurse# WHERE FMemId = 5919204463616842582
     
     
     SELECT * FROM TConsumeBill WHERE FBillNo = '2021618'
     
     SELECT * FROM TConsumeItem WHERE FBillId = 5729512683432802632
     
     UPDATE TConsumeItem SET FMemCourseId = 5684858770110892750 WHERE FId IN(4700673920273706528,
5198633373349285046)
  
       UPDATE TMemberCourseHist SET FMemCourseId = 5684858770110892750 WHERE FTransDetailId IN(4700673920273706528,
5198633373349285046)
     
     UPDATE TMemberCourse SET FUsedPurTimes = 2 WHERE FId = 5684858770110892750
   
     
     UPDATE TMemberCourseHist SET F
     
     SELECT * FROM TMemberCourse WHERE FMemId = 
     4718930616320664303
     
     6501929112655625990