SlideShare uma empresa Scribd logo
1 de 29
Baixar para ler offline
SQL Server 2012: File Tables
File storage connected to RDBMS
• There are lots of files
• We need to store them somewhere
• We need to query over them
• Files have metadata information like dates,
size, content type etc.
• It needs to be queried as well
Why we need it?
• Software that have to deal with files
• File libraries, archives, storages etc.
• Document-centric software
• Email systems with attachments
• Content Management Systems
• Version Control Systems
• and so on and so on…
Who Needs It?
1. Store files to any File System (or external
storage), keep related information in DB
Tables, sync both places
2. Store all files and related information in DB
Tables
Options available before – 1/3
1. Store files to any File System (or external
storage), keep related information in DB Tables,
sync both places
– the only problem here is to keep both places in
sync
– seems to be the most common scenario
Options available before – 2/3
2. Store all files and related information in DB
Tables
• the files content is stored in BLOBs
• huge database size because of content stored within
database file
Options available before – 3/3
SQL Server 2012 brings a new feature:
• FileTables
MSDN:
• “You can store files and documents in special
tables in SQL Server called FileTables, but access
them from Windows applications as if they were
stored in the file system, without making any
changes to your client applications”
New Option – SQL FileTables
Technically FileTables represent both options
combined.
• but automated by SQL Server 2012 Engine
• based on SQL Server 2008/R2 FileStreams
Technically FileTables Are
• Windows File I/O compatibility:
– non-transacted streaming access and in-place updates
– A hierarchical namespace of directories and files
– Storage of 10 file attributes such as Created Date and
Modified Date
– Support for both file and directory management Win
API
• Full-text search over files and metadata
• Semantic search over files and metadata
FileTables Benefits
• Do not support Memory-Mapped Files
– easily reproducible using Windows Notepad
FileTables Restrictions
Installation Options – 1/2
Installation Options – 2/2
<machine-name>
<sql-instance-level FILESTREAM share>
<database-level directory>
<FileTable directory>
Sample:
shirmanovMSSQLSERVERFileTablesDbDocu
ments
UNC Directory Hierarchy
CREATE DATABASE [FileTablesDb]
ON
PRIMARY (NAME = PrimaryFG, FILENAME =
N'c:SqlFileStreamFileTablesDb.mdf'),
FILEGROUP FileStreamFG CONTAINS FILESTREAM (NAME =
FileStreamFG, FILENAME = N'c:SqlFileStreamFileStream')
LOG ON (NAME = FileTablesDbLog, FILENAME =
N'c:SqlFileStreamFileTablesDb.ldf')
WITH FILESTREAM (NON_TRANSACTED_ACCESS = FULL,
DIRECTORY_NAME = N'FileTablesDb')
GO
Create FileStream-enabled Database
CREATE TABLE Documents
AS FileTable
WITH (
FileTable_Directory = 'Documents',
FileTable_Collate_Filename = database_default
);
GO
Create a FileTable
SELECT * FROM sys.filetables;
GO
Create a FileTable
-- enumerate all FileTables in database
SELECT
db_name() AS db_name,
db_id() AS db_id,
SC.[name] AS schema_name,
SO.[schema_id],
SO.[name] AS object_name,
FT.[object_id],
FT.[directory_name],
FT.[filename_collation_id],
FT.[filename_collation_name],
FileTableRootPath() + '' + FT.[directory_name] AS unc_path
FROM
[FileTablesDb].[sys].[filetables] FT
LEFT JOIN [sys].[objects] SO
ON FT.[object_id] = SO.[object_id]
LEFT JOIN [sys].[schemas] SC
ON SC.[schema_id] = SO.[schema_id];
Enumerate All FileTables in Database
• Copy files to UNC share and show them in
database table
Demo
How FileStream Catalog Looks Like
SELECT SERVERPROPERTY
(N'FILESTREAMShareName');
Get SQL Instance-level FILESTREAM Share Name
SELECT DB_NAME(D.database_id) AS
"database_name", D.database_id,
D.non_transacted_access,
D.non_transacted_access_desc, D.directory_name
FROM sys.database_filestream_options D
WHERE directory_name IS NOT NULL;
GO
Get Database-level Directory Name
-- Get path to FileTable at once - uses Current DB
SELECT FileTableRootPath() AS 'FileTableRootPath'
GO
Get Path to FileTable at Once
-- Get a List of Open File Handles
-- Associated with a FileTable
SELECT * FROM
sys.dm_filestream_non_transacted_handles;
GO
Get a List of Open File Handles
-- Kill all open handles in a single filetable
EXEC
sp_kill_filestream_non_transacted_handles
@table_name = 'Documents';
GO
Kill All Open Handles
-- To identify open files and the associated locks
SELECT opened_file_name
FROM
sys.dm_filestream_non_transacted_handles
WHERE fcb_id IN
( SELECT request_owner_id FROM
sys.dm_tran_locks );
GO
Identify Open Files & Associated Locks
INSERT INTO dbo.Documents
(Name, file_stream)
VALUES ('Testfile1.txt', 0x);
Insert a file to the Root via T-SQL
SELECT @pathstring = path_locator.ToString()
from dbo.Documents
where name = 'SQLFiles';
SET @newpath = @pathstring + convert(varchar(20), convert(bigint,
substring(convert(binary(16), newid()), 1, 6))) +
'.' + convert(varchar(20), convert(bigint, substring(convert(binary(16),
newid()), 7, 6))) + '.' + convert(varchar(20), convert(bigint, substring(
convert(binary(16), newid()), 13, 4))) + '/';
INSERT INTO dbo.Documents
(Name, path_locator, file_stream)
VALUES ('SQLFilesTest.txt', @newpath, 0x);
Insert a file to the folder via T-SQL
-- Find duplicate files by name and size
SELECT
COUNT(*) AS duplicates_number,
MAX(D.stream_id) AS stream_id, D.name,
D.file_type, D.cached_file_size
FROM dbo.Documents D
GROUP BY D.name, D.file_type, D.cached_file_size
HAVING COUNT(*) > 1;
Find Duplicate Files
• http://msdn.microsoft.com/en-
us/library/ff929144.aspx
• http://sqlskills.com/BLOGS/BOBB/post/SQL-
Server-2012-FileTables-in-T-SQL-part-3-
hierarchyid-methods.aspx
References

Mais conteúdo relacionado

Mais procurados

Big data with HDFS and Mapreduce
Big data  with HDFS and MapreduceBig data  with HDFS and Mapreduce
Big data with HDFS and Mapreducesenthil0809
 
Directory services by SAJID
Directory services by SAJIDDirectory services by SAJID
Directory services by SAJIDSajid khan
 
tempdb and Performance Keys
tempdb and Performance Keystempdb and Performance Keys
tempdb and Performance KeysNaji El Kotob
 
Oracle dba training
Oracle  dba    training Oracle  dba    training
Oracle dba training P S Rani
 
NOSQL Databases types and Uses
NOSQL Databases types and UsesNOSQL Databases types and Uses
NOSQL Databases types and UsesSuvradeep Rudra
 
Oracle DBA Tutorial for Beginners -Oracle training institute in bangalore
Oracle DBA Tutorial for Beginners -Oracle training institute in bangaloreOracle DBA Tutorial for Beginners -Oracle training institute in bangalore
Oracle DBA Tutorial for Beginners -Oracle training institute in bangaloreTIB Academy
 
Ms sql server architecture
Ms sql server architectureMs sql server architecture
Ms sql server architectureAjeet Singh
 
Basic oracle-database-administration
Basic oracle-database-administrationBasic oracle-database-administration
Basic oracle-database-administrationsreehari orienit
 
Active Directory & LDAP Authentication Without Triggers
Active Directory & LDAP Authentication Without TriggersActive Directory & LDAP Authentication Without Triggers
Active Directory & LDAP Authentication Without TriggersPerforce
 
Open LDAP vs. Active Directory
Open LDAP vs. Active DirectoryOpen LDAP vs. Active Directory
Open LDAP vs. Active DirectoryAhmad Haghighi
 

Mais procurados (20)

Big data with HDFS and Mapreduce
Big data  with HDFS and MapreduceBig data  with HDFS and Mapreduce
Big data with HDFS and Mapreduce
 
Creating database
Creating databaseCreating database
Creating database
 
Oracle DBA
Oracle DBAOracle DBA
Oracle DBA
 
Directory services by SAJID
Directory services by SAJIDDirectory services by SAJID
Directory services by SAJID
 
Oracle Tablespace - Basic
Oracle Tablespace - BasicOracle Tablespace - Basic
Oracle Tablespace - Basic
 
tempdb and Performance Keys
tempdb and Performance Keystempdb and Performance Keys
tempdb and Performance Keys
 
Oracle dba training
Oracle  dba    training Oracle  dba    training
Oracle dba training
 
NOSQL Databases types and Uses
NOSQL Databases types and UsesNOSQL Databases types and Uses
NOSQL Databases types and Uses
 
Oracle DBA Tutorial for Beginners -Oracle training institute in bangalore
Oracle DBA Tutorial for Beginners -Oracle training institute in bangaloreOracle DBA Tutorial for Beginners -Oracle training institute in bangalore
Oracle DBA Tutorial for Beginners -Oracle training institute in bangalore
 
Selecting best NoSQL
Selecting best NoSQL Selecting best NoSQL
Selecting best NoSQL
 
Apache HBase 0.98
Apache HBase 0.98Apache HBase 0.98
Apache HBase 0.98
 
Ms sql server architecture
Ms sql server architectureMs sql server architecture
Ms sql server architecture
 
Nosql databases
Nosql databasesNosql databases
Nosql databases
 
Introduction to NoSQL
Introduction to NoSQLIntroduction to NoSQL
Introduction to NoSQL
 
Basic oracle-database-administration
Basic oracle-database-administrationBasic oracle-database-administration
Basic oracle-database-administration
 
Active Directory & LDAP Authentication Without Triggers
Active Directory & LDAP Authentication Without TriggersActive Directory & LDAP Authentication Without Triggers
Active Directory & LDAP Authentication Without Triggers
 
Nosql
NosqlNosql
Nosql
 
Ldap intro
Ldap introLdap intro
Ldap intro
 
Xml
XmlXml
Xml
 
Open LDAP vs. Active Directory
Open LDAP vs. Active DirectoryOpen LDAP vs. Active Directory
Open LDAP vs. Active Directory
 

Semelhante a SQL Server 2012 - FileTables

Sql server lesson3
Sql server lesson3Sql server lesson3
Sql server lesson3Ala Qunaibi
 
CNIT 152 13 Investigating Mac OS X Systems
CNIT 152 13 Investigating Mac OS X SystemsCNIT 152 13 Investigating Mac OS X Systems
CNIT 152 13 Investigating Mac OS X SystemsSam Bowne
 
CNIT 152: 13 Investigating Mac OS X Systems
CNIT 152: 13 Investigating Mac OS X SystemsCNIT 152: 13 Investigating Mac OS X Systems
CNIT 152: 13 Investigating Mac OS X SystemsSam Bowne
 
CNIT 121: 13 Investigating Mac OS X Systems
CNIT 121: 13 Investigating Mac OS X SystemsCNIT 121: 13 Investigating Mac OS X Systems
CNIT 121: 13 Investigating Mac OS X SystemsSam Bowne
 
UNIT7-FileMgmt.pptx
UNIT7-FileMgmt.pptxUNIT7-FileMgmt.pptx
UNIT7-FileMgmt.pptxNavyaKumar22
 
Hadoop Distributed File System
Hadoop Distributed File SystemHadoop Distributed File System
Hadoop Distributed File SystemMilad Sobhkhiz
 
File Management & Access Control
File Management & Access Control File Management & Access Control
File Management & Access Control YuvrajWadavale
 
