程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> SqlServer數據庫 >> 關於SqlServer >> SQLSERVER數據庫升級腳本圖文步驟

SQLSERVER數據庫升級腳本圖文步驟

編輯:關於SqlServer

只能遠程協助的方式。我特意做了一個腳本,用電話指導客戶在SSMS裡執行一下腳本就可以了

1.0的數據庫跟1.1的數據庫的區別是1.1的數據庫裡的其中一個[CT_OuterCard]表比1.0的多了6個字段,其他所有表都一樣

還有存儲過程增加了很多,其他都沒有改變

首先,先在公司的服務器數據庫上生成存儲過程腳本,數據庫是1.1版本的,下面的圖片裡沒有說明的,都是默認設置,下一步即可

選中數據庫-》右鍵—》任務-》生成腳本

當然,如果你的數據庫裡有自定義函數的話,也可以勾選函數,如果我們的數據庫沒有函數,所以。。。

保存到新建查詢窗口

這一步做完了,然後編寫下面的SQL腳本

復制代碼 代碼如下:
--升級GPOS1.0到GPOS1.1數據庫的升級腳本 2013-7-4
USE [GPOSDB]
GO
------------------刪除所有存儲過程-------------------
--select * from sys.procedures

declare @sql varchar(4000)
set @sql=''
select @sql=@sql+'drop proc '+name+';   ' from sys.procedures
--print @sql
exec(@sql)

