-- Przygotowanie bazy dla demo FILETABLE
USE [master]
GO

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

CREATE DATABASE [PLSSUG_DEMO4]
ON PRIMARY (
	NAME		= N'PLSSUG_DEMO4',
	FILENAME	= N'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\PLSSUG_DEMO4.mdf',
	SIZE		= 102400KB,
	FILEGROWTH	= 51200KB,
	MAXSIZE		= UNLIMITED
),
FILEGROUP [FS_DOCS] CONTAINS FILESTREAM DEFAULT (
	NAME		= N'FS_PLSSUG_DEMO4',
	FILENAME	= N'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\FS_PLSSUG_DEMO4',
	MAXSIZE		= UNLIMITED)
LOG ON (
	NAME		= N'PLSSUG_DEMO4_log',
	FILENAME	= N'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\PLSSUG_DEMO4_log.ldf',
	SIZE		= 51200KB,
	FILEGROWTH	= 20480KB
)
GO

ALTER DATABASE [PLSSUG_DEMO4] SET FILESTREAM (
	NON_TRANSACTED_ACCESS		= FULL,
	DIRECTORY_NAME				= N'PLSSUG_DEMO4'
)
GO

USE [PLSSUG_DEMO4]
GO

IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = N'mp3')
EXEC sys.sp_executesql N'CREATE SCHEMA [mp3]'
GO

IF OBJECT_ID(N'[mp3].[pliki]', N'U') IS NOT NULL
	EXEC sp_executesql N'DROP TABLE mp3.pliki';

CREATE TABLE mp3.pliki AS FILETABLE
GO

-- skopiuj pliki z C:\Darksiders II Official Soundtrack do \\Win-dmduq6acmmk\mssqlserver\PLSSUG_DEMO4\pliki

SELECT * FROM mp3.pliki