USE [master]
GO
/****** Object:  Database [forum]    Script Date: 01.04.2016 10:13:59 ******/
CREATE DATABASE [forum]
 CONTAINMENT = NONE
 ON  PRIMARY 
( NAME = N'forum', FILENAME = N'C:\Program Files (x86)\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\forum.mdf' , SIZE = 5120KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
 LOG ON 
( NAME = N'forum_log', FILENAME = N'C:\Program Files (x86)\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\forum_log.ldf' , SIZE = 2048KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO
ALTER DATABASE [forum] SET COMPATIBILITY_LEVEL = 120
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [forum].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
ALTER DATABASE [forum] SET ANSI_NULL_DEFAULT OFF 
GO
ALTER DATABASE [forum] SET ANSI_NULLS OFF 
GO
ALTER DATABASE [forum] SET ANSI_PADDING OFF 
GO
ALTER DATABASE [forum] SET ANSI_WARNINGS OFF 
GO
ALTER DATABASE [forum] SET ARITHABORT OFF 
GO
ALTER DATABASE [forum] SET AUTO_CLOSE OFF 
GO
ALTER DATABASE [forum] SET AUTO_SHRINK OFF 
GO
ALTER DATABASE [forum] SET AUTO_UPDATE_STATISTICS ON 
GO
ALTER DATABASE [forum] SET CURSOR_CLOSE_ON_COMMIT OFF 
GO
ALTER DATABASE [forum] SET CURSOR_DEFAULT  GLOBAL 
GO
ALTER DATABASE [forum] SET CONCAT_NULL_YIELDS_NULL OFF 
GO
ALTER DATABASE [forum] SET NUMERIC_ROUNDABORT OFF 
GO
ALTER DATABASE [forum] SET QUOTED_IDENTIFIER OFF 
GO
ALTER DATABASE [forum] SET RECURSIVE_TRIGGERS OFF 
GO
ALTER DATABASE [forum] SET  DISABLE_BROKER 
GO
ALTER DATABASE [forum] SET AUTO_UPDATE_STATISTICS_ASYNC OFF 
GO
ALTER DATABASE [forum] SET DATE_CORRELATION_OPTIMIZATION OFF 
GO
ALTER DATABASE [forum] SET TRUSTWORTHY OFF 
GO
ALTER DATABASE [forum] SET ALLOW_SNAPSHOT_ISOLATION OFF 
GO
ALTER DATABASE [forum] SET PARAMETERIZATION SIMPLE 
GO
ALTER DATABASE [forum] SET READ_COMMITTED_SNAPSHOT OFF 
GO
ALTER DATABASE [forum] SET HONOR_BROKER_PRIORITY OFF 
GO
ALTER DATABASE [forum] SET RECOVERY SIMPLE 
GO
ALTER DATABASE [forum] SET  MULTI_USER 
GO
ALTER DATABASE [forum] SET PAGE_VERIFY CHECKSUM  
GO
ALTER DATABASE [forum] SET DB_CHAINING OFF 
GO
ALTER DATABASE [forum] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) 
GO
ALTER DATABASE [forum] SET TARGET_RECOVERY_TIME = 0 SECONDS 
GO
ALTER DATABASE [forum] SET DELAYED_DURABILITY = DISABLED 
GO
USE [forum]
GO
/****** Object:  Table [dbo].[ban_list]    Script Date: 01.04.2016 10:13:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ban_list](
	[user_id] [int] NOT NULL,
	[reason] [nvarchar](max) NOT NULL,
	[unban_date] [date] NULL,
 CONSTRAINT [PK_ban_list] PRIMARY KEY CLUSTERED 
(
	[user_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]

GO
/****** Object:  Table [dbo].[global_stats]    Script Date: 01.04.2016 10:13:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[global_stats](
	[current_online] [int] NOT NULL,
	[user_count] [int] NOT NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[log]    Script Date: 01.04.2016 10:13:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[log](
	[id] [int] NOT NULL,
	[type] [int] NOT NULL,
	[message] [nvarchar](max) NOT NULL,
	[date] [date] NOT NULL,
 CONSTRAINT [PK_log] 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]

GO
/****** Object:  Table [dbo].[posts]    Script Date: 01.04.2016 10:13:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[posts](
	[post_id] [int] NOT NULL,
	[topic_id] [int] NOT NULL,
	[own_user_id] [int] NOT NULL,
	[hidden_by_user] [int] NULL,
	[modded_by_user] [int] NULL,
	[last_mod_date] [date] NULL,
	[text] [nvarchar](3000) NOT NULL,
 CONSTRAINT [PK_posts] PRIMARY KEY CLUSTERED 
(
	[post_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]

GO
/****** Object:  Table [dbo].[topic_groups]    Script Date: 01.04.2016 10:13:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[topic_groups](
	[group_id] [int] NOT NULL,
	[name] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_topic_groups] PRIMARY KEY CLUSTERED 
(
	[group_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]

GO
/****** Object:  Table [dbo].[topics]    Script Date: 01.04.2016 10:13:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[topics](
	[topic_id] [int] NOT NULL,
	[group_id] [int] NOT NULL,
	[name] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_topics] PRIMARY KEY CLUSTERED 
(
	[topic_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]

GO
/****** Object:  Table [dbo].[user_groups]    Script Date: 01.04.2016 10:13:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[user_groups](
	[id] [int] NOT NULL,
	[name] [nvarchar](50) NOT NULL,
	[read_hidden] [int] NOT NULL,
	[hiding_posts] [int] NOT NULL,
	[deleting_posts] [int] NOT NULL,
	[changing_posts] [int] NOT NULL,
	[deleting_topics] [int] NOT NULL,
	[changing_topics] [int] NOT NULL,
	[deleting_groups] [int] NOT NULL,
	[changing_groups] [int] NOT NULL,
 CONSTRAINT [PK_user_groupss] 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]

GO
/****** Object:  Table [dbo].[users]    Script Date: 01.04.2016 10:13:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[users](
	[user_id] [int] NOT NULL,
	[name] [nvarchar](50) NOT NULL,
	[email] [nvarchar](50) NOT NULL,
	[md5_pass] [nvarchar](50) NOT NULL,
	[user_group_id] [int] NOT NULL,
	[last_act_time] [timestamp] NOT NULL,
	[money] [int] NOT NULL,
 CONSTRAINT [PK_users] PRIMARY KEY CLUSTERED 
(
	[user_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]

GO
/****** Object:  Index [IX_posts]    Script Date: 01.04.2016 10:13:59 ******/
CREATE UNIQUE NONCLUSTERED INDEX [IX_posts] ON [dbo].[posts]
(
	[own_user_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [ban_id]    Script Date: 01.04.2016 10:13:59 ******/
CREATE UNIQUE NONCLUSTERED INDEX [ban_id] ON [dbo].[users]
(
	[user_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [group_id]    Script Date: 01.04.2016 10:13:59 ******/
CREATE UNIQUE NONCLUSTERED INDEX [group_id] ON [dbo].[users]
(
	[user_group_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
ALTER TABLE [dbo].[ban_list]  WITH CHECK ADD  CONSTRAINT [FK_ban_list_users] FOREIGN KEY([user_id])
REFERENCES [dbo].[users] ([user_id])
GO
ALTER TABLE [dbo].[ban_list] CHECK CONSTRAINT [FK_ban_list_users]
GO
ALTER TABLE [dbo].[posts]  WITH CHECK ADD  CONSTRAINT [FK_posts_topics] FOREIGN KEY([topic_id])
REFERENCES [dbo].[topics] ([topic_id])
GO
ALTER TABLE [dbo].[posts] CHECK CONSTRAINT [FK_posts_topics]
GO
ALTER TABLE [dbo].[posts]  WITH CHECK ADD  CONSTRAINT [FK_posts_users] FOREIGN KEY([own_user_id])
REFERENCES [dbo].[users] ([user_id])
GO
ALTER TABLE [dbo].[posts] CHECK CONSTRAINT [FK_posts_users]
GO
ALTER TABLE [dbo].[topics]  WITH CHECK ADD  CONSTRAINT [FK_topics_topic_groups] FOREIGN KEY([group_id])
REFERENCES [dbo].[topic_groups] ([group_id])
GO
ALTER TABLE [dbo].[topics] CHECK CONSTRAINT [FK_topics_topic_groups]
GO
ALTER TABLE [dbo].[user_groups]  WITH CHECK ADD  CONSTRAINT [FK_user_groups_user_groups] FOREIGN KEY([id])
REFERENCES [dbo].[users] ([user_group_id])
GO
ALTER TABLE [dbo].[user_groups] CHECK CONSTRAINT [FK_user_groups_user_groups]
GO
USE [master]
GO
ALTER DATABASE [forum] SET  READ_WRITE 
GO
