if exists (select * from dbo.sysobjects where id = object_id(N'[OperationLog]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [OperationLog]
GO

CREATE TABLE [OperationLog] (
	[pkId] [int] IDENTITY (1, 1) NOT NULL ,
	[operation] [varchar] (255) COLLATE Chinese_PRC_CI_AS NULL ,
	[operationUserName] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[operationIp] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[operationTime] [datetime] NULL ,
	[remark] [text] COLLATE Chinese_PRC_CI_AS NULL ,
	[type] [int] NULL ,
	[operationResult] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	CONSTRAINT [PK_OperationLog] PRIMARY KEY  CLUSTERED 
	(
		[pkId]
	)  ON [PRIMARY] 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO


if exists (select * from dbo.sysobjects where id = object_id(N'[questionnaireSpecial]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [questionnaireSpecial]
GO

CREATE TABLE [questionnaireSpecial] (
	[pkId] [int] IDENTITY (1, 1) NOT NULL ,
	[bigClassId] [int] NULL ,
	[questionnaireSpecialName] [varchar] (1000) COLLATE Chinese_PRC_CI_AS NULL ,
	[validDays] [int] NULL ,
	[gate] [int] NULL ,
	[gradeId] [int] NULL ,
	[IsAnonymity] [int] NULL ,
	[restrictObject] [int] NULL ,
	[restrictMode] [int] NULL ,
	[restrictTime] [int] NULL ,
	[IsVerify] [int] NULL ,
	[generateDate] [datetime] NULL ,
	[IsShow] [int] NULL ,
	CONSTRAINT [PK_QUESTIONNAIRESPECIAL] PRIMARY KEY  CLUSTERED 
	(
		[pkId]
	)  ON [PRIMARY] 
) ON [PRIMARY]
GO


if exists (select * from dbo.sysobjects where id = object_id(N'[question]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [question]
GO

CREATE TABLE [question] (
	[pkId] [int] IDENTITY (1, 1) NOT NULL ,
	[questionnaireSpecialId] [int] NULL ,
	[questionName] [varchar] (1000) COLLATE Chinese_PRC_CI_AS NULL ,
	[NotNull] [int] NULL ,
	[optionsType] [int] NULL ,
	[optionsCount] [int] NULL ,
	CONSTRAINT [PK_QUESTION] PRIMARY KEY  CLUSTERED 
	(
		[pkId]
	)  ON [PRIMARY] 
) ON [PRIMARY]
GO


if exists (select * from dbo.sysobjects where id = object_id(N'[options]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [options]
GO

CREATE TABLE [options] (
	[pkId] [int] IDENTITY (1, 1) NOT NULL ,
	[questionId] [int] NULL ,
	[IsTextbox] [int] NULL ,
	[optionsName] [varchar] (1000) COLLATE Chinese_PRC_CI_AS NULL ,
	[counter] [int] NULL ,
	[isPic] [int] NULL ,
	CONSTRAINT [PK_OPTIONS] PRIMARY KEY  CLUSTERED 
	(
		[pkId]
	)  ON [PRIMARY] 
) ON [PRIMARY]
GO


if exists (select * from dbo.sysobjects where id = object_id(N'[IPInfo]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [IPInfo]
GO

CREATE TABLE [IPInfo] (
	[pkId] [int] IDENTITY (1, 1) NOT NULL ,
	[questionnaireSpecialId] [int] NULL ,
	[IP] [bigint] NULL ,
	[date] [datetime] NULL ,
	CONSTRAINT [PK_IPINFO] PRIMARY KEY  CLUSTERED 
	(
		[pkId]
	)  ON [PRIMARY] 
) ON [PRIMARY]
GO


if exists (select * from dbo.sysobjects where id = object_id(N'[answer]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [answer]
GO

CREATE TABLE [answer] (
	[pkId] [int] IDENTITY (1, 1) NOT NULL ,
	[questionId] [int] NULL ,
	[optionsId] [int] NULL ,
	[userId] [int] NULL ,
	[IP] [bigint] NULL ,
	[date] [datetime] NULL ,
	[Message] [text] COLLATE Chinese_PRC_CI_AS NULL ,
	[userName] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	CONSTRAINT [PK_ANSWER] PRIMARY KEY  CLUSTERED 
	(
		[pkId]
	)  ON [PRIMARY] 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO


