zoukankan      html  css  js  c++  java
  • 创建S数据库表SQL语句

    /*==============================================================*/
    /* 脚本作用:      为新区县创建独立的条目表(案卷和卷内)                */
    /* 创建日期:     2018/12/5 14:44:43                              */
    /* 将  ArchvTable  替换为  区县拼音首字母_Archv                     */
    /* 将  ArchvFileTable 替换为 区县拼音首字母_ArchvFile              */
    /*==============================================================*/
    if exists (select 1
                from  sysindexes
               where  id    = object_id('ArchvTable')
                and   name  = 'Index_ArchvTable_ND_AJSXH'
                and   indid > 0
                and   indid < 255)
       drop index ArchvTable.Index_ArchvTable_ND_AJSXH
    go
    if exists (select 1
                from  sysindexes
               where  id    = object_id('ArchvTable')
                and   name  = 'Index_ArchvTable_XZWDDM'
                and   indid > 0
                and   indid < 255)
       drop index ArchvTable.Index_ArchvTable_XZWDDM
    go
    if exists (select 1
                from  sysindexes
               where  id    = object_id('ArchvTable')
                and   name  = 'Index_ArchvTable_AJTM'
                and   indid > 0
                and   indid < 255)
       drop index ArchvTable.Index_ArchvTable_AJTM
    go
    if exists (select 1
                from  sysindexes
               where  id    = object_id('ArchvTable')
                and   name  = 'Index_ArchvTable_AJDH'
                and   indid > 0
                and   indid < 255)
       drop index ArchvTable.Index_ArchvTable_AJDH
    go
    if exists (select 1
                from  sysindexes
               where  id    = object_id('ArchvTable')
                and   name  = 'Index_ArchvTable_LCDH'
                and   indid > 0
                and   indid < 255)
       drop index ArchvTable.Index_ArchvTable_LCDH
    go
    if exists (select 1
                from  sysobjects
               where  id = object_id('ArchvTable')
                and   type = 'U')
       drop table ArchvTable
    go
    /*==============================================================*/
    /* Table: ArchvTable                                            */
    /*==============================================================*/
    create table ArchvTable (
       ArchvID              int                  identity,
       LCDH                 varchar(20)          not null,
       AJSXH                int                  not null,
       AJJS                 int                  not null,
       AJYS                 int                  not null,
       SJSJ                 varchar(15)          not null,
       BJSJ                 varchar(15)          not null,
       AJDH                 varchar(29)          not null,
       AJTM                 varchar(29)          not null,
       ND                   int                  not null,
       YF                   int                  not null,
       BGQX                 varchar(5)           not null,
       KSBGSJ               varchar(8)           not null,
       JSBGSJ               varchar(8)           not null,
       QZH                  varchar(3)           not null,
       LBH                  varchar(10)          not null,
       XZWDDM               varchar(5)           not null,
       MJ                   varchar(20)          not null default '内部资料',
       GDBM                 varchar(100)         not null,
       LJR                  varchar(50)          not null,
       JCR                  varchar(50)          not null,
       JGNF                 int                  not null default YEAR(getdate()),
       WorkingDate          datetime             not null default getdate(),
       WorkStatus           int                  not null,
       WorkingID            int                  null,
       QCID                 int                  null,
       QCDate               datetime             null,
       RS                   int                  null,
       DWFlag               bit                  null,
       constraint PK_ArchvTable primary key nonclustered (ArchvID)
    )
    go
    if exists (select 1 from  sys.extended_properties
               where major_id = object_id('ArchvTable') and minor_id = 0)
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description', 
       'user', @CurrentUser, 'table', 'ArchvTable'
     
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description', 
       '案卷表',
       'user', @CurrentUser, 'table', 'ArchvTable'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'ArchvID')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'ArchvID'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '案卷ID',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'ArchvID'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'LCDH')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'LCDH'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '流程单号',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'LCDH'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'AJSXH')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'AJSXH'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '案卷顺序号',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'AJSXH'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'AJJS')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'AJJS'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '案件件数',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'AJJS'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'AJYS')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'AJYS'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '案件页数',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'AJYS'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'SJSJ')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'SJSJ'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '收集时间',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'SJSJ'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'BJSJ')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'BJSJ'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '办结时间',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'BJSJ'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'AJDH')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'AJDH'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '案卷档号',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'AJDH'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'AJTM')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'AJTM'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '案卷条码',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'AJTM'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'ND')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'ND'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '年度',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'ND'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'YF')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'YF'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '月份',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'YF'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'BGQX')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'BGQX'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '保管期限',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'BGQX'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'KSBGSJ')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'KSBGSJ'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '开始保管时间',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'KSBGSJ'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'JSBGSJ')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'JSBGSJ'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '结束保管时间',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'JSBGSJ'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'QZH')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'QZH'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '全宗号',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'QZH'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'LBH')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'LBH'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '类别号',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'LBH'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'XZWDDM')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'XZWDDM'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '乡镇网点代码',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'XZWDDM'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'MJ')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'MJ'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '密级',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'MJ'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'GDBM')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'GDBM'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '归档部门',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'GDBM'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'LJR')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'LJR'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '立卷人',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'LJR'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'JCR')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'JCR'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '检查人',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'JCR'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'JGNF')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'JGNF'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '加工年份',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'JGNF'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'WorkingDate')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'WorkingDate'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '录入日期',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'WorkingDate'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'WorkStatus')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'WorkStatus'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '加工状态',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'WorkStatus'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'WorkingID')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'WorkingID'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '录入员工号',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'WorkingID'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'QCID')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'QCID'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '质检员工号',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'QCID'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'QCDate')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'QCDate'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '质检日期',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'QCDate'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'RS')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'RS'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '人数',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'RS'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'DWFlag')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'DWFlag'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '单位标志',
       'user', @CurrentUser, 'table', 'ArchvTable', 'column', 'DWFlag'
    go
    /*==============================================================*/
    /* Index: Index_ArchvTable_LCDH                                 */
    /*==============================================================*/
     

    create clustered index Index_ArchvTable_LCDH on ArchvTable (LCDH ASC)
    go
    /*==============================================================*/
    /* Index: Index_ArchvTable_AJDH                                 */
    /*==============================================================*/
     

    create nonclustered index Index_ArchvTable_AJDH on ArchvTable (AJDH ASC)
    go
    /*==============================================================*/
    /* Index: Index_ArchvTable_AJTM                                 */
    /*==============================================================*/
     

    create unique nonclustered index Index_ArchvTable_AJTM on ArchvTable (AJTM ASC)
    go
    /*==============================================================*/
    /* Index: Index_ArchvTable_XZWDDM                               */
    /*==============================================================*/
     

    create nonclustered index Index_ArchvTable_XZWDDM on ArchvTable (XZWDDM ASC)
    go
    /*==============================================================*/
    /* Index: Index_ArchvTable_ND_AJSXH                             */
    /*==============================================================*/
     

    create nonclustered index Index_ArchvTable_ND_AJSXH on ArchvTable (ND ASC,
      AJSXH ASC)
    go

    if exists (select 1
       from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
       where r.fkeyid = object_id('ArchvFileTable') and o.name = 'FK_ArchvFileTable_R_ArchvTable')
    alter table ArchvFileTable
       drop constraint FK_ArchvFileTable_R_ArchvTable
    go
    if exists (select 1
                from  sysindexes
               where  id    = object_id('ArchvFileTable')
                and   name  = 'Index_ArchvFileTable_ArchvID'
                and   indid > 0
                and   indid < 255)
       drop index ArchvFileTable.Index_ArchvFileTable_ArchvID
    go
    if exists (select 1
                from  sysindexes
               where  id    = object_id('ArchvFileTable')
                and   name  = 'Index_ArchvFileTable_GMSFZHM'
                and   indid > 0
                and   indid < 255)
       drop index ArchvFileTable.Index_ArchvFileTable_GMSFZHM
    go
    if exists (select 1
                from  sysindexes
               where  id    = object_id('ArchvFileTable')
                and   name  = 'Index_ArchvFileTable_XM'
                and   indid > 0
                and   indid < 255)
       drop index ArchvFileTable.Index_ArchvFileTable_XM
    go
    if exists (select 1
                from  sysindexes
               where  id    = object_id('ArchvFileTable')
                and   name  = 'Index_ArchvFileTable_AJTXM'
                and   indid > 0
                and   indid < 255)
       drop index ArchvFileTable.Index_ArchvFileTable_AJTXM
    go
    if exists (select 1
                from  sysobjects
               where  id = object_id('ArchvFileTable')
                and   type = 'U')
       drop table ArchvFileTable
    go
    /*==============================================================*/
    /* Table: ArchvFileTable                                        */
    /*==============================================================*/
    create table ArchvFileTable (
       ID                   int                  identity,
       ArchvID              int                  null,
       AJTXM                varchar(23)          not null,
       AJSXH                int                  not null,
       XM                   varchar(1700)        not null,
       GMSFZHM              varchar(1700)        not null,
       BarcodePage          int                  not null,
       QSYM                 int                  not null,
       YH                   varchar(10)          not null,
       YS                   int                  not null,
       BL                   varchar(11)          null,
       BZ                   varchar(200)         null,
       SJSJ                 varchar(8)           not null,
       BJSJ                 varchar(8)           not null,
       JNDH                 varchar(34)          not null,
       YF                   int                  not null,
       WorkingDate          datetime             not null default getdate(),
       QCDate               datetime             null,
       RS                   int                  not null,
       constraint PK_ArchvFileTable primary key nonclustered (ID)
    )
    go
    if exists (select 1 from  sys.extended_properties
               where major_id = object_id('ArchvFileTable') and minor_id = 0)
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description', 
       'user', @CurrentUser, 'table', 'ArchvFileTable'
     
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description', 
       '卷内文件表',
       'user', @CurrentUser, 'table', 'ArchvFileTable'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvFileTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'ID')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'ID'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '行编号',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'ID'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvFileTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'ArchvID')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'ArchvID'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '案卷ID',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'ArchvID'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvFileTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'AJTXM')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'AJTXM'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '案件条形码',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'AJTXM'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvFileTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'AJSXH')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'AJSXH'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '案件顺序号',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'AJSXH'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvFileTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'XM')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'XM'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '姓名',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'XM'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvFileTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'GMSFZHM')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'GMSFZHM'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '身份证号码',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'GMSFZHM'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvFileTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'BarcodePage')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'BarcodePage'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '条码所在页码',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'BarcodePage'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvFileTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'QSYM')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'QSYM'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '起始页码',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'QSYM'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvFileTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'YH')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'YH'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '页号',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'YH'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvFileTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'YS')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'YS'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '页数',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'YS'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvFileTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'BL')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'BL'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '补录',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'BL'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvFileTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'BZ')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'BZ'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '备注',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'BZ'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvFileTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'SJSJ')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'SJSJ'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '收集时间',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'SJSJ'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvFileTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'BJSJ')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'BJSJ'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '办结时间',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'BJSJ'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvFileTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'JNDH')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'JNDH'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '卷内档号',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'JNDH'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvFileTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'YF')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'YF'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '月份',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'YF'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvFileTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'WorkingDate')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'WorkingDate'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '录入日期',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'WorkingDate'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvFileTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'QCDate')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'QCDate'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '质检日期',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'QCDate'
    go
    if exists(select 1 from sys.extended_properties p where
          p.major_id = object_id('ArchvFileTable')
      and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'RS')
    )
    begin
       declare @CurrentUser sysname
    select @CurrentUser = user_name()
    execute sp_dropextendedproperty 'MS_Description',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'RS'
    end

    select @CurrentUser = user_name()
    execute sp_addextendedproperty 'MS_Description',
       '人数',
       'user', @CurrentUser, 'table', 'ArchvFileTable', 'column', 'RS'
    go
    /*==============================================================*/
    /* Index: Index_ArchvFileTable_AJTXM                            */
    /*==============================================================*/
     

    create unique nonclustered index Index_ArchvFileTable_AJTXM on ArchvFileTable (AJTXM ASC)
    go
    /*==============================================================*/
    /* Index: Index_ArchvFileTable_XM                               */
    /*==============================================================*/
     

    create nonclustered index Index_ArchvFileTable_XM on ArchvFileTable (XM ASC)
    go
    /*==============================================================*/
    /* Index: Index_ArchvFileTable_GMSFZHM                          */
    /*==============================================================*/
     

    create nonclustered index Index_ArchvFileTable_GMSFZHM on ArchvFileTable (GMSFZHM ASC)
    go
    /*==============================================================*/
    /* Index: Index_ArchvFileTable_ArchvID                          */
    /*==============================================================*/
     

    create clustered index Index_ArchvFileTable_ArchvID on ArchvFileTable (ArchvID ASC)
    go
    alter table ArchvFileTable
       add constraint FK_ArchvFileTable_R_ArchvTable foreign key (ArchvID)
          references ArchvTable (ArchvID)
    go
     
  • 相关阅读:
    JS 禁止刷新和右键
    报错 避免重复
    CSS 总结
    CSS BUG 总结
    安装 mrtg
    人人网 网站接入总结
    PHPcms 把盛大登陆换成人人网登陆
    HTML 相同name 传递一个数组
    file_get_contents无法请求https连接的解决方法
    现货黄金白银上阻力位和压力位的确定和应用
  • 原文地址:https://www.cnblogs.com/yyldh/p/12758866.html
Copyright © 2011-2022 走看看