USE [master]
GO

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

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


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

USE BOL1;
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.files(
	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)	NOT NULL
);

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

-- wykonaj skrypty:
-- extract_bol.bat
-- import_bol.bat