--------------------------------在[CT_OuterCard]表添加6個字段-------------------------------
ALTER TABLE [dbo].[CT_OuterCard] ADD [I_LimitTransCurrCount] INT  NOT NULL CONSTRAINT [DF_CT_OuterCard_I_LimitTransCurrCount]  DEFAULT ((0))
ALTER TABLE [dbo].[CT_OuterCard] ADD [I_LimitTransType] [int] CONSTRAINT [DF_CT_OuterCard_I_LimitTransType]  DEFAULT ((0))
ALTER TABLE [dbo].[CT_OuterCard] ADD [DE_LimitTransTotal] [decimal](18, 2) NOT NULL CONSTRAINT [DF_CT_OuterCard_DE_LimitTransTotal]  DEFAULT ((0))
ALTER TABLE [dbo].[CT_OuterCard] ADD [DE_LimitTransCurrTotal] [decimal](18, 2) NOT NULL CONSTRAINT [DF_CT_OuterCard_DE_LimitTransCurrTotal]  DEFAULT ((0))
ALTER TABLE [dbo].[CT_OuterCard] ADD [I_LimitCarNo] [int] NOT NULL CONSTRAINT [DF_CT_OuterCard_I_LimitCarNo]  DEFAULT ((0))
ALTER TABLE [dbo].[CT_OuterCard] ADD [D_LimitDate] [datetime] NOT NULL CONSTRAINT [DF_CT_OuterCard_D_LimitDate]  DEFAULT (getdate())
--------------------------------------------------------------------------------------------------------------
--把剛才在新建查詢窗口裡生成的存儲過程腳本粘貼到下面
---------------------------創建GPOS1.1的所有存儲過程---------------------------------------------
USE [GPOSDB]
GO
/****** 對象:  StoredProcedure [dbo].[Report_GreaserSaleStat]    腳本日期: 07/04/2013 13:27:09 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO


CREATE PROC [dbo].[Report_GreaserSaleStat]
@StartDate datetime,
@EndDate datetime,
@Action int --0為交易記錄,1為班次記錄

   
            insert into #tmpCardAmoutStat
                (
                    VC_OC_CardNO,

            set @i=@i+1
        end

        truncate table #tmpCards
        insert into #tmpCards(VC_OC_CardNO)
        select VC_OC_CardNO from CT_OuterCard where isnull(VC_OC_Company,'')=''
        set @j=1
        select @cardcount=count(*) from #tmpCards
        while @j<=@cardcount
        begin
            select @VC_OC_CardNO=VC_OC_CardNO from #tmpCards where  IndexId=@j
            insert into #tmpCardAmoutStat
                (
                    VC_OC_CardNO,
       

        insert into #tmpCardAmoutStat
            (
                VC_OC_CardNO,
                CompanyName,
                VC_OC_UserName,
                StartAmount,
                FillMoney,
                ConsumeSumVol,
                ConsumeMoney,
                SumConsumeSumVol,
                SumConsumeMoney,
                SumFillMoney

            )
        select
            null,
            null,
            '客戶卡小計',
            sum(StartAmount),
            sum(FillMoney),
            sum(ConsumeSumVol),

        truncate table #tmpCards
        insert into #tmpCards(VC_OC_CardNO)
        select VC_IC_CardNO from CT_InhouseCard where isnull(VC_IC_CardNO,'')<>''
        set @j=1
        select @cardcount=count(*) from #tmpCards
        while @j<=@cardcount
        begin
            select @VC_OC_CardNO=VC_OC_CardNO from #tmpCards where  IndexId=@j
            insert into #tmpCardAmoutStat
                (
                    VC_OC_CardNO,
                    CompanyName,
                    VC_OC_UserName,
                    StartAmount,
                    FillMoney,
                    ConsumeSumVol,
                    ConsumeMoney,
                    SumConsumeSumVol,
                    SumConsumeMoney,
                    SumFillMoney

                )
            select
                @VC_OC_CardNO,
                '員工卡',
                isnull((select VC_IC_UserName from CT_InhouseCard where VC_IC_CardNO=@VC_OC_CardNO),''),
                isnull((select top 1 DE_FD_Amount from CT_FuelingData where VC_FD_Cardno=@VC_OC_CardNO and (D_FD_DateTime<=@StartDate) order by D_FD_DateTime desc),0),
                isnull((select sum(DE_A_AppendAmount) from CT_Append where VC_A_CardNO=@VC_OC_CardNO and (D_A_AppendDateTime between @StartDate and @EndDate)),0),
                isnull((select sum(DE_FD_Volume) from CT_FuelingData where VC_FD_Cardno=@VC_OC_CardNO and (D_FD_DateTime between @StartDate and @EndDate)),0),
                isnull((select sum(DE_FD_Amount) from CT_FuelingData where VC_FD_Cardno=@VC_OC_CardNO and (D_FD_DateTime between @StartDate and @EndDate)),0),
                isnull((select sum(DE_FD_Volume) from CT_FuelingData where VC_FD_Cardno=@VC_OC_CardNO),0),
                isnull((select sum(DE_FD_Amount) from CT_FuelingData where VC_FD_Cardno=@VC_OC_CardNO),0),
                isnull((select sum(DE_A_AppendAmount) from CT_Append where VC_A_CardNO=@VC_OC_CardNO),0)
            set @j=@j+1
        end

        insert into #tmpCardAmoutStat
            (
                VC_OC_CardNO,
                CompanyName,
                VC_OC_UserName,
                StartAmount,
                FillMoney,
                ConsumeSumVol,
                ConsumeMoney,
                SumConsumeSumVol,
                SumConsumeMoney,
                SumFillMoney

            )
        select
            null,
            null,
            '員工卡小計',
            sum(StartAmount),
            sum(FillMoney),
            sum(ConsumeSumVol),
            sum(ConsumeMoney),
            sum(SumConsumeSumVol),
            sum(SumConsumeMoney),
            sum(SumFillMoney)
        from
            #tmpCardAmoutStat
        where
            CompanyName='員工卡'
        ---計算員工卡匯總結束---
    end

    ----計算總匯總開始---
    insert into #tmpCardAmoutStat
        (
            VC_OC_CardNO,
            CompanyName,
            VC_OC_UserName,
            StartAmount,
            FillMoney,
            ConsumeSumVol,
            ConsumeMoney,
            SumConsumeSumVol,
            SumConsumeMoney,
            SumFillMoney

        )
    select
        null,
        null,
        '總計',
        sum(StartAmount),
        sum(FillMoney),
        sum(ConsumeSumVol),
        sum(ConsumeMoney),
        sum(SumConsumeSumVol),
        sum(SumConsumeMoney),
        sum(SumFillMoney)
    from
        #tmpCardAmoutStat
    where
        (VC_OC_UserName='客戶卡小計' or VC_OC_UserName='員工卡小計') and VC_OC_CardNO is null
    update #tmpCardAmoutStat set EndAmount=StartAmount+FillMoney-ConsumeMoney
    ---計算總匯總結束---
    select * from  #tmpCardAmoutStat

    drop table #tmpCards
    drop table #tmpCompanys
    drop table #tmpCardAmoutStat
GO

--其他存儲過程省略。。。。。。。。。。。



然後把這個腳本發給客戶,讓客戶在SSMS裡執行一下就可以了

當然如果某些表的主鍵更改了也很簡單,使用alter table alter column語句修改一下就可以了

如有不對的地方,歡迎大家拍磚o(∩_∩)o

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved