{"id":473,"date":"2012-07-31T09:47:00","date_gmt":"2012-07-31T09:47:00","guid":{"rendered":"\/blogs\/bobb\/post\/Using-filestream-with-full-text-Lose-the-redundant-index.aspx"},"modified":"2012-07-31T09:47:00","modified_gmt":"2012-07-31T09:47:00","slug":"using-filetable-with-full-text-lose-the-redundant-index","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-filetable-with-full-text-lose-the-redundant-index\/","title":{"rendered":"Using filetable with full-text? Lose the redundant index"},"content":{"rendered":"<p>\nI&#39;m not sure how many full-text search over filetable demos I&#39;ve seen (including some I&#39;ve written that I was just perusing), that do something like this.\n<\/p>\n<p>\nCREATE TABLE foo AS FILETABLE WITH (FILETABLE_DIRECTORY = N&#39;ftdir&#39;);<br \/>\nCREATE UNIQUE INDEX fooidx ON foo(stream_id);<br \/>\nCREATE FULLTEXT INDEX ON foo (file_stream TYPE COLUMN file_type) KEY INDEX fooidx;\n<\/p>\n<p>\nAfter looking at this a few times, I couldn&#39;t beleive there wasn&#39;t some kind of key contraint\/index on the stream_id column defined as part of the filetable definition. And indeed there is. There&#39;s a UNIQUE constraint already that casues a nonclustered unique index to be built to enforce it. So why the extra nonclustered index, just to use full-text? A couple of extra lines of code should be able to tell us what the filetable named it&#39;s constraint\/index, and we can use that name in the full-text index creation instead. And we won&#39;t need the redundant index.\n<\/p>\n<p>\nBut wait&#8230;we don&#39;t&nbsp;even have to do that.\n<\/p>\n<p>\nCREATE TABLE&#8230; AS FILETABLE takes some additional parameters that make the extra code unnecessary. For our purposes, we only need to name the key constraint that corresponds to the KEY INDEX we&#39;re using in the full-text index. So&#8230;\n<\/p>\n<p>\nCREATE TABLE foo AS FILETABLE WITH (FILETABLE_DIRECTORY = N&#39;ftdir&#39;, FILETABLE_STREAMID_UNIQUE_CONSTRAINT_NAME=UQ_stream_id);<br \/>\nCREATE FULLTEXT INDEX ON foo (file_stream TYPE COLUMN file_type) KEY INDEX UQ_stream_id;\n<\/p>\n<p>\nloses the redundant index. There are also parameters&nbsp;to specify&nbsp;the FILETABLE_PRIMARY_KEY_CONSTRAINT_NAME and FILETABLE_FULLPATH_UNIQUE_CONSTRAINT_NAME as well, if you need them, to make it easier to define foreign keys.&nbsp; Although the filetable&#39;s related objects are fixed at creation time, you can add constraints to a filetable after it is created.\n<\/p>\n<p>\n@bobbeauch<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#39;m not sure how many full-text search over filetable demos I&#39;ve seen (including some I&#39;ve written that I was just perusing), that do something like this. CREATE TABLE foo AS FILETABLE WITH (FILETABLE_DIRECTORY = N&#39;ftdir&#39;); CREATE UNIQUE INDEX fooidx ON foo(stream_id); CREATE FULLTEXT INDEX ON foo (file_stream TYPE COLUMN file_type) KEY INDEX fooidx; After looking [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,18,31],"tags":[],"class_list":["post-473","post","type-post","status-publish","format-standard","hentry","category-filetable","category-full-text-search","category-sql-server-2012"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.9.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Using filetable with full-text? Lose the redundant index - Bob Beauchemin<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-filetable-with-full-text-lose-the-redundant-index\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using filetable with full-text? Lose the redundant index - Bob Beauchemin\" \/>\n<meta property=\"og:description\" content=\"I&#039;m not sure how many full-text search over filetable demos I&#039;ve seen (including some I&#039;ve written that I was just perusing), that do something like this. CREATE TABLE foo AS FILETABLE WITH (FILETABLE_DIRECTORY = N&#039;ftdir&#039;); CREATE UNIQUE INDEX fooidx ON foo(stream_id); CREATE FULLTEXT INDEX ON foo (file_stream TYPE COLUMN file_type) KEY INDEX fooidx; After looking [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-filetable-with-full-text-lose-the-redundant-index\/\" \/>\n<meta property=\"og:site_name\" content=\"Bob Beauchemin\" \/>\n<meta property=\"article:published_time\" content=\"2012-07-31T09:47:00+00:00\" \/>\n<meta name=\"author\" content=\"Bob Beauchemin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Bob Beauchemin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-filetable-with-full-text-lose-the-redundant-index\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-filetable-with-full-text-lose-the-redundant-index\/\",\"name\":\"Using filetable with full-text? Lose the redundant index - Bob Beauchemin\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website\"},\"datePublished\":\"2012-07-31T09:47:00+00:00\",\"dateModified\":\"2012-07-31T09:47:00+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-filetable-with-full-text-lose-the-redundant-index\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-filetable-with-full-text-lose-the-redundant-index\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-filetable-with-full-text-lose-the-redundant-index\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"FileTable\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/category\/filetable\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Using filetable with full-text? Lose the redundant index\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/\",\"name\":\"Bob Beauchemin\",\"description\":\"SQL Server Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e\",\"name\":\"Bob Beauchemin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g\",\"caption\":\"Bob Beauchemin\"},\"sameAs\":[\"http:\/www.sqlskills.com\/blogs\/bobb\/\"],\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/author\/bobb\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Using filetable with full-text? Lose the redundant index - Bob Beauchemin","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-filetable-with-full-text-lose-the-redundant-index\/","og_locale":"en_US","og_type":"article","og_title":"Using filetable with full-text? Lose the redundant index - Bob Beauchemin","og_description":"I&#39;m not sure how many full-text search over filetable demos I&#39;ve seen (including some I&#39;ve written that I was just perusing), that do something like this. CREATE TABLE foo AS FILETABLE WITH (FILETABLE_DIRECTORY = N&#39;ftdir&#39;); CREATE UNIQUE INDEX fooidx ON foo(stream_id); CREATE FULLTEXT INDEX ON foo (file_stream TYPE COLUMN file_type) KEY INDEX fooidx; After looking [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-filetable-with-full-text-lose-the-redundant-index\/","og_site_name":"Bob Beauchemin","article_published_time":"2012-07-31T09:47:00+00:00","author":"Bob Beauchemin","twitter_misc":{"Written by":"Bob Beauchemin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-filetable-with-full-text-lose-the-redundant-index\/","url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-filetable-with-full-text-lose-the-redundant-index\/","name":"Using filetable with full-text? Lose the redundant index - Bob Beauchemin","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website"},"datePublished":"2012-07-31T09:47:00+00:00","dateModified":"2012-07-31T09:47:00+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-filetable-with-full-text-lose-the-redundant-index\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/bobb\/using-filetable-with-full-text-lose-the-redundant-index\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-filetable-with-full-text-lose-the-redundant-index\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/bobb\/"},{"@type":"ListItem","position":2,"name":"FileTable","item":"https:\/\/www.sqlskills.com\/blogs\/bobb\/category\/filetable\/"},{"@type":"ListItem","position":3,"name":"Using filetable with full-text? Lose the redundant index"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website","url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/","name":"Bob Beauchemin","description":"SQL Server Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlskills.com\/blogs\/bobb\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e","name":"Bob Beauchemin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g","caption":"Bob Beauchemin"},"sameAs":["http:\/www.sqlskills.com\/blogs\/bobb\/"],"url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/author\/bobb\/"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts\/473","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/comments?post=473"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts\/473\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/media?parent=473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/categories?post=473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/tags?post=473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}