/*==============================================================*/
/* DBMS name:      Microsoft SQL Server 2012                    */
/* Created on:     2021/5/17 16:21:56                           */
/*==============================================================*/


if exists (select 1
            from  sysobjects
           where  id = object_id('W_Account')
            and   type = 'U')
   drop table W_Account
go

if exists (select 1
            from  sysobjects
           where  id = object_id('W_AreaInfo')
            and   type = 'U')
   drop table W_AreaInfo
go

if exists (select 1
            from  sysobjects
           where  id = object_id('W_Business')
            and   type = 'U')
   drop table W_Business
go

if exists (select 1
            from  sysobjects
           where  id = object_id('W_Device')
            and   type = 'U')
   drop table W_Device
go

if exists (select 1
            from  sysobjects
           where  id = object_id('W_DeviceData')
            and   type = 'U')
   drop table W_DeviceData
go

if exists (select 1
            from  sysobjects
           where  id = object_id('W_DeviceRealData')
            and   type = 'U')
   drop table W_DeviceRealData
go

if exists (select 1
            from  sysobjects
           where  id = object_id('W_Menu')
            and   type = 'U')
   drop table W_Menu
go

if exists (select 1
            from  sysobjects
           where  id = object_id('W_Result')
            and   type = 'U')
   drop table W_Result
go

if exists (select 1
            from  sysobjects
           where  id = object_id('W_Role')
            and   type = 'U')
   drop table W_Role
go

if exists (select 1
            from  sysobjects
           where  id = object_id('W_RoleAuthorize')
            and   type = 'U')
   drop table W_RoleAuthorize
go

if exists (select 1
            from  sysobjects
           where  id = object_id('W_WasteType')
            and   type = 'U')
   drop table W_WasteType
go

/*==============================================================*/
/* Table: W_Account                                             */
/*==============================================================*/
create table W_Account (
   Id                   uniqueidentifier     not null,
   UserName             varchar(50)          not null,
   RealName             nvarchar(100)        not null,
   Phone                varchar(50)          not null,
   Password             varchar(50)          not null,
   Secret               varchar(50)          not null,
   RoleId               uniqueidentifier     not null,
   AccountType          int                  not null,
   BusinessId           uniqueidentifier     not null,
   Status               int                  not null,
   LastVisitIP          varchar(50)          not null,
   LastVisitTime        datetime             null,
   CreateTime           datetime             not null,
   constraint PK_W_ACCOUNT primary key (Id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('W_Account') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'W_Account' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '账户表', 
   'user', @CurrentUser, 'table', 'W_Account'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Account')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'UserName')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Account', 'column', 'UserName'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '账户',
   'user', @CurrentUser, 'table', 'W_Account', 'column', 'UserName'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Account')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'RealName')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Account', 'column', 'RealName'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '昵称',
   'user', @CurrentUser, 'table', 'W_Account', 'column', 'RealName'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Account')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Phone')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Account', 'column', 'Phone'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '手机号',
   'user', @CurrentUser, 'table', 'W_Account', 'column', 'Phone'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Account')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Password')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Account', 'column', 'Password'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '密码',
   'user', @CurrentUser, 'table', 'W_Account', 'column', 'Password'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Account')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Secret')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Account', 'column', 'Secret'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '密钥',
   'user', @CurrentUser, 'table', 'W_Account', 'column', 'Secret'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Account')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'RoleId')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Account', 'column', 'RoleId'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '角色ID',
   'user', @CurrentUser, 'table', 'W_Account', 'column', 'RoleId'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Account')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'AccountType')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Account', 'column', 'AccountType'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '账户类型',
   'user', @CurrentUser, 'table', 'W_Account', 'column', 'AccountType'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Account')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'BusinessId')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Account', 'column', 'BusinessId'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '客户ID',
   'user', @CurrentUser, 'table', 'W_Account', 'column', 'BusinessId'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Account')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Account', 'column', 'Status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '状态,0-禁用,1-启用',
   'user', @CurrentUser, 'table', 'W_Account', 'column', 'Status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Account')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'LastVisitIP')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Account', 'column', 'LastVisitIP'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '最近访问IP',
   'user', @CurrentUser, 'table', 'W_Account', 'column', 'LastVisitIP'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Account')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'LastVisitTime')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Account', 'column', 'LastVisitTime'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '最近访问时间',
   'user', @CurrentUser, 'table', 'W_Account', 'column', 'LastVisitTime'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Account')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'CreateTime')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Account', 'column', 'CreateTime'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '注册时间',
   'user', @CurrentUser, 'table', 'W_Account', 'column', 'CreateTime'
go

/*==============================================================*/
/* Table: W_AreaInfo                                            */
/*==============================================================*/
create table W_AreaInfo (
   Id                   int                  not null,
   pid                  int                  not null,
   name                 nvarchar(100)        not null,
   code                 varchar(50)          not null,
   level                int                  not null
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('W_AreaInfo') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'W_AreaInfo' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '地址信息配置', 
   'user', @CurrentUser, 'table', 'W_AreaInfo'
go

/*==============================================================*/
/* Table: W_Business                                            */
/*==============================================================*/
create table W_Business (
   Id                   uniqueidentifier     not null,
   Code                 varchar(100)         not null,
   ParentId             uniqueidentifier     not null,
   Name                 nvarchar(100)        not null,
   Phone                varchar(20)          not null,
   Status               int                  not null,
   Remark               nvarchar(200)        not null,
   Province             varchar(50)          not null,
   City                 varchar(50)          not null,
   Area                 varchar(50)          not null,
   Address              nvarchar(200)        not null,
   CreateTime           datetime             not null,
   constraint PK_W_BUSINESS primary key (Id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('W_Business') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'W_Business' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '商户表', 
   'user', @CurrentUser, 'table', 'W_Business'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Business')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Code')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Business', 'column', 'Code'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '商户编号',
   'user', @CurrentUser, 'table', 'W_Business', 'column', 'Code'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Business')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'ParentId')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Business', 'column', 'ParentId'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '上级ID',
   'user', @CurrentUser, 'table', 'W_Business', 'column', 'ParentId'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Business')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Business', 'column', 'Name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '昵称',
   'user', @CurrentUser, 'table', 'W_Business', 'column', 'Name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Business')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Phone')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Business', 'column', 'Phone'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '手机号',
   'user', @CurrentUser, 'table', 'W_Business', 'column', 'Phone'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Business')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Business', 'column', 'Status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '状态,0-禁用,1-启用',
   'user', @CurrentUser, 'table', 'W_Business', 'column', 'Status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Business')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Business', 'column', 'Remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '商户简介',
   'user', @CurrentUser, 'table', 'W_Business', 'column', 'Remark'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Business')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Province')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Business', 'column', 'Province'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '省份',
   'user', @CurrentUser, 'table', 'W_Business', 'column', 'Province'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Business')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'City')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Business', 'column', 'City'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '城市',
   'user', @CurrentUser, 'table', 'W_Business', 'column', 'City'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Business')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Area')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Business', 'column', 'Area'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '区县',
   'user', @CurrentUser, 'table', 'W_Business', 'column', 'Area'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Business')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Address')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Business', 'column', 'Address'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '详细地址',
   'user', @CurrentUser, 'table', 'W_Business', 'column', 'Address'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Business')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'CreateTime')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Business', 'column', 'CreateTime'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '注册时间',
   'user', @CurrentUser, 'table', 'W_Business', 'column', 'CreateTime'
go

