SQLSERVER数据库升级脚本图文步骤

时间:2024-01-27 10:20:26 

只能远程协助的方式。我特意做了一个脚本,用电话指导客户在SSMS里执行一下脚本就可以了

1.0的数据库跟1.1的数据库的区别是1.1的数据库里的其中一个[CT_OuterCard]表比1.0的多了6个字段,其他所有表都一样

还有存储过程增加了很多,其他都没有改变

首先,先在公司的服务器数据库上生成存储过程脚本,数据库是1.1版本的,下面的图片里没有说明的,都是默认设置,下一步即可

选中数据库-》右键—》任务-》生成脚本

SQLSERVER数据库升级脚本图文步骤

SQLSERVER数据库升级脚本图文步骤

当然,如果你的数据库里有自定义函数的话,也可以勾选函数,如果我们的数据库没有函数,所以。。。

SQLSERVER数据库升级脚本图文步骤

SQLSERVER数据库升级脚本图文步骤

保存到新建查询窗口

SQLSERVER数据库升级脚本图文步骤

这一步做完了,然后编写下面的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

标签:SQLSERVER,数据库升级脚本
0
投稿

猜你喜欢

  • JS内部事件机制之单线程原理

    2024-05-03 15:58:24
  • 通过Python爬虫代理IP快速增加博客阅读量

    2023-08-17 16:17:55
  • python实现的简单RPG游戏流程实例

    2021-11-13 21:29:53
  • python机器学习之决策树分类详解

    2023-04-28 14:31:05
  • 10分钟学会Google Map API (一)

    2009-06-07 18:17:00
  • Scrapy-Redis结合POST请求获取数据的方法示例

    2023-08-25 06:31:56
  • Tensorflow 实现线性回归模型的示例代码

    2023-07-03 09:00:41
  • javascript自动生成包含数字与字符的随机字符串

    2024-04-17 09:45:29
  • Python爬取梨视频的示例

    2022-05-24 08:12:33
  • VSCode远程连接服务器报错:Could not establish connection to

    2023-10-03 03:02:17
  • 利用Tensorflow构建和训练自己的CNN来做简单的验证码识别方式

    2021-02-07 14:24:18
  • 在python中利用pycharm自定义代码块教程(三步搞定)

    2022-11-20 01:00:50
  • 如何使用python爬取知乎热榜Top50数据

    2021-11-13 05:47:09
  • Python ftp上传文件

    2023-10-01 06:35:34
  • Python实现类似比特币的加密货币区块链的创建与交易实例

    2022-03-19 15:49:49
  • js中各浏览器中鼠标按键值的差异

    2024-05-05 09:15:28
  • Python Pandas批量读取csv文件到dataframe的方法

    2022-12-15 17:05:03
  • python pandas loc 布尔索引示例说明

    2021-02-28 22:43:19
  • Highcharts+NodeJS搭建数据可视化平台示例

    2024-05-02 17:38:38
  • python爬虫 urllib模块url编码处理详解

    2021-09-13 02:24:37
  • asp之家 网络编程 m.aspxhome.com