IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[barcodedef]') AND type in (N'U')) DROP TABLE [barcodedef];
CREATE TABLE [barcodedef] (
	[defid]     char(1) primary key,  
	[bclen]     tinyint  not null, 
	[bcreslen]  tinyint  not null,
	[bcdatalen] tinyint  not null, 
	[bcvallen]  tinyint  not null,
	[bcchklen]  tinyint  not null,
   	[bcstruc]   varchar(60)
)

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[drugtypedef]') AND type in (N'U')) DROP TABLE [drugtypedef];
CREATE TABLE [drugtypedef] (
	[drugtype]   varchar(3)   not null,
	[reslen]     tinyint      not null,
	[idnolen]    tinyint      not null,
	[typedetail] nvarchar(30) not null,
)

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[allproduct]') AND type in (N'U')) DROP TABLE [allproduct];
CREATE TABLE [allproduct] (
	[id] int IDENTITY NOT NULL, 
	[productCode] char(7) not null ,
	[productName] nvarchar(60) not null,
	[comment]     nvarchar(120) default ''  not null,
	[subTypeNo]  char(10) not null,
	[authorizedNo] varchar(60) default ''  not null,
	[type]   nvarchar(60)  null,
	[spec]   nvarchar(60) default '' not null,
	[packageSpec]  nvarchar(60) not null,
	[packUnit]  nvarchar(60) null,
	[physicDetailType] varchar(3) NULL,
	[resprodcode] varchar(13) not null,
	[pkgRatio]  varchar(20) null,
	[pkglvcount] tinyint,
	[oncescannum]  Integer default 0 not null,
	[othersyscode] varchar(20) null,
	[trayboxnum] tinyint default 0 not null,
	[productstatus] tinyint default 1 not null,
	[stockflag]  tinyint  default 0 not null,
	[minbarcount] int default 0 not null,
	[reserve0]   int default 0,
	[reserve1]   varchar(30) null,
	[sysuserid]  int  not null , 
	[firsttime]  datetime default getdate() not null,
	[updateuser] integer default -1 not null,   
	[updatetime] datetime default getdate() not null, 
	[lastupdate] datetime null,
	PRIMARY KEY NONCLUSTERED ([resprodcode])
);

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[productrescode]') AND type in (N'U')) DROP TABLE [productrescode];
CREATE TABLE [productrescode] (
    [id] int IDENTITY NOT NULL, 
	[productCode] char(7) not null,
	[subTypeNo]  char(10) not null,
	[resprodcode] varchar(13) not null,
	[codeVersion] varchar(5) not null,
	[codeLevel]   tinyint ,
	[pkgRatio]    varchar(20),
	[rescode]     varchar(10) not null,
	[countbarcode] bigint default 0 not null,
	[countproduct] bigint default 0 not null,
	[reserve0]   int default 0,
	[reserve1]   varchar(30),
	[sysuserid]  int  not null ,
	[statusFlag] tinyint default 0 NOT NULL,
	[firsttime] datetime default getdate() not null,
	[updateuser] int default -1 not null,
	[updatetime] datetime default getdate() not null,
	PRIMARY KEY NONCLUSTERED ([pkgRatio],[codeVersion], [rescode])
);

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[barcodefile]') AND type in (N'U')) DROP TABLE [barcodefile];
CREATE TABLE [barcodefile] (
	[id] int primary key IDENTITY NOT NULL,
	[orderno]    varchar(20) not null,
	[fileno]     varchar(5) not null,
	[detailtype] varchar(5) null,
	[rescode]    varchar(10) not null,
	[subTypeNo]  char(10) not null,
	[resprodcode] varchar(13) not null,
	[pkgRatio]   varchar(20) not null,
	[codelv]     tinyint not null, 
	[startno]    bigint not null,
	[endno]      bigint not null,
	[verno]      varchar(10) not null,
	[barcodedefid]  char(1)  not null,
	[countnum]   Integer  not null,
	[storetable]  varchar(50) not null,
	[bcfilename] varchar(200) not null UNIQUE,
	[filestatus] char(1) not null default '0',
	[reserve0]   integer default 0,
	[reserve1]   varchar(30) null,
	[sysuserid]  integer  not null ,
	[relID] int default 0 NOT NULL,
	[inputtime] datetime default getdate() not null
);

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[barcodefileimport]') AND type in (N'U')) DROP TABLE [barcodefileimport];
CREATE TABLE [barcodefileimport] (
	[id] int primary key IDENTITY NOT NULL,
	[orderno]    varchar(20) not null,
	[fileno]     varchar(5) not null,
	[detailtype] varchar(5) null,
	[rescode]    varchar(10) not null,
	[subTypeNo]  char(10) not null,
	[resprodcode] varchar(13) not null,
	[pkgRatio]   varchar(20) not null,
	[codelv]     tinyint not null, 
	[startno]    bigint not null,
	[startCode] [char](20) NOT NULL,
	[useNo] [bigint]  NULL,
	[useCode] [char](20)  NULL,
	[endno]      bigint not null,
	[endCode] [char](20) NOT NULL,
	[verno]      varchar(10) not null,
	[barcodedefid]  char(1)  not null ,
	[countnum]   Integer  not null,
	[freeAmount] [int] default 0 NOT NULL,
	[bcfilename] varchar(200) not null UNIQUE,
	[filestatus] char(1) not null default '0',
	[sysuserid]  integer  not null ,
	[createTime] datetime default getdate() not null,
	[updateTime] datetime default getdate() not null,
);

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[fileoperation]') AND type in (N'U')) DROP TABLE [fileoperation];
CREATE TABLE [fileoperation] (
    [id] int IDENTITY not null,
	[fileid] integer not null,
	[filestatus] char(1) not null,
	[operation] nvarchar(80) not null,
	[oprstrbar] char(20) null,
	[oprendbar] char(20) null,
	[oprcount]   integer ,
	[sysuserid] integer not null,
	[createtime] datetime not null default getdate()
);

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[bardata]') AND type in (N'U')) DROP TABLE [bardata];
CREATE TABLE [bardata] (
	[id] int IDENTITY not null,
	[code20]    char(20) not null UNIQUE,
	[prodsubtype] char(10) not null,
	[resprodcode] varchar(13) not null,
	[codelv]    tinyint not null,
	[fileid]    integer not null,
	[status]    tinyint not null default 0,
	[updatepc]   varchar(10),
	[taskid]  integer,
	[vbatch]     varchar(20),  
	[firsttime]  datetime default getdate() not null,
	[lasttime]   datetime default getdate()
);

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[bardata000]') AND type in (N'U')) DROP TABLE [bardata000];
CREATE TABLE [bardata000] (
	[id] int IDENTITY not null,
	[code20]    char(20) not null UNIQUE,
	[prodsubtype] char(10) not null,
	[resprodcode] varchar(13) not null,
	[codelv]    tinyint not null,
	[fileid]    integer not null,
	[status]    tinyint not null default 0,
	[updatepc]   varchar(10),
	[taskid]  integer,
	[vbatch]     varchar(20),  
	[firsttime]  datetime default getdate() not null,
	[lasttime]   datetime default getdate()
);

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[drugline]') AND type in (N'U')) DROP TABLE [drugline];
CREATE TABLE [drugline] (
	[id] int IDENTITY not null,
	[lineid] char(4) primary key not null,
	[linename] nvarchar(60) not null,
	[linemaster]  nvarchar(40) not null,
	[lineplace]  nvarchar(60) not null ,
	[sysuserid]  integer  not null ,
	[firsttime] datetime default getdate() not null,
	[updateuser] integer default -1 not null,
	[updatetime] datetime default getdate() not null
);

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[linecomputer]') AND type in (N'U')) DROP TABLE [linecomputer];
CREATE TABLE [linecomputer] (
	[id] int IDENTITY not null,
	[pcid]    char(4) primary key not null,
	[pcname]   nvarchar(60) not null,
	[pcmaster]  nvarchar(40) not null,
	[pcipinfo]  nvarchar(100),
	[pccomment] nvarchar(200),
	[sysuserid]  integer  not null ,
	[firsttime] datetime default getdate() not null,
	[updateuser] integer default -1 not null,
	[updatetime] datetime default getdate() not null
);

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[linepcdrug]') AND type in (N'U')) DROP TABLE [linepcdrug];
CREATE TABLE [linepcdrug] (
	[id] int IDENTITY NOT NULL,
	[productCode] char(7) not null,
	[subTypeNo]  char(10) not null,
	[resprodcode] varchar(13) not null,
	[lineid]   char(4) not null ,
	[pcid]     char(4) not null ,
	[comment] nvarchar(200),
	[sysuserid] integer not null,
	[operatetime]  datetime default getdate() not null,
);

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[productordertask]') AND type in (N'U')) DROP TABLE [productordertask];
CREATE TABLE [productordertask] (
	[id] int primary key IDENTITY NOT NULL,
	[productCode] char(7) not null,
	[subTypeNo]  char(10) not null,
	[resprodcode] varchar(13) not null,
	[batchno]    varchar(30) not null,
	[makedate]   char(10),
	[validdate]  char(10),
	[plancount]  integer not null,
	[nowcount]   integer not null default 0,
	[status]     tinyint not null default 0,
	[boxrtltb]   varchar(20) not null,
	[reserve0]   integer default 0,
	[reserve1]   varchar(30),
	[sysuserid]  integer  not null ,
	[firsttime] datetime default getdate() not null,
	[updateuser] integer default -1 not null,
	[updatetime] datetime default getdate() not null,
	[lastupdate] datetime default getdate() not null,
);

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[productorderdetail]') AND type in (N'U')) DROP TABLE [productorderdetail];
CREATE TABLE [productorderdetail] (
    [id] int IDENTITY NOT NULL,
	[taskid] integer not null  ,
	[showtaskid]  varchar(12) ,
	[lineid]  char(4) not null,
	[pcid] char(4) not null, 
	[taskcount] integer not null default 0,
	[boxsnid] integer not null default 0,
	[status]  tinyint not null default 0,
	[reserve0]   integer default 0,
	[reserve1]   varchar(30),
	[sysuserid]  integer  not null ,
	[firsttime] datetime default getdate() not null,
	[updateuser] integer default -1 not null,
	[updatetime] datetime default getdate() not null,
);

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[clientproddata]') AND type in (N'U')) DROP TABLE [clientproddata];
CREATE TABLE [clientproddata] (
	[id] int IDENTITY NOT NULL,
	[clientid] char(4) not null,
	[productCode] char(7) not null,
	[subTypeNo]  char(10) not null,
	[resprodcode] varchar(13) not null,
	[createtime] datetime not null default getdate(),
	[downloadid] integer not null default 0,
	[downloadtime]  datetime not null default getdate() ,
	[recupdatetime]  datetime not null default getdate(),
	[reservetime0]   datetime not null default getdate(),
	[reservetime1]   datetime not null default getdate(),
	[reservetime2]   datetime not null default getdate()
);

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[productallbox]') AND type in (N'U')) DROP TABLE [productallbox];
CREATE TABLE [productallbox] (
	[taskid] integer not null  ,
	[resprodcode] varchar(13) not null,
	[boxcode] char(20) not null ,
	[codelv]  tinyint not null,
	[lineid]  char(4) not null,
	[pcid]    char(4) not null, 
	[boxflag]  tinyint not null,
	[boxcount]  integer not null,
	[boxbatch]  varchar(30) NOT NULL,
	[boxsnid]   integer not null,
    [maintskid] int not null,
	[boxxmldata] ntext,
	[palletcode] varchar(30),
	[status]  tinyint not null default 0,
	[stockflag] tinyint not null default 0,
	[datatable]  varchar(20) not null,
	[reserve0]   integer default 0,
	[reserve1]   varchar(30),
	[sysuserid]   integer  ,
	[savetime]  datetime default getdate() not null,
	[updateuser] varchar(40),
	[updatetime] datetime
);

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[boxdata000]') AND type in (N'U')) DROP TABLE [boxdata000];
CREATE TABLE [boxdata000] (
	[id] int IDENTITY NOT NULL,
	[prodsubtype] char(10) not null,
	[resprodcode] varchar(13) not null,
	[code20] char(20) not null UNIQUE,
	[parentcode] char(20),
	[codelv]  tinyint not null,
	[lv4code] tinyint default 0 not null,
	[lv3code] tinyint default 0 not null,
	[lv2code] tinyint default 0 not null,
	[lv1code] tinyint default 0 not null,
	[smidcode] char(20),
	[lmidcode] char(20),
	[boxcode] char(20) not null,
	[codeflag] tinyint not null,
	[lineid] char(4) not null,
	[taskid] integer not null,
	[status]  tinyint not null default 0,
	[sysuserid] integer  default -1,
	[savetime]  datetime default getdate() not null,
	[updateuser] integer,
	[updatetime] datetime
);

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[customers]') AND type in (N'U')) DROP TABLE [customers];
CREATE TABLE [customers] (
    [id] int IDENTITY NOT NULL,
	[customerid]  varchar(20) primary key NOT NULL,
	[customername] nvarchar(60) not null,
	[statusflag] tinyint default 0 not  null,
	[shortname]    varchar(60) not null,
	[othersyscode] varchar(20),
	[comment]    nvarchar(200),
	[reserve0]   integer default 0,
	[reserve1]   varchar(30),
	[sysuserid]   integer  not null ,
	[savetime]  datetime default getdate() not null,
	[updateuser] integer,
	[updatetime] datetime default getdate()
);

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[productstores]') AND type in (N'U')) DROP TABLE [productstores];
CREATE TABLE [productstores] (
    [id] int IDENTITY NOT NULL,
	[stoid] char(4) primary key not null,
	[storename] nvarchar(40) not null,
	[comment]   nvarchar(120),
	[reserve0]   integer default 0,
	[reserve1]   varchar(30),
	[sysuserid]   integer  not null ,
	[savetime]  datetime default getdate() not null,
	[updateuser] varchar(40),
	[updatetime] datetime null
);

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[storeoperators]') AND type in (N'U')) DROP TABLE [storeoperators];
CREATE TABLE [storeoperators] (
    [id] int IDENTITY NOT NULL,
	[oprid]  varchar(6) not null primary key,
	[oprname] nvarchar(20) not null,
	[shortname] varchar(20) ,
	[statusflag] tinyint default 0 not  null,
	[oprpwd]  varchar(10) not null,
	[reserve0]   integer default 0,
	[reserve1]   varchar(30),
	[sysuserid]   integer  not null ,
	[savetime]  datetime default getdate() not null,
	[updateuser] integer,
	[updatetime] datetime default getdate()
);

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[warehousepad]') AND type in (N'U')) DROP TABLE [warehousepad];
CREATE TABLE [warehousepad] (
	[id] int IDENTITY NOT NULL,
	[padid]   varchar(4) not null primary key, 
	[padsn]   varchar(50) null, 
	[paduser] nvarchar(20) null, 
	[padtype] varchar(50) not null,
	[reserve0]   integer default 0,
	[reserve1]   varchar(30),
	[sysuserid]   integer  not null,
	[savetime]  datetime default getdate() not null, 
	[updateuser] integer,
	[updatetime] datetime default getdate()
);

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[warehouseticket]') AND type in (N'U')) DROP TABLE [warehouseticket];
CREATE TABLE [warehouseticket] (
    [id] int IDENTITY NOT NULL,	
	[ticketid]    varchar(30) not null,
	[subtckid]    varchar(30) null,
	[stoid]       varchar(4) null,
	[oprid]       varchar(6) null,
	[upcstmid]    varchar(20) null,
	[customerid]  varchar(20) null,
	[ticktype]    char(2) not null,
	[titckdate]   datetime null,
	[pdaid]       varchar(10) null,
	[resprodcode] varchar(13) not null,
	[batchno]     varchar(30) not null,
	[amount]      integer  not null default 0,
	[boxcodenum]  integer  not null default 0,
	[lv1count]    integer  not null default 0,
	[lv2count]    integer  not null default 0,
	[lv3count]    integer  not null default 0,
	[lv4count]    integer  not null default 0,
	[downstatus]  tinyint  not null default 0,
	[orderstatus] tinyint  not null default 0,
	[ticketxmldata]  ntext,
	[othersyscode] varchar(30) null,
	[reserve0]    integer default 0,
	[reserve1]    varchar(30),
	[updateuser]  varchar(40),
	[savetime]    datetime not null default getdate(),
	[updatetime]  datetime not null default getdate()
);

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[warehouseticketdetail]') AND type in (N'U')) DROP TABLE [warehouseticketdetail];
CREATE TABLE [warehouseticketdetail] (
    [id] int IDENTITY NOT NULL,
    [tid] int default 0 not null,
	[ticketid]   varchar(30) not null,
	[subtckid]   varchar(30)  null,
	[ticktype]    char(2) not null,
	[operatype] char(1) not null,
	[code20]     char(20) not null,
	[codelv]     tinyint not null,
	[lv4code]    tinyint default 0 not null,
    [lv3code]    tinyint default 0 not null,
    [lv2code]    tinyint default 0 not null,
    [lv1code]    tinyint default 0 not null,
	[smidcode]   char(20),
	[lmidcode]   char(20),
	[boxcode]    char(20) not null,
	[palletcode] varchar(30),
	[reserve0]   integer default 0,
	[reserve1]   varchar(30),
	[scantime]   datetime  not null ,
	[sysuser]    varchar(40) not null,
	[savetime]   datetime default getdate() not null
);

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[sysparams]') AND type in (N'U')) DROP TABLE [sysparams];
CREATE TABLE [sysparams] (
	[paraname]  varchar(60) not null,
	[paravalue] varchar(200) not  null,
	[paraid]    varchar(10) not null,
	[parasubid] varchar(10) ,
	[comment]   nvarchar(80),
	[paraedit]  tinyint not null default 0
);

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[sysfunction]') AND type in (N'U')) DROP TABLE [sysfunction];
CREATE TABLE [sysfunction] (
	[funcid] int IDENTITY primary key NOT NULL,
	[funcgroup] varchar(20) not null,
	[funcdefine] varchar(20) not null,
	[funcname]   nvarchar(30)not null,
	[comname]    varchar(40) not null,
	[formname]   varchar(20) not null,
	[comment]    nvarchar(60),
	[functype]   tinyint not null ,
	[funcstatus] tinyint not null default 0,
	[reserve0]   integer default 0,
	[reserve1]   varchar(30),
	[sysuser]   varchar(40) not null,
	[savetime]  datetime default getdate() not null,
	[updateuser] varchar(40),
	[updatetime] datetime 
);

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[sysusergroup]') AND type in (N'U')) DROP TABLE [sysusergroup];
CREATE TABLE [sysusergroup] (
	[id] int primary key IDENTITY NOT NULL,
	[groupname]  varchar(40) not null,
	[groupstatus] tinyint not null default 0,
	[adminid] int default 0 not null,
	[operation] varchar(max) null,
	[sysuser]   varchar(40) not null,
	[savetime]  datetime default getdate() not null,
	[updateuser] varchar(40),
	[updatetime] datetime ,
);

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[sysgroupfunc]') AND type in (N'U')) DROP TABLE [sysgroupfunc];
CREATE TABLE [sysgroupfunc] (
	[id] int IDENTITY NOT NULL,
	[groupid] integer not null references sysusergroup(id),
	[funcid]  integer not null references sysfunction(funcid),
	[reserve0]   integer default 0,
	[reserve1]   varchar(30),
	[sysuser]   varchar(40) not null,
	[savetime]  datetime default getdate() not null,
	[updateuser] varchar(40),
	[updatetime] datetime ,
);

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[sysuserlist]') AND type in (N'U')) DROP TABLE [sysuserlist];
CREATE TABLE [sysuserlist] (	
	[id]   int IDENTITY primary key not null, 
	[username]  varchar(40) not null,
	[truename] nvarchar(30) null,
	[userpwd]   varchar(180) not null,
	[usergroup]  integer not null,
	[operation] varchar(3000) NULL,
	[groupadmin] tinyint not  null default 0,
	[pcid]        varchar(200),
	[lineid]      varchar(200),
	[userstatus]  tinyint not null default 0,
	[lastlogtime] datetime ,
	[limitime] datetime NULL,
	[vailddates]  integer not null ,
	[errorls] tinyint default 0 not null,
	[sysuser]   varchar(40) not null,
	[savetime]  datetime default getdate() not null,
	[updateuser] varchar(40),
	[updatetime] datetime default getdate(),
);

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[sysuserfunc]') AND type in (N'U')) DROP TABLE [sysuserfunc];
CREATE TABLE [sysuserfunc] (
	[id] int IDENTITY NOT NULL,
	[userid] integer not null references sysuserlist(id),
	[funcid]  integer not null references sysfunction(funcid),
	[reserve0]   integer default 0,
	[reserve1]   varchar(30),
	[sysuser]   varchar(40) not null,
	[savetime]  datetime default getdate() not null,
	[updateuser] varchar(40),
	[updatetime] datetime ,
);

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[syslogmsg]') AND type in (N'U')) DROP TABLE [syslogmsg];
CREATE TABLE [syslogmsg] (
	[id] int IDENTITY NOT NULL,
	[sysuserid]  integer ,
	[username]   varchar(40),
	[mid]       int default 0 not null,
	[mpid]       int default 0 not null,
	[pcid]       char(4) not null,
	[logmessage] nvarchar(300) ,
	[msgtype]    tinyint not null default 1,
	[showflag]   tinyint not null default 1,
	[comment]    varchar(100),
	[savetime]   datetime not null default getdate(),
);

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[lastvarvalue]') AND type in (N'U')) DROP TABLE [lastvarvalue];
CREATE TABLE [lastvarvalue] (
	[id] int IDENTITY not null,
	[paname]  varchar(20) not null,
	[pavalue] varchar(200) not null
)

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[sysmenu]') AND type in (N'U')) DROP TABLE [sysmenu];
CREATE TABLE [sysmenu] (
  [id] int IDENTITY NOT NULL,
  [mid] int DEFAULT 0 NOT NULL,   
  [msort] tinyint DEFAULT 0 NOT NULL,  
  [pid] int DEFAULT 0 NOT NULL,   
  [name] varchar(50) NOT NULL ,
  [icon] varchar(30) NULL,
  [type] smallint NOT NULL ,
  [url] varchar(100) NOT NULL, 
  [status] tinyint DEFAULT 0 NOT NULL,
  [memo] nvarchar(250) NULL,
  [createTime] datetime DEFAULT getdate() NOT NULL,
  PRIMARY KEY NONCLUSTERED ([mid])
);  

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[codereplace]') AND type in (N'U')) DROP TABLE [codereplace];
CREATE TABLE [codereplace] (
  [id] int IDENTITY NOT NULL,
  [code_old] varchar(20) not null,
  [code_new] varchar(20) not null,
  [codereplace] varchar(20) not null,
  [msg] nvarchar(250) null,
  [createTime] datetime DEFAULT getdate() NOT NULL
); 

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[ProductRelation]') AND type in (N'U')) DROP TABLE [ProductRelation];
CREATE TABLE [ProductRelation] (
	[id] int IDENTITY NOT NULL,
	[fprodCode] [char](20) NULL,
	[sprodCode] [char](20) NULL,
	[blevel] tinyint default 0  NOT NULL,
	[bcount] int default 0 not null,
	[statusFlag] tinyint DEFAULT 0 NOT NULL,
	[createTime]  datetime DEFAULT getdate() NOT NULL,
	[updateTime]   datetime DEFAULT getdate() NOT NULL
); 