/*==============================================================*/
/* Table: W_Device                                              */
/*==============================================================*/
create table W_Device (
   Id                   uniqueidentifier     not null,
   FacEcode             varchar(50)          not null,
   Ecode                varchar(50)          not null,
   DeviceType           int                  not null,
   Name                 nvarchar(100)        not null,
   Businessid           uniqueidentifier     not null,
   NetType              int                  not null,
   Province             varchar(50)          not null,
   City                 varchar(50)          not null,
   Area                 varchar(50)          not null,
   Address              nvarchar(200)        not null,
   Remark               nvarchar(200)        not null,
   InstallTime          datetime             null,
   Status               int                  not null,
   LastHeartTime        datetime             null,
   CreateTime           datetime             not null,
   constraint PK_W_DEVICE primary key (Id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('W_Device') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'W_Device' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '设备表', 
   'user', @CurrentUser, 'table', 'W_Device'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Device')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'FacEcode')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Device', 'column', 'FacEcode'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '设备出厂编号',
   'user', @CurrentUser, 'table', 'W_Device', 'column', 'FacEcode'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Device')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Ecode')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Device', 'column', 'Ecode'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '设备编号',
   'user', @CurrentUser, 'table', 'W_Device', 'column', 'Ecode'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Device')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'DeviceType')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Device', 'column', 'DeviceType'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '设备型号',
   'user', @CurrentUser, 'table', 'W_Device', 'column', 'DeviceType'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Device')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Device', 'column', 'Name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '设备名称',
   'user', @CurrentUser, 'table', 'W_Device', 'column', 'Name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Device')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Businessid')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Device', 'column', 'Businessid'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '所属商户',
   'user', @CurrentUser, 'table', 'W_Device', 'column', 'Businessid'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Device')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'NetType')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Device', 'column', 'NetType'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '联网方式,1-4G,2-Wifi',
   'user', @CurrentUser, 'table', 'W_Device', 'column', 'NetType'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Device')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'City')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Device', 'column', 'City'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '城市',
   'user', @CurrentUser, 'table', 'W_Device', 'column', 'City'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Device')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Area')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Device', 'column', 'Area'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '区县',
   'user', @CurrentUser, 'table', 'W_Device', 'column', 'Area'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Device')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Address')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Device', 'column', 'Address'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '详细地址',
   'user', @CurrentUser, 'table', 'W_Device', 'column', 'Address'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Device')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Device', 'column', 'Remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'W_Device', 'column', 'Remark'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Device')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'InstallTime')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Device', 'column', 'InstallTime'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '安装到小区的时间',
   'user', @CurrentUser, 'table', 'W_Device', 'column', 'InstallTime'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Device')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Device', 'column', 'Status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '设备状态,0-异常,1-正常',
   'user', @CurrentUser, 'table', 'W_Device', 'column', 'Status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Device')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'LastHeartTime')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Device', 'column', 'LastHeartTime'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '最近使用时间',
   'user', @CurrentUser, 'table', 'W_Device', 'column', 'LastHeartTime'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Device')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'CreateTime')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Device', 'column', 'CreateTime'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '注册时间',
   'user', @CurrentUser, 'table', 'W_Device', 'column', 'CreateTime'
go

/*==============================================================*/
/* Table: W_DeviceData                                          */
/*==============================================================*/
create table W_DeviceData (
   DeviceId             uniqueidentifier     not null,
   ICCID                varchar(50)          not null,
   IMEI                 varchar(50)          not null,
   IMSI                 varchar(50)          not null,
   Longitude            varchar(50)          not null,
   Latitude             varchar(50)          not null,
   LastBeatTime         datetime             null,
   LastStartTime        datetime             null,
   Sign                 varchar(50)          not null,
   constraint PK_W_DEVICEDATA primary key (DeviceId)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('W_DeviceData') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'W_DeviceData' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '设备信息', 
   'user', @CurrentUser, 'table', 'W_DeviceData'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_DeviceData')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'ICCID')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_DeviceData', 'column', 'ICCID'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   'ICCID',
   'user', @CurrentUser, 'table', 'W_DeviceData', 'column', 'ICCID'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_DeviceData')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'IMEI')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_DeviceData', 'column', 'IMEI'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   'IMEI',
   'user', @CurrentUser, 'table', 'W_DeviceData', 'column', 'IMEI'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_DeviceData')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'IMSI')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_DeviceData', 'column', 'IMSI'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   'SIM卡IMSI',
   'user', @CurrentUser, 'table', 'W_DeviceData', 'column', 'IMSI'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_DeviceData')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Longitude')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_DeviceData', 'column', 'Longitude'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '经度',
   'user', @CurrentUser, 'table', 'W_DeviceData', 'column', 'Longitude'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_DeviceData')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Latitude')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_DeviceData', 'column', 'Latitude'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '纬度',
   'user', @CurrentUser, 'table', 'W_DeviceData', 'column', 'Latitude'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_DeviceData')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'LastBeatTime')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_DeviceData', 'column', 'LastBeatTime'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '最近心跳时间',
   'user', @CurrentUser, 'table', 'W_DeviceData', 'column', 'LastBeatTime'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_DeviceData')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'LastStartTime')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_DeviceData', 'column', 'LastStartTime'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '最近开机时间',
   'user', @CurrentUser, 'table', 'W_DeviceData', 'column', 'LastStartTime'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_DeviceData')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Sign')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_DeviceData', 'column', 'Sign'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '信号强度',
   'user', @CurrentUser, 'table', 'W_DeviceData', 'column', 'Sign'
go

