首页 > 数据库 >SQL Server 新建表案例语句

SQL Server 新建表案例语句

时间:2022-08-26 14:45:24浏览次数:70  
标签:语句 ActualFreightSurcharge name dbo Server sys SQL TABLE EgSys

GO
IF NOT EXISTS
(
    SELECT 1
    FROM sys.objects o
    WHERE o.name = 'EgSys_ActualFreightSurcharge'
          AND o.type = 'u'
)
BEGIN
    CREATE TABLE [dbo].[EgSys_ActualFreightSurcharge]
    (
        [FreightSurchargeId] [INT] IDENTITY(1, 1) NOT NULL,
        [FreightId] [INT] NOT NULL,
        [USDExchangeRateToCNY] [DECIMAL](13,4) NOT NULL DEFAULT 0,
        [USDExchangeRateToEUR] [DECIMAL](13,4) NOT NULL DEFAULT 0,
        [PeakSeasonSurchargeRate] [DECIMAL](13,4) NOT NULL DEFAULT 0,
        [TariffAmount] [DECIMAL](13,4) NOT NULL DEFAULT 0,
        [FuelSurchargeRate] [DECIMAL](13,4) NOT NULL DEFAULT 0,
        [CreateDate] [DATETIME] NOT NULL,
        [CreateBy] [VARCHAR](50) NOT NULL,
        [UpdateDate] [DATETIME] NOT NULL,
        [UpdateBy] [VARCHAR](50) NOT NULL,
        CONSTRAINT [PK_EgSys_ActualFreightSurcharge]
        PRIMARY KEY CLUSTERED ([FreightSurchargeId] ASC)
        WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY];

    EXEC sys.sp_addextendedproperty @name = N'MS_Description',
                                    @value = N'主键',
                                    @level0type = N'SCHEMA',
                                    @level0name = N'dbo',
                                    @level1type = N'TABLE',
                                    @level1name = N'EgSys_ActualFreightSurcharge',
                                    @level2type = N'COLUMN',
                                    @level2name = N'FreightSurchargeId';

    EXEC sys.sp_addextendedproperty @name = N'MS_Description',
                                    @value = N'EgSys_ActualFreightMain表主键',
                                    @level0type = N'SCHEMA',
                                    @level0name = N'dbo',
                                    @level1type = N'TABLE',
                                    @level1name = N'EgSys_ActualFreightSurcharge',
                                    @level2type = N'COLUMN',
                                    @level2name = N'FreightId';

    EXEC sys.sp_addextendedproperty @name = N'MS_Description',
                                    @value = N'美金兑人民币汇率',
                                    @level0type = N'SCHEMA',
                                    @level0name = N'dbo',
                                    @level1type = N'TABLE',
                                    @level1name = N'EgSys_ActualFreightSurcharge',
                                    @level2type = N'COLUMN',
                                    @level2name = N'USDExchangeRateToCNY';
                                    
    EXEC sys.sp_addextendedproperty @name = N'MS_Description',
                                    @value = N'美金兑欧元汇率',
                                    @level0type = N'SCHEMA',
                                    @level0name = N'dbo',
                                    @level1type = N'TABLE',
                                    @level1name = N'EgSys_ActualFreightSurcharge',
                                    @level2type = N'COLUMN',
                                    @level2name = N'USDExchangeRateToEUR';
                                    
    EXEC sys.sp_addextendedproperty @name = N'MS_Description',
                                    @value = N'旺季附加费费率',
                                    @level0type = N'SCHEMA',
                                    @level0name = N'dbo',
                                    @level1type = N'TABLE',
                                    @level1name = N'EgSys_ActualFreightSurcharge',
                                    @level2type = N'COLUMN',
                                    @level2name = N'PeakSeasonSurchargeRate';
                                    
    EXEC sys.sp_addextendedproperty @name = N'MS_Description',
                                    @value = N'关税金额',
                                    @level0type = N'SCHEMA',
                                    @level0name = N'dbo',
                                    @level1type = N'TABLE',
                                    @level1name = N'EgSys_ActualFreightSurcharge',
                                    @level2type = N'COLUMN',
                                    @level2name = N'TariffAmount';
                                    
    EXEC sys.sp_addextendedproperty @name = N'MS_Description',
                                    @value = N'燃油附加费费率',
                                    @level0type = N'SCHEMA',
                                    @level0name = N'dbo',
                                    @level1type = N'TABLE',
                                    @level1name = N'EgSys_ActualFreightSurcharge',
                                    @level2type = N'COLUMN',
                                    @level2name = N'FuelSurchargeRate';

    EXEC sys.sp_addextendedproperty @name = N'MS_Description',
                                    @value = N'创建时间',
                                    @level0type = N'SCHEMA',
                                    @level0name = N'dbo',
                                    @level1type = N'TABLE',
                                    @level1name = N'EgSys_ActualFreightSurcharge',
                                    @level2type = N'COLUMN',
                                    @level2name = N'CreateDate';

    EXEC sys.sp_addextendedproperty @name = N'MS_Description',
                                    @value = N'创建人',
                                    @level0type = N'SCHEMA',
                                    @level0name = N'dbo',
                                    @level1type = N'TABLE',
                                    @level1name = N'EgSys_ActualFreightSurcharge',
                                    @level2type = N'COLUMN',
                                    @level2name = N'CreateBy';

    EXEC sys.sp_addextendedproperty @name = N'MS_Description',
                                    @value = N'更新时间',
                                    @level0type = N'SCHEMA',
                                    @level0name = N'dbo',
                                    @level1type = N'TABLE',
                                    @level1name = N'EgSys_ActualFreightSurcharge',
                                    @level2type = N'COLUMN',
                                    @level2name = N'UpdateDate';

    EXEC sys.sp_addextendedproperty @name = N'MS_Description',
                                    @value = N'更新人',
                                    @level0type = N'SCHEMA',
                                    @level0name = N'dbo',
                                    @level1type = N'TABLE',
                                    @level1name = N'EgSys_ActualFreightSurcharge',
                                    @level2type = N'COLUMN',
                                    @level2name = N'UpdateBy';

    EXEC sys.sp_addextendedproperty @name = N'MS_Description',
                                    @value = N'物流附加费配置表',
                                    @level0type = N'SCHEMA',
                                    @level0name = N'dbo',
                                    @level1type = N'TABLE',
                                    @level1name = N'EgSys_ActualFreightSurcharge';

    EXEC sys.sp_addextendedproperty @name = N'MS_Description',
                                    @value = N'主键索引',
                                    @level0type = N'SCHEMA',
                                    @level0name = N'dbo',
                                    @level1type = N'TABLE',
                                    @level1name = N'EgSys_ActualFreightSurcharge',
                                    @level2type = N'CONSTRAINT',
                                    @level2name = N'PK_EgSys_ActualFreightSurcharge';