File system in operating system e learning
File system in operating system e learningFile system in operating system e learning
File system in operating system e learningLavanya Sharma
 
2005_604_Wagner_slides
2005_604_Wagner_slides2005_604_Wagner_slides
2005_604_Wagner_slidesMary Wagner
 
Javase7 1641812
Javase7 1641812Javase7 1641812
Javase7 1641812Vinay H G
 
File Management (1).pptx
File Management (1).pptxFile Management (1).pptx
File Management (1).pptxSolomonAnab1
 

Semelhante a SQL Server 2012 - FileTables (20)

Sql server lesson3
Sql server lesson3Sql server lesson3
Sql server lesson3
 
File system
File systemFile system
File system
 
Ch10 file system interface
Ch10   file system interfaceCh10   file system interface
Ch10 file system interface
 
CNIT 152 13 Investigating Mac OS X Systems
CNIT 152 13 Investigating Mac OS X SystemsCNIT 152 13 Investigating Mac OS X Systems
CNIT 152 13 Investigating Mac OS X Systems
 
CNIT 152: 13 Investigating Mac OS X Systems
CNIT 152: 13 Investigating Mac OS X SystemsCNIT 152: 13 Investigating Mac OS X Systems
CNIT 152: 13 Investigating Mac OS X Systems
 
CNIT 121: 13 Investigating Mac OS X Systems
CNIT 121: 13 Investigating Mac OS X SystemsCNIT 121: 13 Investigating Mac OS X Systems
CNIT 121: 13 Investigating Mac OS X Systems
 
UNIT7-FileMgmt.pptx
UNIT7-FileMgmt.pptxUNIT7-FileMgmt.pptx
UNIT7-FileMgmt.pptx
 
Hadoop Distributed File System
Hadoop Distributed File SystemHadoop Distributed File System
Hadoop Distributed File System
 
File Management & Access Control
File Management & Access Control File Management & Access Control
File Management & Access Control
 
Windowsforensics
WindowsforensicsWindowsforensics
Windowsforensics
 
File system in operating system e learning
File system in operating system e learningFile system in operating system e learning
File system in operating system e learning
 
AHUG Presentation: Fun with Hadoop File Systems
AHUG Presentation: Fun with Hadoop File SystemsAHUG Presentation: Fun with Hadoop File Systems
AHUG Presentation: Fun with Hadoop File Systems
 
2005_604_Wagner_slides
2005_604_Wagner_slides2005_604_Wagner_slides
2005_604_Wagner_slides
 
File System operating system operating system
File System  operating system operating systemFile System  operating system operating system
File System operating system operating system
 
Javase7 1641812
Javase7 1641812Javase7 1641812
Javase7 1641812
 
File Management (1).pptx
File Management (1).pptxFile Management (1).pptx
File Management (1).pptx
 
Os6
Os6Os6
Os6
 
9781111306366 ppt ch11
9781111306366 ppt ch119781111306366 ppt ch11
9781111306366 ppt ch11
 
File Management
File ManagementFile Management
File Management
 
File System.pptx
File System.pptxFile System.pptx
File System.pptx
 

Mais de Sperasoft

особенности работы с Locomotion в Unreal Engine 4
особенности работы с Locomotion в Unreal Engine 4особенности работы с Locomotion в Unreal Engine 4
особенности работы с Locomotion в Unreal Engine 4Sperasoft
 
концепт и архитектура геймплея в Creach: The Depleted World
концепт и архитектура геймплея в Creach: The Depleted Worldконцепт и архитектура геймплея в Creach: The Depleted World
концепт и архитектура геймплея в Creach: The Depleted WorldSperasoft
 
Опыт разработки VR игры для UE4
Опыт разработки VR игры для UE4Опыт разработки VR игры для UE4
Опыт разработки VR игры для UE4Sperasoft
 
Организация работы с UE4 в команде до 20 человек
Организация работы с UE4 в команде до 20 человек Организация работы с UE4 в команде до 20 человек
Организация работы с UE4 в команде до 20 человек Sperasoft
 