/*==============================================================*/
/* Table: W_DeviceRealData                                      */
/*==============================================================*/
create table W_DeviceRealData (
   Id                   uniqueidentifier     not null,
   DeviceId             uniqueidentifier     not null,
   BusinessId           uniqueidentifier     not null,
   TodayCount           int                  not null,
   TotalCount           int                  not null,
   TodayWeigth          decimal(18,2)        not null,
   TotalWeight          decimal(18,2)        not null,
   constraint PK_W_DEVICEREALDATA primary key (Id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('W_DeviceRealData') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'W_DeviceRealData' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '设备实时数据', 
   'user', @CurrentUser, 'table', 'W_DeviceRealData'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_DeviceRealData')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'DeviceId')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_DeviceRealData', 'column', 'DeviceId'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '设备ID',
   'user', @CurrentUser, 'table', 'W_DeviceRealData', 'column', 'DeviceId'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_DeviceRealData')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'BusinessId')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_DeviceRealData', 'column', 'BusinessId'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '商户ID',
   'user', @CurrentUser, 'table', 'W_DeviceRealData', 'column', 'BusinessId'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_DeviceRealData')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'TodayCount')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_DeviceRealData', 'column', 'TodayCount'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '今日次数',
   'user', @CurrentUser, 'table', 'W_DeviceRealData', 'column', 'TodayCount'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_DeviceRealData')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'TotalCount')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_DeviceRealData', 'column', 'TotalCount'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '累计次数',
   'user', @CurrentUser, 'table', 'W_DeviceRealData', 'column', 'TotalCount'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_DeviceRealData')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'TodayWeigth')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_DeviceRealData', 'column', 'TodayWeigth'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '今日重量',
   'user', @CurrentUser, 'table', 'W_DeviceRealData', 'column', 'TodayWeigth'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_DeviceRealData')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'TotalWeight')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_DeviceRealData', 'column', 'TotalWeight'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '累计投放重量',
   'user', @CurrentUser, 'table', 'W_DeviceRealData', 'column', 'TotalWeight'
go

/*==============================================================*/
/* Table: W_Menu                                                */
/*==============================================================*/
create table W_Menu (
   Id                   uniqueidentifier     not null,
   ParentId             uniqueidentifier     not null,
   Name                 nvarchar(50)         not null,
   Icon                 varchar(50)          not null,
   UrlAddress           varchar(200)         not null,
   SortCode             int                  not null,
   Status               int                  not null,
   CreateTime           datetime             not null,
   constraint PK_W_MENU primary key (Id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('W_Menu') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'W_Menu' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '菜单', 
   'user', @CurrentUser, 'table', 'W_Menu'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Menu')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'ParentId')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Menu', 'column', 'ParentId'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '父ID',
   'user', @CurrentUser, 'table', 'W_Menu', 'column', 'ParentId'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Menu')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Menu', 'column', 'Name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '名称',
   'user', @CurrentUser, 'table', 'W_Menu', 'column', 'Name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Menu')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Icon')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Menu', 'column', 'Icon'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '图标',
   'user', @CurrentUser, 'table', 'W_Menu', 'column', 'Icon'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Menu')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'UrlAddress')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Menu', 'column', 'UrlAddress'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '链接',
   'user', @CurrentUser, 'table', 'W_Menu', 'column', 'UrlAddress'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Menu')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'SortCode')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Menu', 'column', 'SortCode'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '排序',
   'user', @CurrentUser, 'table', 'W_Menu', 'column', 'SortCode'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Menu')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Menu', 'column', 'Status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '状态',
   'user', @CurrentUser, 'table', 'W_Menu', 'column', 'Status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Menu')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'CreateTime')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Menu', 'column', 'CreateTime'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建时间',
   'user', @CurrentUser, 'table', 'W_Menu', 'column', 'CreateTime'
go

/*==============================================================*/
/* Table: W_Result                                              */
/*==============================================================*/
create table W_Result (
   Id                   uniqueidentifier     not null,
   DeviceId             uniqueidentifier     not null,
   BusinessId           uniqueidentifier     not null,
   WasteType            varchar(50)          not null,
   Tare                 decimal(18,2)        not null,
   GrossWeight          decimal(18,2)        not null,
   NetWeight            decimal(18,2)        not null,
   Registration         nvarchar(200)        not null,
   CreateTime           datetime             not null,
   constraint PK_W_RESULT primary key (Id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('W_Result') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'W_Result' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '投放记录', 
   'user', @CurrentUser, 'table', 'W_Result'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Result')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'DeviceId')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Result', 'column', 'DeviceId'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '设备ID',
   'user', @CurrentUser, 'table', 'W_Result', 'column', 'DeviceId'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Result')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'BusinessId')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Result', 'column', 'BusinessId'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '设备所属商户',
   'user', @CurrentUser, 'table', 'W_Result', 'column', 'BusinessId'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Result')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'WasteType')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Result', 'column', 'WasteType'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '物品分类',
   'user', @CurrentUser, 'table', 'W_Result', 'column', 'WasteType'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Result')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Tare')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Result', 'column', 'Tare'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '皮重,单位KG',
   'user', @CurrentUser, 'table', 'W_Result', 'column', 'Tare'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Result')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'GrossWeight')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Result', 'column', 'GrossWeight'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '毛重',
   'user', @CurrentUser, 'table', 'W_Result', 'column', 'GrossWeight'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Result')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'NetWeight')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Result', 'column', 'NetWeight'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '净重',
   'user', @CurrentUser, 'table', 'W_Result', 'column', 'NetWeight'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Result')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Registration')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Result', 'column', 'Registration'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '车牌号',
   'user', @CurrentUser, 'table', 'W_Result', 'column', 'Registration'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Result')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'CreateTime')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Result', 'column', 'CreateTime'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '上报时间',
   'user', @CurrentUser, 'table', 'W_Result', 'column', 'CreateTime'
go

/*==============================================================*/
/* Table: W_Role                                                */
/*==============================================================*/
create table W_Role (
   Id                   uniqueidentifier     not null,
   Name                 nvarchar(50)         not null,
   EnCode               varchar(50)          not null,
   Remark               nvarchar(200)        not null,
   CreateTime           datetime             not null,
   constraint PK_W_ROLE primary key (Id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('W_Role') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'W_Role' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '角色', 
   'user', @CurrentUser, 'table', 'W_Role'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Role')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Role', 'column', 'Name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '角色名称',
   'user', @CurrentUser, 'table', 'W_Role', 'column', 'Name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Role')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'EnCode')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Role', 'column', 'EnCode'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '角色编码',
   'user', @CurrentUser, 'table', 'W_Role', 'column', 'EnCode'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Role')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Role', 'column', 'Remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'W_Role', 'column', 'Remark'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_Role')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'CreateTime')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_Role', 'column', 'CreateTime'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建时间',
   'user', @CurrentUser, 'table', 'W_Role', 'column', 'CreateTime'
go

/*==============================================================*/
/* Table: W_RoleAuthorize                                       */
/*==============================================================*/
create table W_RoleAuthorize (
   Id                   uniqueidentifier     not null,
   RoleId               uniqueidentifier     not null,
   MenuId               uniqueidentifier     not null,
   CreateTime           datetime             not null,
   constraint PK_W_ROLEAUTHORIZE primary key (Id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('W_RoleAuthorize') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'W_RoleAuthorize' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '角色菜单', 
   'user', @CurrentUser, 'table', 'W_RoleAuthorize'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_RoleAuthorize')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'RoleId')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_RoleAuthorize', 'column', 'RoleId'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '角色ID',
   'user', @CurrentUser, 'table', 'W_RoleAuthorize', 'column', 'RoleId'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_RoleAuthorize')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'MenuId')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_RoleAuthorize', 'column', 'MenuId'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '菜单ID',
   'user', @CurrentUser, 'table', 'W_RoleAuthorize', 'column', 'MenuId'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_RoleAuthorize')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'CreateTime')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_RoleAuthorize', 'column', 'CreateTime'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建时间',
   'user', @CurrentUser, 'table', 'W_RoleAuthorize', 'column', 'CreateTime'
go

/*==============================================================*/
/* Table: W_WasteType                                           */
/*==============================================================*/
create table W_WasteType (
   Id                   uniqueidentifier     not null,
   Code                 varchar(20)          not null,
   Name                 nvarchar(100)        not null,
   Status               int                  not null,
   CreateTime           datetime             not null,
   constraint PK_W_WASTETYPE primary key (Id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('W_WasteType') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'W_WasteType' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '垃圾物品分类', 
   'user', @CurrentUser, 'table', 'W_WasteType'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_WasteType')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Code')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_WasteType', 'column', 'Code'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '物品编码',
   'user', @CurrentUser, 'table', 'W_WasteType', 'column', 'Code'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_WasteType')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_WasteType', 'column', 'Name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '物品名称',
   'user', @CurrentUser, 'table', 'W_WasteType', 'column', 'Name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_WasteType')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'Status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_WasteType', 'column', 'Status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '状态,0-禁用,1-启用',
   'user', @CurrentUser, 'table', 'W_WasteType', 'column', 'Status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('W_WasteType')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'CreateTime')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'W_WasteType', 'column', 'CreateTime'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '添加时间',
   'user', @CurrentUser, 'table', 'W_WasteType', 'column', 'CreateTime'
go