END;

IF NOT EXISTS ( 
    SELECT 1 FROM sys.sysobjects (NOLOCK) so
    INNER JOIN sys.syscolumns (NOLOCK) sc ON so.id = sc.id
    WHERE so.name = 'EgSys_ActualFreightMain' AND sc.name = 'UpdateDate'
)
BEGIN
    ALTER TABLE dbo.EgSys_ActualFreightMain ADD UpdateDate DATETIME NOT NULL DEFAULT GETDATE()
    EXEC sys.sp_addextendedproperty @name = N'MS_Description',
                                    @value = N'更新时间', 
                                    @level0type = N'SCHEMA', 
                                    @level0name = N'dbo',
                                    @level1type = N'TABLE', 
                                    @level1name = N'EgSys_ActualFreightMain',
                                    @level2type = N'COLUMN', 
                                    @level2name = N'UpdateDate'    
END;

IF NOT EXISTS ( 
    SELECT 1 FROM sys.sysobjects (NOLOCK) so
    INNER JOIN sys.syscolumns (NOLOCK) sc ON so.id = sc.id
    WHERE so.name = 'EgSys_ActualFreightMain' AND sc.name = 'UpdateBy'
)
BEGIN
    ALTER TABLE dbo.EgSys_ActualFreightMain ADD UpdateBy VARCHAR(50) NOT NULL DEFAULT ''
    EXEC sys.sp_addextendedproperty @name = N'MS_Description',
                                    @value = N'更新人',
                                    @level0type = N'SCHEMA',
                                    @level0name = N'dbo',
                                    @level1type = N'TABLE',
                                    @level1name = N'EgSys_ActualFreightMain',
                                    @level2type = N'COLUMN',
                                    @level2name = N'UpdateBy'
END;
GO

 

标签:语句,ActualFreightSurcharge,name,dbo,Server,sys,SQL,TABLE,EgSys
From: https://www.cnblogs.com/code-porter-233/p/16627505.html

相关文章

  • Mysql 系列 | join 优化
    上一篇中说了join语句的执行过程,了解了深层逻辑,则优化方案呼之欲出。Multi-RangeRead(MRR)优化select*fromt1wherea>=1anda<=100;回表时,根据ID去主键索引......
  • 1. SQL--前言
    1.前言SQL是StructuredQueryLanguage的缩写,译为“结构化查询语言”。SQL是一种数据库操作语言,用来检索和管理关系型数据库中的数据,比如插入数据、删除数据、查询数......
  • SQL Server游标的使用案例
    SELECT*INTObackup_db.dbo.EgSys_ActualFreightDetail_202208251630FROMEgSys_ActualFreightDetail(NOLOCK);BEGINDECLARE@DetailIDINT;DECLARE@PackageFee......
  • Serverless实战——2分钟,教你用Serverless每天给女朋友自动发土味情话
    原文链接:https://developer.aliyun.com/article/981268演示视频:https://developer.aliyun.com/live/249772一、Serverless简介Serverless,中文意思是“无服务器”,所谓的......
  • 通过iptables转发到TDSQL实现外网访问云数据库
    腾讯云有些TDSQL,如pgsql版的不能通过外网访问。此时提供2种方案,一种是nginx转发,一种是iptables。这看起来都需要额外的服务器成本,没办法。这里我们使用iptables,因为最方便......
  • Mysql查询当前年份、去年,当前月份、上个月′,当前周、上一周新增数据
    查询当前年份新增数据select*fromtestwhereYEAR(create_time)=YEAR(NOW())查询当去年份新增数据<iftest="param.lastYearStatus!=null">andYEAR(creat......
  • Mysql按日、周、月进行分组统计
    1)按天统计:selectDATE_FORMAT(start_time,'%Y%m%d')days,count(product_no)countfromtestgroupbydays;2)按周统计:selectDATE_FORMAT(start_time,'%Y%u')week......
  • 创建SparkSQL的项目
    创建项目方式和前面一样pom依赖不一样无需导入spark_core包,因为spark_sql中包含了spark_corepom.xml文件<?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="h......
  • MySQL在grant时报错ERROR 1064 (42000)
    网上查到的grant方式大多会报错,主要原因是MySQL版本8.0后不能再使用原来的方式查询MySQL版本SELECTversion();在8.0版本下grantallprivilegesontest.*tote......
  • MySQL查询性能优化七种武器之索引下推
    今天要讲的是MySQL的另一种查询性能优化方式— 索引下推(IndexConditionPushdown,简称ICP),是MySQL5.6版本增加的特性。1.索引下推的作用主要作用有两个:减少回表查询......