Gameplay Tags
Gameplay TagsGameplay Tags
Gameplay TagsSperasoft
 
Data Driven Gameplay in UE4
Data Driven Gameplay in UE4Data Driven Gameplay in UE4
Data Driven Gameplay in UE4Sperasoft
 
Code and Memory Optimisation Tricks
Code and Memory Optimisation Tricks Code and Memory Optimisation Tricks
Code and Memory Optimisation Tricks Sperasoft
 
The theory of relational databases
The theory of relational databasesThe theory of relational databases
The theory of relational databasesSperasoft
 
Automated layout testing using Galen Framework
Automated layout testing using Galen FrameworkAutomated layout testing using Galen Framework
Automated layout testing using Galen FrameworkSperasoft
 
Sperasoft talks: Android Security Threats
Sperasoft talks: Android Security ThreatsSperasoft talks: Android Security Threats
Sperasoft talks: Android Security ThreatsSperasoft
 
Sperasoft Talks: RxJava Functional Reactive Programming on Android
Sperasoft Talks: RxJava Functional Reactive Programming on AndroidSperasoft Talks: RxJava Functional Reactive Programming on Android
Sperasoft Talks: RxJava Functional Reactive Programming on AndroidSperasoft
 
Sperasoft‬ talks j point 2015
Sperasoft‬ talks j point 2015Sperasoft‬ talks j point 2015
Sperasoft‬ talks j point 2015Sperasoft
 
Effective Мeetings
Effective МeetingsEffective Мeetings
Effective МeetingsSperasoft
 
Unreal Engine 4 Introduction
Unreal Engine 4 IntroductionUnreal Engine 4 Introduction
Unreal Engine 4 IntroductionSperasoft
 
JIRA Development
JIRA DevelopmentJIRA Development
JIRA DevelopmentSperasoft
 
Introduction to Elasticsearch
Introduction to ElasticsearchIntroduction to Elasticsearch
Introduction to ElasticsearchSperasoft
 
MOBILE DEVELOPMENT with HTML, CSS and JS
MOBILE DEVELOPMENT with HTML, CSS and JSMOBILE DEVELOPMENT with HTML, CSS and JS
MOBILE DEVELOPMENT with HTML, CSS and JSSperasoft
 
Quick Intro Into Kanban
Quick Intro Into KanbanQuick Intro Into Kanban
Quick Intro Into KanbanSperasoft
 
ECMAScript 6 Review
ECMAScript 6 ReviewECMAScript 6 Review
ECMAScript 6 ReviewSperasoft
 
Console Development in 15 minutes
Console Development in 15 minutesConsole Development in 15 minutes
Console Development in 15 minutesSperasoft
 

Mais de Sperasoft (20)

особенности работы с Locomotion в Unreal Engine 4
особенности работы с Locomotion в Unreal Engine 4особенности работы с Locomotion в Unreal Engine 4
особенности работы с Locomotion в Unreal Engine 4
 
концепт и архитектура геймплея в Creach: The Depleted World
концепт и архитектура геймплея в Creach: The Depleted Worldконцепт и архитектура геймплея в Creach: The Depleted World
концепт и архитектура геймплея в Creach: The Depleted World
 
Опыт разработки VR игры для UE4
Опыт разработки VR игры для UE4Опыт разработки VR игры для UE4
Опыт разработки VR игры для UE4
 
Организация работы с UE4 в команде до 20 человек
Организация работы с UE4 в команде до 20 человек Организация работы с UE4 в команде до 20 человек
Организация работы с UE4 в команде до 20 человек
 
Gameplay Tags
Gameplay TagsGameplay Tags
Gameplay Tags
 
Data Driven Gameplay in UE4
Data Driven Gameplay in UE4Data Driven Gameplay in UE4
Data Driven Gameplay in UE4
 
Code and Memory Optimisation Tricks
Code and Memory Optimisation Tricks Code and Memory Optimisation Tricks
Code and Memory Optimisation Tricks
 
