SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[QAUserInfo]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[QAUserInfo](
	[UserName] [nvarchar](256) NOT NULL,
	[Mark] [int] NULL,
	[AnswerMark] [int] NULL,
	[RewardMark] [int] NULL,
	[PaidMark] [int] NULL,
	[PunishMark] [int] NULL,
	[SolvedQuestion] [int] NULL,
	[AnswerCount] [int] NULL,
	[AnswerAcceptCount] [int] NULL,
	[QuestionSolvedCount] [int] NULL,
	[QuestionUnsolveCount] [int] NULL,
	[QuestionCancelledCount] [int] NULL,
 CONSTRAINT [PK_tblQAUserInfo] PRIMARY KEY CLUSTERED 
(
	[UserName] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[QACatalog]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[QACatalog](
	[Id]		[int] NOT NULL,
	[ParentID]	[int] NOT NULL,
	[Layer]			[int] NOT NULL,
	[Name]			nvarchar](50) NOT NULL,
	[Status]		 [bit] NOT NULL,
	[DisplayOrder] [int] NOT NULL,
 CONSTRAINT [PK_tblQACatalog] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[QAQuestion]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[QAQuestion](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[CatalogId] [int] foreign key references [QACatalog](Id) ON Delete CASCADE NOT NULL,
	[UserName] [nvarchar](256) foreign key references [QAUserInfo](UserName) NOT NULL,
	[Title] [nvarchar](100) NOT NULL,
	[Text] [ntext] NOT NULL,
	[AdditionText] [ntext] NULL,
	[Mark] [int] NOT NULL CONSTRAINT [DF_tblQAQuestion_Mark]  DEFAULT ((20)),
	[PostDatetime] [datetime] NOT NULL,
	[State] [int] NOT NULL CONSTRAINT [DF_tblQAQuestion_Condition]  DEFAULT ((0)),
 CONSTRAINT [PK_tblQAQuestion] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[QAAnswer]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[QAAnswer](
	[Id]	[int] IDENTITY(1,1) NOT NULL,
	[QId]			[int] foreign key references [QAQuestion](Id) ON Delete CASCADE NOT NULL,
	[UserName]		[nvarchar](256) foreign key references [QAUserInfo](UserName) NOT NULL,
	[Text]			[ntext] NOT NULL,
	[BestAnswer]	[bit] NOT NULL CONSTRAINT [DF_tblQAAnswer_BestAnswer]  DEFAULT ((0)),
	[PostDatetime]	[datetime] NOT NULL,
	[VoteNice]		[int] NOT NULL CONSTRAINT [DF_tblQAAnswer_Vote]  DEFAULT ((0)),
	[VoteBad]		[int] NOT NULL CONSTRAINT [DF_tblQAAnswer_VoteBad]  DEFAULT ((0)),
 CONSTRAINT [PK_tblQAAnswer] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[QAConfig]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[QAConfig](
	[Solved] [int] NOT NULL DEFAULT ((0)),
	[Unsolve] [int] NOT NULL DEFAULT ((0))
) ON [PRIMARY]
END
