USE [master]
GO

IF EXISTS (SELECT name FROM sys.databases WHERE name = N'BOL2')
DROP DATABASE [BOL2]
GO

CREATE DATABASE [BOL2]
ON PRIMARY (
	NAME		= N'BOL2',
	FILENAME	= N'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\BOL2.mdf',
	SIZE		= 102400KB,
	FILEGROWTH	= 20480KB,
	MAXSIZE		= UNLIMITED
),
FILEGROUP [FilestreamFG] CONTAINS FILESTREAM DEFAULT (
	NAME		= N'BOL2_fs',
	FILENAME	= N'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\BOL2_fs'
)
LOG ON (
	NAME		= N'BOL2_log', 
	FILENAME	= N'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\BOL2_log.ldf',
	SIZE		= 20480KB,
	MAXSIZE		= 2048GB,
	FILEGROWTH	= 20480KB
	)
GO

IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
BEGIN
	EXEC [BOL2].[dbo].[sp_fulltext_database] @action = 'enable'
END
GO

USE BOL2;
GO

-- bazuje na: http://weblogs.sqlteam.com/robv/archive/2013/09/17/full-text-indexing-books-online.aspx

CREATE SCHEMA help AUTHORIZATION dbo;
GO

CREATE FULLTEXT CATALOG FTC AS DEFAULT;
GO

CREATE TABLE help.filesFS(
	file_id		INT					NOT NULL	IDENTITY(1, 1)	CONSTRAINT PK_help_files		PRIMARY KEY,
    path		VARCHAR(256)		NOT NULL					CONSTRAINT UNQ_help_files_path	UNIQUE,
    doc_type	VARCHAR(6)										DEFAULT('.xml'),

    content		VARBINARY(MAX)		FILESTREAM	NOT NULL,
	rguid		UNIQUEIDENTIFIER	ROWGUIDCOL	NOT NULL		CONSTRAINT UNQ_rguid			UNIQUE	DEFAULT NEWID()
);

CREATE FULLTEXT INDEX ON help.filesFS(
	content 
	TYPE COLUMN doc_type 
	LANGUAGE 1033
) 
KEY INDEX PK_help_files;

-- wykonaj skrypt:
-- import_bol_fs.bat