The theory of relational databases
The theory of relational databasesThe theory of relational databases
The theory of relational databases
 
Automated layout testing using Galen Framework
Automated layout testing using Galen FrameworkAutomated layout testing using Galen Framework
Automated layout testing using Galen Framework
 
Sperasoft talks: Android Security Threats
Sperasoft talks: Android Security ThreatsSperasoft talks: Android Security Threats
Sperasoft talks: Android Security Threats
 
Sperasoft Talks: RxJava Functional Reactive Programming on Android
Sperasoft Talks: RxJava Functional Reactive Programming on AndroidSperasoft Talks: RxJava Functional Reactive Programming on Android
Sperasoft Talks: RxJava Functional Reactive Programming on Android
 
Sperasoft‬ talks j point 2015
Sperasoft‬ talks j point 2015Sperasoft‬ talks j point 2015
Sperasoft‬ talks j point 2015
 
Effective Мeetings
Effective МeetingsEffective Мeetings
Effective Мeetings
 
Unreal Engine 4 Introduction
Unreal Engine 4 IntroductionUnreal Engine 4 Introduction
Unreal Engine 4 Introduction
 
JIRA Development
JIRA DevelopmentJIRA Development
JIRA Development
 
Introduction to Elasticsearch
Introduction to ElasticsearchIntroduction to Elasticsearch
Introduction to Elasticsearch
 
MOBILE DEVELOPMENT with HTML, CSS and JS
MOBILE DEVELOPMENT with HTML, CSS and JSMOBILE DEVELOPMENT with HTML, CSS and JS
MOBILE DEVELOPMENT with HTML, CSS and JS
 
Quick Intro Into Kanban
Quick Intro Into KanbanQuick Intro Into Kanban
Quick Intro Into Kanban
 
ECMAScript 6 Review
ECMAScript 6 ReviewECMAScript 6 Review
ECMAScript 6 Review
 
Console Development in 15 minutes
Console Development in 15 minutesConsole Development in 15 minutes
Console Development in 15 minutes
 

Último

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 

