/*********    Ini Tables (AttParam”¢auth_user)    *********/ 
/**********************************************************************
select * from dbo.sysobjects where id = object_id(N'[dbo].[±ķĆū]') 
and OBJECTPROPERTY(id, N'IsUserTable') = 1
**********************************************************************/

/****************************** Access *******************************/
/****** Table [dbo].[action_log]  DateTime: 01/25/2013 17:34:29 ******/
if not exists (select * from dbo.sysobjects where name = 'action_log' and xtype = 'U')
CREATE TABLE [dbo].[action_log](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[action_time] [datetime] NULL,
	[user_id] [int] NULL,
	[content_type_id] [int] NULL,
	[object_id] [int] NULL,
	[object_repr] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[action_flag] [int] NULL,
	[change_message] [nvarchar](500) COLLATE Chinese_PRC_CI_AS NULL,
PRIMARY KEY CLUSTERED 
(
	[id] ASC
) ON [PRIMARY]
) ON [PRIMARY]

/****** Table [dbo].[acc_map]  DateTime: 01/25/2013 17:34:29 ******/
if not exists (select * from dbo.sysobjects where name = 'acc_map' and xtype = 'U')
CREATE TABLE [dbo].[acc_map](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[change_operator] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[change_time] [datetime] NULL,
	[create_operator] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[create_time] [datetime] NULL,
	[delete_operator] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[delete_time] [datetime] NULL,
	[status] [int] NOT NULL CONSTRAINT [default_value_acc_map_status]  DEFAULT ('0'),
	[map_name] [nvarchar](30) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [default_value_acc_map_map_name]  DEFAULT (''),
	[map_path] [nvarchar](max) COLLATE Chinese_PRC_CI_AS NULL,
	[area_id] [int] NULL,
	[width] [int] NULL CONSTRAINT [default_value_acc_map_width]  DEFAULT ('0'),
	[height] [int] NULL CONSTRAINT [default_value_acc_map_height]  DEFAULT ('0'),
PRIMARY KEY CLUSTERED 
(
	[id] ASC
) ON [PRIMARY]
) ON [PRIMARY]

/****** Table [dbo].[AttParam]  DateTime: 01/25/2013 17:34:29 ******/
if not exists (select * from dbo.sysobjects where name = 'AttParam' and xtype = 'U')
begin
CREATE TABLE [dbo].[AttParam](
	[PARANAME] [nvarchar](20) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[PARATYPE] [nvarchar](2) COLLATE Chinese_PRC_CI_AS NULL,
	[PARAVALUE] [nvarchar](100) COLLATE Chinese_PRC_CI_AS NOT NULL,
PRIMARY KEY CLUSTERED 
(
	[PARANAME] ASC
) ON [PRIMARY]
) ON [PRIMARY]
insert into AttParam(ParaName,ParaValue) values('DBVersion',404);
insert into AttParam(ParaName,ParaValue) values('DBVersionAccess',2);
insert into AttParam(ParaName,ParaValue) values('DBVersionPatrol',2);
end

/****** Table [dbo].[auth_group]  DateTime: 01/25/2013 17:34:29 ******/
if not exists (select * from dbo.sysobjects where name = 'auth_group' and xtype = 'U')
CREATE TABLE [dbo].[auth_group](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[name] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[Permission] [nvarchar](max) COLLATE Chinese_PRC_CI_AS NULL,
	[Remark] [nvarchar](max) COLLATE Chinese_PRC_CI_AS NULL,
PRIMARY KEY CLUSTERED 
(
	[id] ASC
) ON [PRIMARY],
UNIQUE NONCLUSTERED 
(
	[name] ASC
) ON [PRIMARY]
) ON [PRIMARY]