Último (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

SQL Server 2012 - FileTables

  • 1. SQL Server 2012: File Tables File storage connected to RDBMS
  • 2. • There are lots of files • We need to store them somewhere • We need to query over them • Files have metadata information like dates, size, content type etc. • It needs to be queried as well Why we need it?
  • 3. • Software that have to deal with files • File libraries, archives, storages etc. • Document-centric software • Email systems with attachments • Content Management Systems • Version Control Systems • and so on and so on… Who Needs It?
  • 4. 1. Store files to any File System (or external storage), keep related information in DB Tables, sync both places 2. Store all files and related information in DB Tables Options available before – 1/3
  • 5. 1. Store files to any File System (or external storage), keep related information in DB Tables, sync both places – the only problem here is to keep both places in sync – seems to be the most common scenario Options available before – 2/3
  • 6. 2. Store all files and related information in DB Tables • the files content is stored in BLOBs • huge database size because of content stored within database file Options available before – 3/3
  • 7. SQL Server 2012 brings a new feature: • FileTables MSDN: • “You can store files and documents in special tables in SQL Server called FileTables, but access them from Windows applications as if they were stored in the file system, without making any changes to your client applications” New Option – SQL FileTables
  • 8. Technically FileTables represent both options combined. • but automated by SQL Server 2012 Engine • based on SQL Server 2008/R2 FileStreams Technically FileTables Are
  • 9. • Windows File I/O compatibility: – non-transacted streaming access and in-place updates – A hierarchical namespace of directories and files – Storage of 10 file attributes such as Created Date and Modified Date – Support for both file and directory management Win API • Full-text search over files and metadata • Semantic search over files and metadata FileTables Benefits
  • 10. • Do not support Memory-Mapped Files – easily reproducible using Windows Notepad FileTables Restrictions
  • 13. <machine-name> <sql-instance-level FILESTREAM share> <database-level directory> <FileTable directory> Sample: shirmanovMSSQLSERVERFileTablesDbDocu ments UNC Directory Hierarchy
  • 14. CREATE DATABASE [FileTablesDb] ON PRIMARY (NAME = PrimaryFG, FILENAME = N'c:SqlFileStreamFileTablesDb.mdf'), FILEGROUP FileStreamFG CONTAINS FILESTREAM (NAME = FileStreamFG, FILENAME = N'c:SqlFileStreamFileStream') LOG ON (NAME = FileTablesDbLog, FILENAME = N'c:SqlFileStreamFileTablesDb.ldf') WITH FILESTREAM (NON_TRANSACTED_ACCESS = FULL, DIRECTORY_NAME = N'FileTablesDb') GO Create FileStream-enabled Database
  • 15. CREATE TABLE Documents AS FileTable WITH ( FileTable_Directory = 'Documents', FileTable_Collate_Filename = database_default ); GO Create a FileTable
  • 16. SELECT * FROM sys.filetables; GO Create a FileTable
  • 17. -- enumerate all FileTables in database SELECT db_name() AS db_name, db_id() AS db_id, SC.[name] AS schema_name, SO.[schema_id], SO.[name] AS object_name, FT.[object_id], FT.[directory_name], FT.[filename_collation_id], FT.[filename_collation_name], FileTableRootPath() + '' + FT.[directory_name] AS unc_path FROM [FileTablesDb].[sys].[filetables] FT LEFT JOIN [sys].[objects] SO ON FT.[object_id] = SO.[object_id] LEFT JOIN [sys].[schemas] SC ON SC.[schema_id] = SO.[schema_id]; Enumerate All FileTables in Database
  • 18. • Copy files to UNC share and show them in database table Demo
  • 20. SELECT SERVERPROPERTY (N'FILESTREAMShareName'); Get SQL Instance-level FILESTREAM Share Name
  • 21. SELECT DB_NAME(D.database_id) AS "database_name", D.database_id, D.non_transacted_access, D.non_transacted_access_desc, D.directory_name FROM sys.database_filestream_options D WHERE directory_name IS NOT NULL; GO Get Database-level Directory Name
  • 22. -- Get path to FileTable at once - uses Current DB SELECT FileTableRootPath() AS 'FileTableRootPath' GO Get Path to FileTable at Once
  • 23. -- Get a List of Open File Handles -- Associated with a FileTable SELECT * FROM sys.dm_filestream_non_transacted_handles; GO Get a List of Open File Handles
  • 24. -- Kill all open handles in a single filetable EXEC sp_kill_filestream_non_transacted_handles @table_name = 'Documents'; GO Kill All Open Handles
  • 25. -- To identify open files and the associated locks SELECT opened_file_name FROM sys.dm_filestream_non_transacted_handles WHERE fcb_id IN ( SELECT request_owner_id FROM sys.dm_tran_locks ); GO Identify Open Files & Associated Locks
  • 26. INSERT INTO dbo.Documents (Name, file_stream) VALUES ('Testfile1.txt', 0x); Insert a file to the Root via T-SQL
  • 27. SELECT @pathstring = path_locator.ToString() from dbo.Documents where name = 'SQLFiles'; SET @newpath = @pathstring + convert(varchar(20), convert(bigint, substring(convert(binary(16), newid()), 1, 6))) + '.' + convert(varchar(20), convert(bigint, substring(convert(binary(16), newid()), 7, 6))) + '.' + convert(varchar(20), convert(bigint, substring( convert(binary(16), newid()), 13, 4))) + '/'; INSERT INTO dbo.Documents (Name, path_locator, file_stream) VALUES ('SQLFilesTest.txt', @newpath, 0x); Insert a file to the folder via T-SQL
  • 28. -- Find duplicate files by name and size SELECT COUNT(*) AS duplicates_number, MAX(D.stream_id) AS stream_id, D.name, D.file_type, D.cached_file_size FROM dbo.Documents D GROUP BY D.name, D.file_type, D.cached_file_size HAVING COUNT(*) > 1; Find Duplicate Files