/****** Table [dbo].[auth_user]  DateTime: 01/25/2013 17:34:29 ******/
if not exists (select * from dbo.sysobjects where name = 'auth_user' and xtype = 'U')
begin
CREATE TABLE [dbo].[auth_user](
	[id] [int] IDENTITY(1,1) NOT NULL primary key,
	[username] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[password] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[Status] [int] NULL,
	[last_login] [datetime] NULL,
	[RoleID] [int] NULL,
	[Remark] [nvarchar](max) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
insert into Auth_User(username,password,Status,RoleID,Remark) values('admin','admin',1,0,'');
end

/****** Table [dbo].[DEPARTMENTS]  DateTime: 01/25/2013 17:34:29 ******/
if not exists (select * from dbo.sysobjects where name = 'DEPARTMENTS' and xtype = 'U')
CREATE TABLE [dbo].[DEPARTMENTS](
	[DEPTID] [int] IDENTITY(1,1) NOT NULL,
	[DEPTNAME] [nvarchar](30) COLLATE Chinese_PRC_CI_AS NULL,
	[SUPDEPTID] [int] NOT NULL DEFAULT ((1)),
	[InheritParentSch] [smallint] NULL DEFAULT ((1)),
	[InheritDeptSch] [smallint] NULL DEFAULT ((1)),
	[InheritDeptSchClass] [smallint] NULL DEFAULT ((1)),
	[AutoSchPlan] [smallint] NULL DEFAULT ((1)),
	[InLate] [smallint] NULL DEFAULT ((1)),
	[OutEarly] [smallint] NULL DEFAULT ((1)),
	[InheritDeptRule] [smallint] NULL DEFAULT ((1)),
	[MinAutoSchInterval] [int] NULL DEFAULT ((24)),
	[RegisterOT] [smallint] NULL DEFAULT ((1)),
	[DefaultSchId] [int] NOT NULL DEFAULT ((1)),
	[ATT] [smallint] NULL DEFAULT ((1)),
	[Holiday] [smallint] NULL DEFAULT ((1)),
	[OverTime] [smallint] NULL DEFAULT ((1)),
	[change_operator] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[change_time] [datetime] NULL,
	[create_operator] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[create_time] [datetime] NULL,
	[delete_operator] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[delete_time] [datetime] NULL,
	[status] [int] NULL,
	[code] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[type] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[invalidate] [datetime] NULL,
 CONSTRAINT [DEPTID] PRIMARY KEY CLUSTERED 
(
	[DEPTID] ASC
) ON [PRIMARY]
) ON [PRIMARY]

/****** Table [dbo].[personnel_area]  DateTime: 01/25/2013 17:34:29 ******/
if not exists (select * from dbo.sysobjects where name = 'personnel_area' and xtype = 'U')
CREATE TABLE [dbo].[personnel_area](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[change_operator] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[change_time] [datetime] NULL,
	[create_operator] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[create_time] [datetime] NULL,
	[delete_operator] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[delete_time] [datetime] NULL,
	[status] [smallint] NOT NULL CONSTRAINT [default_value_personnel_area_status]  DEFAULT ('0'),
	[areaid] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[areaname] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[parent_id] [int] NULL DEFAULT ((0)),
	[remark] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
PRIMARY KEY CLUSTERED 
(
	[id] ASC
) ON [PRIMARY]
) ON [PRIMARY]

/****** Table [dbo].[personnel_issuecard]  DateTime: 01/25/2013 17:34:29 ******/
if not exists (select * from dbo.sysobjects where name = 'personnel_issuecard' and xtype = 'U')
CREATE TABLE [dbo].[personnel_issuecard](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[change_operator] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[change_time] [datetime] NULL,
	[create_operator] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[create_time] [datetime] NULL,
	[delete_operator] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[delete_time] [datetime] NULL,
	[status] [int] NULL,
	[UserID_id] [int] NULL,
	[cardno] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[effectivenessdate] [datetime] NULL,
	[isvalid] [bit] NOT NULL DEFAULT ('1'),
	[cardpwd] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[failuredate] [datetime] NULL,
	[cardstatus] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL DEFAULT ('1'),
	[issuedate] [datetime] NULL DEFAULT ('2011-07-15'),
PRIMARY KEY CLUSTERED 
(
	[id] ASC
) ON [PRIMARY]
) ON [PRIMARY]

/****** Table [dbo].[SystemLog]  DateTime: 12/13/2013 10:28:29 ******/
if not exists (select * from dbo.sysobjects where name = 'SystemLog' and xtype = 'U')
CREATE TABLE [dbo].[SystemLog](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[Operator] [varchar](20) COLLATE Chinese_PRC_CI_AS NULL,
	[LogTime] [datetime] NULL DEFAULT (getdate()),
	[MachineAlias] [varchar](20) COLLATE Chinese_PRC_CI_AS NULL,
	[LogTag] [smallint] NULL,
	[LogDescr] [varchar](50) COLLATE Chinese_PRC_CI_AS NULL,
PRIMARY KEY CLUSTERED 
(
	[ID] ASC
) ON [PRIMARY]
) ON [PRIMARY]

/****** Table [dbo].[TEMPLATE]  DateTime: 01/25/2013 17:34:29 ******/
if not exists (select * from dbo.sysobjects where name = 'TEMPLATE' and xtype = 'U')
CREATE TABLE [dbo].[TEMPLATE](
	[TEMPLATEID] [int] IDENTITY(1,1) NOT NULL,
	[USERID] [int] NOT NULL,
	[FINGERID] [int] NOT NULL DEFAULT ('0'),
	[TEMPLATE] [image] NULL,
	[TEMPLATE2] [image] NULL,
	[BITMAPPICTURE] [image] NULL,
	[BITMAPPICTURE2] [image] NULL,
	[BITMAPPICTURE3] [image] NULL,
	[BITMAPPICTURE4] [image] NULL,
	[USETYPE] [smallint] NULL,
	[EMACHINENUM] [nvarchar](3) COLLATE Chinese_PRC_CI_AS NULL,
	[TEMPLATE1] [image] NULL,
	[Flag] [smallint] NULL,
	[DivisionFP] [smallint] NULL,
	[TEMPLATE4] [image] NULL,
	[TEMPLATE3] [image] NULL,
	[change_operator] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[change_time] [datetime] NULL,
	[create_operator] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[create_time] [datetime] NULL,
	[delete_operator] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[delete_time] [datetime] NULL,
	[status] [int] NULL,
	[Valid] [int] NULL DEFAULT ('1'),
	[Fpversion] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[bio_type] [int] NULL DEFAULT ('0'),
	[SN] [int] NULL,
	[UTime] [datetime] NULL,
PRIMARY KEY CLUSTERED 
(
	[TEMPLATEID] ASC
) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

/****** Table [dbo].[USERINFO]  DateTime: 01/25/2013 17:34:29 ******/
if not exists (select * from dbo.sysobjects where name = 'USERINFO' and xtype = 'U')
CREATE TABLE [dbo].[USERINFO](
	[USERID] [int] IDENTITY(1,1) NOT NULL,
	[Badgenumber] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[SSN] [nvarchar](20) COLLATE Chinese_PRC_CI_AS NULL,
	[Name] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[Gender] [nvarchar](8) COLLATE Chinese_PRC_CI_AS NULL,
	[TITLE] [nvarchar](20) COLLATE Chinese_PRC_CI_AS NULL,
	[PAGER] [nvarchar](20) COLLATE Chinese_PRC_CI_AS NULL,
	[BIRTHDAY] [datetime] NULL,
	[HIREDDAY] [datetime] NULL,
	[street] [nvarchar](80) COLLATE Chinese_PRC_CI_AS NULL,
	[CITY] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[STATE] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[ZIP] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[OPHONE] [nvarchar](20) COLLATE Chinese_PRC_CI_AS NULL,
	[FPHONE] [nvarchar](20) COLLATE Chinese_PRC_CI_AS NULL,
	[VERIFICATIONMETHOD] [smallint] NULL,
	[DEFAULTDEPTID] [int] NULL DEFAULT ((1)),
	[SECURITYFLAGS] [smallint] NULL,
	[ATT] [smallint] NOT NULL DEFAULT ((1)),
	[INLATE] [smallint] NOT NULL DEFAULT ((1)),
	[OUTEARLY] [smallint] NOT NULL DEFAULT ((1)),
	[OVERTIME] [smallint] NOT NULL DEFAULT ((1)),
	[SEP] [smallint] NOT NULL DEFAULT ((1)),
	[HOLIDAY] [smallint] NOT NULL DEFAULT ((1)),
	[MINZU] [nvarchar](8) COLLATE Chinese_PRC_CI_AS NULL,
	[PASSWORD] [nvarchar](20) COLLATE Chinese_PRC_CI_AS NULL,
	[LUNCHDURATION] [smallint] NULL,
	[PHOTO] [image] NULL,
	[mverifypass] [nvarchar](10) COLLATE Chinese_PRC_CI_AS NULL,
	[Notes] [image] NULL,
	[privilege] [int] NULL DEFAULT ((0)),
	[InheritDeptSch] [smallint] NULL,
	[InheritDeptSchClass] [smallint] NULL,
	[AutoSchPlan] [smallint] NULL DEFAULT ((1)),
	[MinAutoSchInterval] [int] NULL DEFAULT ((24)),
	[RegisterOT] [smallint] NULL DEFAULT ((1)),
	[InheritDeptRule] [smallint] NULL,
	[EMPRIVILEGE] [smallint] NULL,
	[CardNo] [nvarchar](20) COLLATE Chinese_PRC_CI_AS NULL,
                   [Pin1] [int] NULL DEFAULT ((0)),
	[change_operator] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[change_time] [datetime] NULL,
	[create_operator] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[create_time] [datetime] NULL,
	[delete_operator] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[delete_time] [datetime] NULL,
	[status] [int] NULL DEFAULT ('0'),
	[lastname] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[AccGroup] [int] NULL,
	[TimeZones] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[identitycard] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[UTime] [datetime] NULL,
	[Education] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[OffDuty] [int] NULL,
	[DelTag] [int] NULL,
	[morecard_group_id] [int] NULL,
	[set_valid_time] [bit] NULL,
	[acc_startdate] [datetime] NULL,
	[acc_enddate] [datetime] NULL,
	[birthplace] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[Political] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[contry] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[hiretype] [int] NULL,
	[email] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[firedate] [datetime] NULL,
	[isatt] [bit] NULL,
	[homeaddress] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[emptype] [int] NULL,
	[bankcode1] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[bankcode2] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[isblacklist] [int] NULL,
	[Iuser1] [int] NULL,
	[Iuser2] [int] NULL,
	[Iuser3] [int] NULL,
	[Iuser4] [int] NULL,
	[Iuser5] [int] NULL,
	[Cuser1] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[Cuser2] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[Cuser3] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[Cuser4] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[Cuser5] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[Duser1] [datetime] NULL,
	[Duser2] [datetime] NULL,
	[Duser3] [datetime] NULL,
	[Duser4] [datetime] NULL,
	[Duser5] [datetime] NULL,
PRIMARY KEY CLUSTERED 
(
	[USERID] ASC
) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

/****************************** Patrol *******************************/
/****** Object:  Table [dbo].[GP_Device]    Script Date: 08/19/2014 11:28:02 ******/
if not exists (select * from dbo.sysobjects where name = 'GP_Device' and xtype = 'U')
CREATE TABLE [dbo].[GP_Device](
	[ReaderID] [smallint] NOT NULL,
	[RouteID] [int] NULL,
	[SerialNumber] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[IsOnlyRFMachine] [tinyint] NULL,
	[Routes] [varchar](255) COLLATE Chinese_PRC_CI_AS NULL,
	[DateFmt] [tinyint] NULL,
	[VSMode] [tinyint] NULL,
	[VSSite] [bit] NOT NULL,
	[IdleMinute] [smallint] NULL,
PRIMARY KEY CLUSTERED 
(
	[ReaderID] ASC
) ON [PRIMARY]
) ON [PRIMARY]

/****** Table [dbo].[GP_Event]  DateTime: 01/25/2013 17:34:29 ******/
if not exists (select * from dbo.sysobjects where name = 'GP_Event' and xtype = 'U')
CREATE TABLE [dbo].[GP_Event](
	[EventID] [int] IDENTITY(1,1) NOT NULL,
	[EventName] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[EventCard] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[Remark] [nvarchar](255) COLLATE Chinese_PRC_CI_AS NULL,
PRIMARY KEY CLUSTERED 
(
	[EventID] ASC
) ON [PRIMARY]
) ON [PRIMARY]

/****** Table [dbo].[GP_HisEvent]  DateTime: 01/25/2013 17:34:29 ******/
if not exists (select * from dbo.sysobjects where name = 'GP_HisEvent' and xtype = 'U')
CREATE TABLE [dbo].[GP_HisEvent](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[EventID] [int] NULL,
	[EventName] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[EventCard] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[StartTime] [datetime] NULL,
	[FinishTime] [datetime] NULL,
PRIMARY KEY CLUSTERED 
(
	[ID] ASC
) ON [PRIMARY]
) ON [PRIMARY]

/****** Table [dbo].[GP_HisPersonnel]  DateTime: 01/25/2013 17:34:29 ******/
if not exists (select * from dbo.sysobjects where name = 'GP_HisPersonnel' and xtype = 'U')
CREATE TABLE [dbo].[GP_HisPersonnel](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[Pin2] [int] NULL,
	[Name] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[LastName] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[UserCard] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[StartTime] [datetime] NULL,
	[FinishTime] [datetime] NULL,
PRIMARY KEY CLUSTERED 
(
	[ID] ASC
) ON [PRIMARY]
) ON [PRIMARY]

/****** Table [dbo].[GP_HisRoute]  DateTime: 01/25/2013 17:34:29 ******/
if not exists (select * from dbo.sysobjects where name = 'GP_HisRoute' and xtype = 'U')
CREATE TABLE [dbo].[GP_HisRoute](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[RouteID] [int] NULL,
	[RouteName] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[Tags] [varchar](8000) Not NULL,
	[Events] [varchar](1024) NULL,	
	[Intervals] [varchar](8000) NULL,
	[Errors]  [varchar](8000) NULL,
	[RoundMin] [smallint] NULL,
	[BeforeMin] [smallint] NULL,
                   [AfterMin] [smallint] NULL,
	[Style] [tinyint] NULL,
	[IsBatch] [bit] NOT NULL,
	[IsGroup] [bit] NOT NULL,
	[StartTime] [datetime] NULL,
	[FinishTime] [datetime] NULL,
PRIMARY KEY CLUSTERED 
(
	[ID] ASC
) ON [PRIMARY]
) ON [PRIMARY]

/****** Table [dbo].[GP_HisTag]  DateTime: 01/25/2013 17:34:29 ******/
if not exists (select * from dbo.sysobjects where name = 'GP_HisTag' and xtype = 'U')
CREATE TABLE [dbo].[GP_HisTag](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[TagID] [int] NULL,
	[TagName] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[TagSN] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,	
	[Style] [tinyint] NULL,
	[StartTime] [datetime] NULL,
	[FinishTime] [datetime] NULL,
PRIMARY KEY CLUSTERED 
(
	[ID] ASC
) ON [PRIMARY]
) ON [PRIMARY]

/****** Object:  Table [dbo].[GP_IDENTITY]    Script Date: 08/19/2014 11:28:02 ******/
if not exists (select * from dbo.sysobjects where name = 'GP_IDENTITY' and xtype = 'U')
begin
  CREATE TABLE [dbo].[GP_IDENTITY](
	  [id] [int] NOT NULL
  ) ON [PRIMARY]
  declare @id int
  set @id = 0
  while @id < 1000
  begin
    insert GP_IDENTITY(id) Values(@id)
    set @id = @id + 1
  end
end

/****** Object:  Table [dbo].[GP_MapLine]    Script Date: 08/19/2014 11:28:02 ******/
if not exists (select * from dbo.sysobjects where name = 'GP_MapLine' and xtype = 'U')
CREATE TABLE [dbo].[GP_MapLine](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[MapID] [tinyint] NULL,
	[TagAID] [int] NULL,
	[TagBID] [int] NULL,
PRIMARY KEY CLUSTERED 
(
	[ID] ASC
) ON [PRIMARY]
) ON [PRIMARY]

/****** Object:  Table [dbo].[GP_MapTag]    Script Date: 08/19/2014 11:28:02 ******/
if not exists (select * from dbo.sysobjects where name = 'GP_MapTag' and xtype = 'U')
CREATE TABLE [dbo].[GP_MapTag](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[MapID] [tinyint] NULL,
	[TagID] [int] NULL,
	[PointX] [int] NULL,
	[PointY] [int] NULL,
PRIMARY KEY CLUSTERED 
(
	[ID] ASC
) ON [PRIMARY]
) ON [PRIMARY]

/****** Table [dbo].[GP_Personnel]  DateTime: 01/25/2013 17:34:29 ******/
if not exists (select * from dbo.sysobjects where name = 'GP_Personnel' and xtype = 'U')
CREATE TABLE [dbo].[GP_Personnel](
	[Pin2] [int] NOT NULL,
	[UserGroup] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[UserType] [tinyint] NULL
) ON [PRIMARY]

/****** Table [dbo].[GP_Record]  DateTime: 01/25/2013 17:34:29 ******/
if not exists (select * from dbo.sysobjects where name = 'GP_Record' and xtype = 'U')
CREATE TABLE [dbo].[GP_Record](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[ReaderID] [smallint] NULL,
	[RouteID] [int] NULL,
	[TagID] [int] NULL,
	[Pin2] [int] NULL,
	[ReadingTime] [datetime] NULL,	
	[PlanID] [int] NULL,
	[Flag] [tinyint] NULL,
	[VSNeed] [tinyint] NULL,
	[VSReal] [tinyint] NULL,
	[Events] [varchar](255) COLLATE Chinese_PRC_CI_AS NULL,
	[Remark] [nvarchar](max) NULL,
PRIMARY KEY CLUSTERED 
(
	[ID] ASC
) ON [PRIMARY]
) ON [PRIMARY]

/****** Table [dbo].[GP_Route]  DateTime: 01/25/2013 17:34:29 ******/
if not exists (select * from dbo.sysobjects where name = 'GP_Route' and xtype = 'U')
CREATE TABLE [dbo].[GP_Route](
	[RouteID] [int] IDENTITY(1,1) NOT NULL,
	[RouteName] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[Tags] [varchar](8000) Not NULL,
	[Events] [varchar](1024) NULL,	
	[Intervals] [varchar](8000) NULL,
	[Errors]  [varchar](8000) NULL,
	[RoundMin] [smallint] NULL,
	[BeforeMin] [smallint] NULL,
                   [AfterMin] [smallint] NULL,
	[Style] [tinyint] NULL,
	[IsBatch] [bit] NOT NULL,
	[IsGroup] [bit] NOT NULL,
PRIMARY KEY CLUSTERED 
(
	[RouteID] ASC
) ON [PRIMARY]
) ON [PRIMARY]

/****** Table [dbo].[GP_Tag]  DateTime: 01/25/2013 17:34:29 ******/
if not exists (select * from dbo.sysobjects where name = 'GP_Tag' and xtype = 'U')
CREATE TABLE [dbo].[GP_Tag](
	[TagID] [int] IDENTITY(1,1) NOT NULL,
	[TagName] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[TagSN] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,	
	[Style] [tinyint] NULL,
	[Active] [bit] NOT NULL,
PRIMARY KEY CLUSTERED 
(
	[TagID] ASC
) ON [PRIMARY]
) ON [PRIMARY]

/****** Object:  Table [dbo].[GP_Task]    Script Date: 08/19/2014 11:28:02 ******/
if not exists (select * from dbo.sysobjects where name = 'GP_Task' and xtype = 'U')
CREATE TABLE [dbo].[GP_Task](
	[TaskID] [int] IDENTITY(1,1) NOT NULL,
	[RouteID] [int] NULL,
	[StartTime] [nvarchar](20) NULL,
	[FinishTime] [nvarchar](20) NULL,
	[OutOfDay] [bit] NOT NULL,
	[Weeks] [varchar](50) NULL,
	[Flag] [tinyint] NULL,
	[CreateTime] [datetime] NULL,
PRIMARY KEY CLUSTERED 
(
	[TaskID] ASC
) ON [PRIMARY]
) ON [PRIMARY]

/****** Object:  Table [dbo].[GP_Plan]    Script Date: 10/29/2014 11:32:02 ******/
if not exists (select * from dbo.sysobjects where name = 'GP_Plan' and xtype = 'U')
CREATE TABLE [dbo].[GP_Plan](
	[PlanID] [int] IDENTITY(1,1) NOT NULL,
	[PlanDate] [nvarchar](50) NULL,
	[StartTime] [nvarchar](50) NULL,
	[FinishTime] [nvarchar](50) NULL,
	[OutOfDay] [bit] NOT NULL,
	[RouteID] [smallint] NULL,
	[Pin2] [int] NULL,
	[Qualified] [bit] NULL,
	[Validation] [bit] NULL,
	[OverTime] [bit] NULL,
	[RepPatrol] [bit] NULL,
	[MorePoint] [bit] NULL,
	[ErrorPoint] [bit] NULL,
	[LeakPoint] [bit] NULL,
	[Absence] [bit] NULL,
	[Style] [tinyint] NULL,
PRIMARY KEY CLUSTERED 
(
	[PlanID] ASC
) ON [PRIMARY]
) ON [PRIMARY]
