SlideShare a Scribd company logo
1 of 77
SQL Server 2008 for Developers UTS Short Course
Peter Gfader Specializes in  C# and .NET (Java not anymore) TestingAutomated tests Agile, ScrumCertified Scrum Trainer Technology aficionado  Silverlight ASP.NET Windows Forms
Course Website Course Timetable & Materials http://www.ssw.com.au/ssw/Events/2010UTSSQL/ Resources http://sharepoint.ssw.com.au/Training/UTSSQL/
Course Overview
What we did last weekCLR Integration .NET .NET FX CLR
What we did last weekCLR Integration Stored Proc Functions Triggers Bottom Line Use T-SQL for all data operations Use CLR assemblies for any complex calculations and transformations
Homework? Find all products that have a productnumber starting with BK Find all products with "Road" in the name that are Silver Find a list of products that have no review Find the list price ([listprice]) of all products in our shop What is the sum of the list price of all our products Find the product with the maximum and minimum listprice Find a list of products with their discount sale (hint see Sales.SalesOrderDetail) Find the sum of pricesof the products in each subcategory
Session 5SQL Server Full-Text Searchusing Full-Text search in SQL Server 2008
Agenda What is Full text search The old way 2005 The new way 2008 How to Querying
What is Fulltext search SELECT *FROM [Northwind].[dbo].[Employees]WHERE Notes LIKE '%grad%‘
What is REAL Fulltext search Allows searching for text/words in columns Similar words Plural of words Based on special index Full-text index (Full text catalog) SELECT *FROM [Northwind].[dbo].[Employees]WHEREFREETEXT(*,'grad‘)
Theory
Full-Text Search Terminology 1/3 Full-text index  ,[object Object]
Used in full text queries Full-text catalog  ,[object Object],Word breaker  ,[object Object],[object Object]
Full-Text Search Terminology 3/3 Stopwords/Stoplists  not relevant word to search  e.g. ‘and’, ‘a’, ‘is’ and ‘the’ in English Accent insensitivity cafè = cafe
Fulltext search – Under the hood
The old way! SQL 2005
The new way! SQL 2008
How toAdministration
Administering Full-Text Search Full-text administration can be separated into three main tasks: Creating/altering/dropping full-text catalogs  Creating/altering/dropping full-text indexes Scheduling and maintaining index population.
Administering Full-Text Search
Index vs. Full-text index
Administering Full-Text Search Automatic update of index Slows down database performance Manually repopulate full text index Time consuming Asynchronous process in the background Periods of low activity Index not up to date
How to Creating a Full Text Catalog ,[object Object]
SQL 2008 is smart,[object Object]
Creating a Full-Text Catalog (SQL 2005) Syntax CREATE FULLTEXT CATALOG catalog_name       [ON FILEGROUP filegroup]      [IN PATH 'rootpath']       [WITH <catalog_option>]       [AS DEFAULT]       [AUTHORIZATION owner_name ] <catalog_option>::=      ACCENT_SENSITIVITY = {ON|OFF}  Example USE AdventureWorks_FulllText CREATE FULLTEXT CATALOG AdventureWorks_FullTextCatalog ON FILEGROUP FullTextCatalog_FGWITH ACCENT_SENSITIVITY = ON AS DEFAULTAUTHORIZATION dbo
Creating a Full-Text CatalogStep by step Create a directory on the operating system named C:est Launch SSMS, connect to your instance, and open a new query window Add a new filegroup to the AdventureWorks_FulllText USE Master GO ALTER DATABASE AdventureWorks_FulllText GO ALTER DATABASE AdventureWorks_FulllText  ADD FILE (NAME = N’ AdventureWorks_FulllText _data’, FILENAME=N’C:ESTAdventureWorks_FulllText _data.ndf’, SIZE=2048KB, FILEGROTH=1024KB ) TO FILEGROUP [FTFG1] GO Create a full-text catalog on the FTFG1 filegroup by executing the following command:USE AdventureWorks_FulllTextGOCREATE FULLTEXT CATALOG AWCatalog on FILEGROUP FTFG1 IN PATH ‘C:EST’ AS DEFAULT;GO
SQL 2008
SQL 2008
How toCreating Full Text Indexes
Property of column
Full-text Index property window
Summary TSQL command CREATE FULLTEXT INDEX  Full-text indexes on  Text-based Binary Image columns VARBINARY / IMAGE  Store files in their native format within SQL Server  Full-text indexing and searching Lots of helper services/functionality Word-breaker routines, language files, noise word files, filters and protocol handlers.
How to Index and Catalog Population
	Because of the external structure for storing full-text indexes, changes to underlying data columns are not immediately reflected in the full-text index. Instead, a background process enlists the word breakers, filters and noise word filters to build the tokens for each column, which are then merged back into the main index either automatically or manually. This update process is called population or a crawl. To keep your full-text indexes up to date, you must periodically populate them. Populating a Full-Text Index
You can choose from there modes for full-text population: Full Incremental Update Populating a Full-Text Index
Populating a Full-Text Index Full Read and process all rows Very resource-intensive Incremental  Automatically populates the index for rows that were modified since the last population Requires timestamp column  Update  Uses changes tracking from SQL Server (inserts, updates, and deletes) Specify how you want to propagate the changes to the index AUTO automatic processing MANUAL implement a manual method for processing changes
Populating a Full-Text Index Example ALTER FULLTEXT INDEX ON Production.ProductDescription START FULL POPULATION; ALTER FULLTEXT INDEX ON Production.Document START FULL POPULATION;
Populating a Full-Text Catalog Syntax ALTER FULLTEXT CATALOG catalog_name{ REBUILD [ WITH ACCENT_SENSITIVITY = { ON | OFF } ] | REORGANIZE | AS DEFAULT } ,[object Object],ACCENT_SENSITIVITY change ,[object Object],Performance Frees up disk and memory
Populating a Full-Text Catalog Example USE AdventureWorks_FulllText;  ALTER FULLTEXT CATALOG AdventureWorks_FullTextCatalogREBUILD WITH ACCENT_SENSITIVITY=OFF; -- Check Accentsensitivity SELECT FULLTEXTCATALOGPROPERTY('AdventureWorks_FullTextCatalog', 'accentsensitivity');
Managing Population Schedules In SQL 2000, full text catalogs could only be populated on specified schedules SQL 2005/2008 can track database changes and keep the catalog up to date, with a minor performance hit
How toQuerying SQL Server Using Full-Text Search Querying SQL Server Using Full-Text Search Full-Text query keywords FREETEXT FREETEXTTABLE CONTAINS CONTAINSTABLE
FREETEXT Fuzzy search (less precise ) Inflectional forms (Stemming) Related words (Thesaurus)
FREETEXT Fuzzy search (less precise ) Inflectional forms (Stemming) Related words (Thesaurus) SELECT ProductDescriptionID, Description  FROM Production.ProductDescription WHERE [Description] LIKE  N'%bike%'; SELECT ProductDescriptionID, Description  FROM Production.ProductDescription WHERE FREETEXT(Description, N’bike’);
FREETEXTTABLE + rank column Value between 1 and 1,000  Relative number, how well the row matches the search criteria SELECT  PD.ProductDescriptionID,  PD.Description,  KEYTBL.[KEY],  KEYTBL.RANK FROM  Production.ProductDescriptionAS PD 	INNER JOIN FREETEXTTABLE(Production.ProductDescription, Description, N’bike’) AS KEYTBL ON PD.ProductDescriptionID = KEYTBL.[KEY]
CONTAINS ,[object Object],SELECT ProductDescriptionID, Description FROM Production.ProductDescription WHERE CONTAINS(Description, N'bike'); SELECT ProductDescriptionID, Description FROM Production.ProductDescription WHERE CONTAINS(Description, N‘”bike*”'): INFLECTIONAL Consider word stems in search“ride“  “riding", “riden", .. THESAURUSReturn Synonyms"metal“   "gold", "aluminium"," steel", ..
SELECT ProductDescriptionID, Description FROM Production.ProductDescriptionWHERE CONTAINS(Description, N' FORMSOF (INFLECTIONAL, ride) '); SELECT ProductDescriptionID, Description FROM Production.ProductDescriptionWHERE CONTAINS(Description, N' FORMSOF (THESAURUS, ride) '); Word proximity NEAR ( ~ ) How near words are in the text/document SELECT ProductDescriptionID, Description FROM Production.ProductDescriptionWHERE CONTAINS(Description, N'mountainNEAR bike'); SELECT ProductDescriptionID, Description FROM Production.ProductDescriptionWHERE CONTAINS(Description, N'mountain~ bike'); SELECT ProductDescriptionID, Description FROM Production.ProductDescriptionWHERE CONTAINS(Description, 'ISABOUT (mountain weight(.8), bikes weight (.2) )');
CONTAINTABLE CONTAINSTABLE (table , { column_name | (column_list ) | * } ,' < contains_search_condition > ' [ , LANGUAGE language_term]   [ ,top_n_by_rank ] ) < contains_search_condition > ::=     { < simple_term >     | < prefix_term >     | < generation_term >     | < proximity_term >     | < weighted_term >     }     | { ( < contains_search_condition > )     { { AND | & } | { AND NOT | &! } | { OR | | } } < contains_search_condition > [ ...n ]     } < simple_term > ::=           word | "phrase " < prefix term > ::=      { "word *" | "phrase *" } < generation_term > ::=      FORMSOF ( { INFLECTIONAL | THESAURUS } , < simple_term > [ ,...n ] ) < proximity_term > ::=      { < simple_term > | < prefix_term > }      { { NEAR | ~ } { < simple_term > | < prefix_term > } } [ ...n ] < weighted_term > ::=      ISABOUT         ( { {   < simple_term >   | < prefix_term >   | < generation_term >   | < proximity_term >   }    [ WEIGHT (weight_value ) ]    } [ ,...n ]         )
Querying SQL Server Using Full-Text Search
Full-text search much more powerful than LIKE More specific, relevant results Better performance  LIKE for small amounts of text  Full-text search scales to huge documents Provides ranking of results Common uses Search through the content in a text-intensive, database driven website, e.g. a knowledge base Search the contents of documents stored in BLOB fields Perform advanced searches e.g. with exact phrases - "to be or not to be" (however needs care!) e.g. Boolean operators - AND, OR, NOT, NEAR
Integrated backup, restore and recovery Faster queries and index building Data definition language (DDL) statements for creating and altering indexes System stored procedures deprecated Noise Insensitivity – noise words no longer break the query Accent Insensitivity (optional) – e.g. café and cafe are the same Multiple columns can be included in full-text searches Pre-computed ranking optimizations when using FREETEXTTABLE Improved ranking algorithm Catalogs can be set to populate continuously track changes, or index when the CPU is idle
Writing FTS terms The power of FTS is in the expression which is passed to the CONTAINS or CONTAINSTABLE function Several different types of terms: Simple terms Prefix terms Generation terms Proximity terms Weighted terms
Simple terms Either words or phrases Quotes are optional, but recommended Matches columns which contain the exact words or phrases specified Case insensitive Punctuation is ignored e.g. CONTAINS(Column, 'SQL') CONTAINS(Column, ' "SQL" ') CONTAINS(Column, 'Microsoft SQL Server') CONTAINS(Column, ' "Microsoft SQL Server" ')
Prefix terms Matches words beginning with the specified text e.g. CONTAINS(Column, ' "local*" ') matches local, locally, locality CONTAINS(Column, ' "local wine*" ') matches "local winery", "locally wined"
Generation terms Inflectional FORMSOF(INFLECTIONAL, "expression") "drive“  "drove", "driven", .. (share the same stem) When vague words such as "best" are used, doesn't match the exact word, only "good" Thesaurus FORMSOF(THESAURUS, "expression") "metal“   "gold", "aluminium"," steel", .. Both return variants of the specified word, but variants are determined differently
Thesaurus Supposed to match synonyms of search terms – but the thesaurus seems to be very limited Does not match plurals Not particularly useful http://technet.microsoft.com/en-us/library/cc721269.aspx#_Toc202506231
Proximity terms SyntaxCONTAINS(Column, 'local NEAR winery')CONTAINS(Column, ' "local" NEAR "winery" ') Important for ranking Both words must be in the column, like AND Terms on either side of NEAR must be either simple or proximity terms
Weighted terms Each word can be given a rank Can be combined with simple, prefix, generation and proximity terms e.g. CONTAINS(Column, 'ISABOUT(	performance weight(.8),	comfortable weight(.4))') CONTAINS(Column, 'ISABOUT(	FORMSOF(INFLECTIONAL, "performance") weight (.8),	FORMSOF(INFLECTIONAL, "comfortable") weight (.4))')
Pro Contra Pros?Cons?
Disadvantages Full text catalogs  Disk space  Up-to-date Continuous updating  performance hit Queries  Complicated to generate  Generated as a string Generated on the client
Advantages Backing up full text catalogs SQL 2005 Included in SQL backups by default Retained on detach and re-attach Option in detach dialog to include keep the full text catalog In SQL2008 you don’t have to worry about this
Advantages Much more powerful than LIKE Specific Ranking Performance Pre-computed ranking (FREETEXTTABLE) Configurable Population Schedule Continuously track changes, or index when the CPU is idle
Quick tips - Podcasts Pluralcast - SQL Server Under the Covers http://shrinkster.com/1ff4 Dotnetrocks - Search for SQL Server http://www.dotnetrocks.com/archives.aspx RunAsRadio - Search for SQL Server http://www.runasradio.com/archives.aspx

More Related Content

What's hot (7)

Les 01 Arch
Les 01 ArchLes 01 Arch
Les 01 Arch
 
OTN TOUR 2016 - DBA Commands and Concepts That Every Developer Should Know
OTN TOUR 2016 - DBA Commands and Concepts That Every Developer Should KnowOTN TOUR 2016 - DBA Commands and Concepts That Every Developer Should Know
OTN TOUR 2016 - DBA Commands and Concepts That Every Developer Should Know
 
Batchhow
BatchhowBatchhow
Batchhow
 
phoenix-on-calcite-nyc-meetup
phoenix-on-calcite-nyc-meetupphoenix-on-calcite-nyc-meetup
phoenix-on-calcite-nyc-meetup
 
OGSA-DAI DQP: A Developer's View
OGSA-DAI DQP: A Developer's ViewOGSA-DAI DQP: A Developer's View
OGSA-DAI DQP: A Developer's View
 
Parsing strange v2
Parsing strange v2Parsing strange v2
Parsing strange v2
 
Useful PL/SQL Supplied Packages
Useful PL/SQL Supplied PackagesUseful PL/SQL Supplied Packages
Useful PL/SQL Supplied Packages
 

Viewers also liked

Effective Usage of SQL Server 2005 Database Mirroring
Effective Usage of SQL Server 2005 Database MirroringEffective Usage of SQL Server 2005 Database Mirroring
Effective Usage of SQL Server 2005 Database Mirroring
webhostingguy
 

Viewers also liked (16)

quản trị CSDL với SQL
quản trị CSDL với SQLquản trị CSDL với SQL
quản trị CSDL với SQL
 
Applied Semantic Search with Microsoft SQL Server
Applied Semantic Search with Microsoft SQL ServerApplied Semantic Search with Microsoft SQL Server
Applied Semantic Search with Microsoft SQL Server
 
Understanding indices
Understanding indicesUnderstanding indices
Understanding indices
 
Secrets of Enterprise Data Mining 201310
Secrets of Enterprise Data Mining 201310Secrets of Enterprise Data Mining 201310
Secrets of Enterprise Data Mining 201310
 
Sql Saturday 111 Atlanta applied enterprise semantic mining
Sql Saturday 111 Atlanta applied enterprise semantic miningSql Saturday 111 Atlanta applied enterprise semantic mining
Sql Saturday 111 Atlanta applied enterprise semantic mining
 
FileTable and Semantic Search in SQL Server 2012
FileTable and Semantic Search in SQL Server 2012FileTable and Semantic Search in SQL Server 2012
FileTable and Semantic Search in SQL Server 2012
 
Sql 2012 development and programming
Sql 2012  development and programmingSql 2012  development and programming
Sql 2012 development and programming
 
Backup and Restore SQL Server Databases in Microsoft Azure
Backup and Restore SQL Server Databases in Microsoft AzureBackup and Restore SQL Server Databases in Microsoft Azure
Backup and Restore SQL Server Databases in Microsoft Azure
 
Effective Usage of SQL Server 2005 Database Mirroring
Effective Usage of SQL Server 2005 Database MirroringEffective Usage of SQL Server 2005 Database Mirroring
Effective Usage of SQL Server 2005 Database Mirroring
 
SQL Server Performance Tuning Baseline
SQL Server Performance Tuning BaselineSQL Server Performance Tuning Baseline
SQL Server Performance Tuning Baseline
 
Sql Server Performance Tuning
Sql Server Performance TuningSql Server Performance Tuning
Sql Server Performance Tuning
 
SQL Server - Querying and Managing XML Data
SQL Server - Querying and Managing XML DataSQL Server - Querying and Managing XML Data
SQL Server - Querying and Managing XML Data
 
Always on in SQL Server 2012
Always on in SQL Server 2012Always on in SQL Server 2012
Always on in SQL Server 2012
 
File Upload
File UploadFile Upload
File Upload
 
What's new in SQL Server 2016
What's new in SQL Server 2016What's new in SQL Server 2016
What's new in SQL Server 2016
 
Implementing Full Text in SQL Server
Implementing Full Text in SQL ServerImplementing Full Text in SQL Server
Implementing Full Text in SQL Server
 

Similar to SQL Server - Full text search

What's New for Developers in SQL Server 2008?
What's New for Developers in SQL Server 2008?What's New for Developers in SQL Server 2008?
What's New for Developers in SQL Server 2008?
ukdpe
 
As08 Revised
As08 RevisedAs08 Revised
As08 Revised
chapm1943
 
Sql tuning guideline
Sql tuning guidelineSql tuning guideline
Sql tuning guideline
Sidney Chen
 
Building A Catalog Of Power Copies S2010
Building A Catalog Of Power Copies S2010Building A Catalog Of Power Copies S2010
Building A Catalog Of Power Copies S2010
Catiadr
 
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu   (obscure) tools of the trade for tuning oracle sq lsTony Jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
InSync Conference
 

Similar to SQL Server - Full text search (20)

Sql Summit Clr, Service Broker And Xml
Sql Summit   Clr, Service Broker And XmlSql Summit   Clr, Service Broker And Xml
Sql Summit Clr, Service Broker And Xml
 
Cursors, triggers, procedures
Cursors, triggers, proceduresCursors, triggers, procedures
Cursors, triggers, procedures
 
Erik_van_Roon.pdf
Erik_van_Roon.pdfErik_van_Roon.pdf
Erik_van_Roon.pdf
 
SQL Server 2016 novelties
SQL Server 2016 noveltiesSQL Server 2016 novelties
SQL Server 2016 novelties
 
Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005
 
TSQL in SQL Server 2012
TSQL in SQL Server 2012TSQL in SQL Server 2012
TSQL in SQL Server 2012
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
38_Spotkanie_PLSSUGweWroclawiu_KilkaSłów_ApexSQL_FreeTools
38_Spotkanie_PLSSUGweWroclawiu_KilkaSłów_ApexSQL_FreeTools38_Spotkanie_PLSSUGweWroclawiu_KilkaSłów_ApexSQL_FreeTools
38_Spotkanie_PLSSUGweWroclawiu_KilkaSłów_ApexSQL_FreeTools
 
What's New for Developers in SQL Server 2008?
What's New for Developers in SQL Server 2008?What's New for Developers in SQL Server 2008?
What's New for Developers in SQL Server 2008?
 
SQL Server 2008 Overview
SQL Server 2008 OverviewSQL Server 2008 Overview
SQL Server 2008 Overview
 
As08 Revised
As08 RevisedAs08 Revised
As08 Revised
 
Sql tuning guideline
Sql tuning guidelineSql tuning guideline
Sql tuning guideline
 
R12 d49656 gc10-apps dba 07
R12 d49656 gc10-apps dba 07R12 d49656 gc10-apps dba 07
R12 d49656 gc10-apps dba 07
 
Introduction to Elasticsearch
Introduction to ElasticsearchIntroduction to Elasticsearch
Introduction to Elasticsearch
 
Building A Catalog Of Power Copies S2010
Building A Catalog Of Power Copies S2010Building A Catalog Of Power Copies S2010
Building A Catalog Of Power Copies S2010
 
Building and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning CBuilding and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning C
 
Introduction to Oracle Database.pptx
Introduction to Oracle Database.pptxIntroduction to Oracle Database.pptx
Introduction to Oracle Database.pptx
 
Introducing U-SQL (SQLPASS 2016)
Introducing U-SQL (SQLPASS 2016)Introducing U-SQL (SQLPASS 2016)
Introducing U-SQL (SQLPASS 2016)
 
Dynamic websites lec3
Dynamic websites lec3Dynamic websites lec3
Dynamic websites lec3
 
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu   (obscure) tools of the trade for tuning oracle sq lsTony Jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
 

More from Peter Gfader

More from Peter Gfader (20)

Achieving Technical Excellence in Your Software Teams - from Devternity
Achieving Technical Excellence in Your Software Teams - from Devternity Achieving Technical Excellence in Your Software Teams - from Devternity
Achieving Technical Excellence in Your Software Teams - from Devternity
 
You Can't Be Agile If Your Testing Practices Suck - Vilnius October 2019
You Can't Be Agile If Your Testing Practices Suck - Vilnius October 2019You Can't Be Agile If Your Testing Practices Suck - Vilnius October 2019
You Can't Be Agile If Your Testing Practices Suck - Vilnius October 2019
 
You Cant Be Agile If Your Code Sucks (with 9 Tips For Dev Teams)
You Cant Be Agile If Your Code Sucks (with 9 Tips For Dev Teams)You Cant Be Agile If Your Code Sucks (with 9 Tips For Dev Teams)
You Cant Be Agile If Your Code Sucks (with 9 Tips For Dev Teams)
 
How to make more impact as an engineer
How to make more impact as an engineerHow to make more impact as an engineer
How to make more impact as an engineer
 
13 explosive things you should try as an agilist
13 explosive things you should try as an agilist13 explosive things you should try as an agilist
13 explosive things you should try as an agilist
 
You cant be agile if your code sucks
You cant be agile if your code sucksYou cant be agile if your code sucks
You cant be agile if your code sucks
 
Use Scrum and Continuous Delivery to innovate like crazy!
Use Scrum and Continuous Delivery to innovate like crazy!Use Scrum and Continuous Delivery to innovate like crazy!
Use Scrum and Continuous Delivery to innovate like crazy!
 
Innovation durch Scrum und Continuous Delivery
Innovation durch Scrum und Continuous DeliveryInnovation durch Scrum und Continuous Delivery
Innovation durch Scrum und Continuous Delivery
 
Speed = $$$
Speed = $$$Speed = $$$
Speed = $$$
 
Qcon london2012 recap
Qcon london2012 recapQcon london2012 recap
Qcon london2012 recap
 
Continuous Delivery with TFS msbuild msdeploy
Continuous Delivery with TFS msbuild msdeployContinuous Delivery with TFS msbuild msdeploy
Continuous Delivery with TFS msbuild msdeploy
 
Silverlight vs HTML5 - Lessons learned from the real world...
Silverlight vs HTML5 - Lessons learned from the real world...Silverlight vs HTML5 - Lessons learned from the real world...
Silverlight vs HTML5 - Lessons learned from the real world...
 
Clean Code Development
Clean Code DevelopmentClean Code Development
Clean Code Development
 
Data Mining with SQL Server 2008
Data Mining with SQL Server 2008Data Mining with SQL Server 2008
Data Mining with SQL Server 2008
 
SSAS - Other Cube Browsers
SSAS - Other Cube BrowsersSSAS - Other Cube Browsers
SSAS - Other Cube Browsers
 
Reports with SQL Server Reporting Services
Reports with SQL Server Reporting ServicesReports with SQL Server Reporting Services
Reports with SQL Server Reporting Services
 
OLAP – Creating Cubes with SQL Server Analysis Services
OLAP – Creating Cubes with SQL Server Analysis ServicesOLAP – Creating Cubes with SQL Server Analysis Services
OLAP – Creating Cubes with SQL Server Analysis Services
 
Business Intelligence with SQL Server
Business Intelligence with SQL ServerBusiness Intelligence with SQL Server
Business Intelligence with SQL Server
 
Usability AJAX and other ASP.NET Features
Usability AJAX and other ASP.NET FeaturesUsability AJAX and other ASP.NET Features
Usability AJAX and other ASP.NET Features
 
Work with data in ASP.NET
Work with data in ASP.NETWork with data in ASP.NET
Work with data in ASP.NET
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 

SQL Server - Full text search

  • 1. SQL Server 2008 for Developers UTS Short Course
  • 2. Peter Gfader Specializes in C# and .NET (Java not anymore) TestingAutomated tests Agile, ScrumCertified Scrum Trainer Technology aficionado Silverlight ASP.NET Windows Forms
  • 3. Course Website Course Timetable & Materials http://www.ssw.com.au/ssw/Events/2010UTSSQL/ Resources http://sharepoint.ssw.com.au/Training/UTSSQL/
  • 5. What we did last weekCLR Integration .NET .NET FX CLR
  • 6. What we did last weekCLR Integration Stored Proc Functions Triggers Bottom Line Use T-SQL for all data operations Use CLR assemblies for any complex calculations and transformations
  • 7. Homework? Find all products that have a productnumber starting with BK Find all products with "Road" in the name that are Silver Find a list of products that have no review Find the list price ([listprice]) of all products in our shop What is the sum of the list price of all our products Find the product with the maximum and minimum listprice Find a list of products with their discount sale (hint see Sales.SalesOrderDetail) Find the sum of pricesof the products in each subcategory
  • 8. Session 5SQL Server Full-Text Searchusing Full-Text search in SQL Server 2008
  • 9. Agenda What is Full text search The old way 2005 The new way 2008 How to Querying
  • 10. What is Fulltext search SELECT *FROM [Northwind].[dbo].[Employees]WHERE Notes LIKE '%grad%‘
  • 11. What is REAL Fulltext search Allows searching for text/words in columns Similar words Plural of words Based on special index Full-text index (Full text catalog) SELECT *FROM [Northwind].[dbo].[Employees]WHEREFREETEXT(*,'grad‘)
  • 13.
  • 14.
  • 15. Full-Text Search Terminology 3/3 Stopwords/Stoplists not relevant word to search e.g. ‘and’, ‘a’, ‘is’ and ‘the’ in English Accent insensitivity cafè = cafe
  • 16. Fulltext search – Under the hood
  • 17. The old way! SQL 2005
  • 18.
  • 19. The new way! SQL 2008
  • 20.
  • 22. Administering Full-Text Search Full-text administration can be separated into three main tasks: Creating/altering/dropping full-text catalogs Creating/altering/dropping full-text indexes Scheduling and maintaining index population.
  • 25. Administering Full-Text Search Automatic update of index Slows down database performance Manually repopulate full text index Time consuming Asynchronous process in the background Periods of low activity Index not up to date
  • 26.
  • 27.
  • 28. Creating a Full-Text Catalog (SQL 2005) Syntax CREATE FULLTEXT CATALOG catalog_name       [ON FILEGROUP filegroup]      [IN PATH 'rootpath']       [WITH <catalog_option>]       [AS DEFAULT]       [AUTHORIZATION owner_name ] <catalog_option>::=      ACCENT_SENSITIVITY = {ON|OFF} Example USE AdventureWorks_FulllText CREATE FULLTEXT CATALOG AdventureWorks_FullTextCatalog ON FILEGROUP FullTextCatalog_FGWITH ACCENT_SENSITIVITY = ON AS DEFAULTAUTHORIZATION dbo
  • 29. Creating a Full-Text CatalogStep by step Create a directory on the operating system named C:est Launch SSMS, connect to your instance, and open a new query window Add a new filegroup to the AdventureWorks_FulllText USE Master GO ALTER DATABASE AdventureWorks_FulllText GO ALTER DATABASE AdventureWorks_FulllText ADD FILE (NAME = N’ AdventureWorks_FulllText _data’, FILENAME=N’C:ESTAdventureWorks_FulllText _data.ndf’, SIZE=2048KB, FILEGROTH=1024KB ) TO FILEGROUP [FTFG1] GO Create a full-text catalog on the FTFG1 filegroup by executing the following command:USE AdventureWorks_FulllTextGOCREATE FULLTEXT CATALOG AWCatalog on FILEGROUP FTFG1 IN PATH ‘C:EST’ AS DEFAULT;GO
  • 32. How toCreating Full Text Indexes
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 44.
  • 45. Summary TSQL command CREATE FULLTEXT INDEX Full-text indexes on Text-based Binary Image columns VARBINARY / IMAGE Store files in their native format within SQL Server Full-text indexing and searching Lots of helper services/functionality Word-breaker routines, language files, noise word files, filters and protocol handlers.
  • 46. How to Index and Catalog Population
  • 47. Because of the external structure for storing full-text indexes, changes to underlying data columns are not immediately reflected in the full-text index. Instead, a background process enlists the word breakers, filters and noise word filters to build the tokens for each column, which are then merged back into the main index either automatically or manually. This update process is called population or a crawl. To keep your full-text indexes up to date, you must periodically populate them. Populating a Full-Text Index
  • 48. You can choose from there modes for full-text population: Full Incremental Update Populating a Full-Text Index
  • 49. Populating a Full-Text Index Full Read and process all rows Very resource-intensive Incremental Automatically populates the index for rows that were modified since the last population Requires timestamp column Update Uses changes tracking from SQL Server (inserts, updates, and deletes) Specify how you want to propagate the changes to the index AUTO automatic processing MANUAL implement a manual method for processing changes
  • 50. Populating a Full-Text Index Example ALTER FULLTEXT INDEX ON Production.ProductDescription START FULL POPULATION; ALTER FULLTEXT INDEX ON Production.Document START FULL POPULATION;
  • 51.
  • 52. Populating a Full-Text Catalog Example USE AdventureWorks_FulllText; ALTER FULLTEXT CATALOG AdventureWorks_FullTextCatalogREBUILD WITH ACCENT_SENSITIVITY=OFF; -- Check Accentsensitivity SELECT FULLTEXTCATALOGPROPERTY('AdventureWorks_FullTextCatalog', 'accentsensitivity');
  • 53.
  • 54.
  • 55. Managing Population Schedules In SQL 2000, full text catalogs could only be populated on specified schedules SQL 2005/2008 can track database changes and keep the catalog up to date, with a minor performance hit
  • 56. How toQuerying SQL Server Using Full-Text Search Querying SQL Server Using Full-Text Search Full-Text query keywords FREETEXT FREETEXTTABLE CONTAINS CONTAINSTABLE
  • 57. FREETEXT Fuzzy search (less precise ) Inflectional forms (Stemming) Related words (Thesaurus)
  • 58. FREETEXT Fuzzy search (less precise ) Inflectional forms (Stemming) Related words (Thesaurus) SELECT ProductDescriptionID, Description FROM Production.ProductDescription WHERE [Description] LIKE N'%bike%'; SELECT ProductDescriptionID, Description FROM Production.ProductDescription WHERE FREETEXT(Description, N’bike’);
  • 59. FREETEXTTABLE + rank column Value between 1 and 1,000 Relative number, how well the row matches the search criteria SELECT PD.ProductDescriptionID, PD.Description, KEYTBL.[KEY], KEYTBL.RANK FROM Production.ProductDescriptionAS PD INNER JOIN FREETEXTTABLE(Production.ProductDescription, Description, N’bike’) AS KEYTBL ON PD.ProductDescriptionID = KEYTBL.[KEY]
  • 60.
  • 61. SELECT ProductDescriptionID, Description FROM Production.ProductDescriptionWHERE CONTAINS(Description, N' FORMSOF (INFLECTIONAL, ride) '); SELECT ProductDescriptionID, Description FROM Production.ProductDescriptionWHERE CONTAINS(Description, N' FORMSOF (THESAURUS, ride) '); Word proximity NEAR ( ~ ) How near words are in the text/document SELECT ProductDescriptionID, Description FROM Production.ProductDescriptionWHERE CONTAINS(Description, N'mountainNEAR bike'); SELECT ProductDescriptionID, Description FROM Production.ProductDescriptionWHERE CONTAINS(Description, N'mountain~ bike'); SELECT ProductDescriptionID, Description FROM Production.ProductDescriptionWHERE CONTAINS(Description, 'ISABOUT (mountain weight(.8), bikes weight (.2) )');
  • 62. CONTAINTABLE CONTAINSTABLE (table , { column_name | (column_list ) | * } ,' < contains_search_condition > ' [ , LANGUAGE language_term]   [ ,top_n_by_rank ] ) < contains_search_condition > ::=     { < simple_term >     | < prefix_term >     | < generation_term >     | < proximity_term >     | < weighted_term >     }     | { ( < contains_search_condition > )     { { AND | & } | { AND NOT | &! } | { OR | | } } < contains_search_condition > [ ...n ]     } < simple_term > ::=           word | "phrase " < prefix term > ::=      { "word *" | "phrase *" } < generation_term > ::=      FORMSOF ( { INFLECTIONAL | THESAURUS } , < simple_term > [ ,...n ] ) < proximity_term > ::=      { < simple_term > | < prefix_term > }      { { NEAR | ~ } { < simple_term > | < prefix_term > } } [ ...n ] < weighted_term > ::=      ISABOUT         ( { {   < simple_term >   | < prefix_term >   | < generation_term >   | < proximity_term >   }    [ WEIGHT (weight_value ) ]    } [ ,...n ]         )
  • 63. Querying SQL Server Using Full-Text Search
  • 64. Full-text search much more powerful than LIKE More specific, relevant results Better performance LIKE for small amounts of text Full-text search scales to huge documents Provides ranking of results Common uses Search through the content in a text-intensive, database driven website, e.g. a knowledge base Search the contents of documents stored in BLOB fields Perform advanced searches e.g. with exact phrases - "to be or not to be" (however needs care!) e.g. Boolean operators - AND, OR, NOT, NEAR
  • 65. Integrated backup, restore and recovery Faster queries and index building Data definition language (DDL) statements for creating and altering indexes System stored procedures deprecated Noise Insensitivity – noise words no longer break the query Accent Insensitivity (optional) – e.g. café and cafe are the same Multiple columns can be included in full-text searches Pre-computed ranking optimizations when using FREETEXTTABLE Improved ranking algorithm Catalogs can be set to populate continuously track changes, or index when the CPU is idle
  • 66. Writing FTS terms The power of FTS is in the expression which is passed to the CONTAINS or CONTAINSTABLE function Several different types of terms: Simple terms Prefix terms Generation terms Proximity terms Weighted terms
  • 67. Simple terms Either words or phrases Quotes are optional, but recommended Matches columns which contain the exact words or phrases specified Case insensitive Punctuation is ignored e.g. CONTAINS(Column, 'SQL') CONTAINS(Column, ' "SQL" ') CONTAINS(Column, 'Microsoft SQL Server') CONTAINS(Column, ' "Microsoft SQL Server" ')
  • 68. Prefix terms Matches words beginning with the specified text e.g. CONTAINS(Column, ' "local*" ') matches local, locally, locality CONTAINS(Column, ' "local wine*" ') matches "local winery", "locally wined"
  • 69. Generation terms Inflectional FORMSOF(INFLECTIONAL, "expression") "drive“  "drove", "driven", .. (share the same stem) When vague words such as "best" are used, doesn't match the exact word, only "good" Thesaurus FORMSOF(THESAURUS, "expression") "metal“  "gold", "aluminium"," steel", .. Both return variants of the specified word, but variants are determined differently
  • 70. Thesaurus Supposed to match synonyms of search terms – but the thesaurus seems to be very limited Does not match plurals Not particularly useful http://technet.microsoft.com/en-us/library/cc721269.aspx#_Toc202506231
  • 71. Proximity terms SyntaxCONTAINS(Column, 'local NEAR winery')CONTAINS(Column, ' "local" NEAR "winery" ') Important for ranking Both words must be in the column, like AND Terms on either side of NEAR must be either simple or proximity terms
  • 72. Weighted terms Each word can be given a rank Can be combined with simple, prefix, generation and proximity terms e.g. CONTAINS(Column, 'ISABOUT( performance weight(.8), comfortable weight(.4))') CONTAINS(Column, 'ISABOUT( FORMSOF(INFLECTIONAL, "performance") weight (.8), FORMSOF(INFLECTIONAL, "comfortable") weight (.4))')
  • 74. Disadvantages Full text catalogs Disk space Up-to-date Continuous updating  performance hit Queries Complicated to generate Generated as a string Generated on the client
  • 75. Advantages Backing up full text catalogs SQL 2005 Included in SQL backups by default Retained on detach and re-attach Option in detach dialog to include keep the full text catalog In SQL2008 you don’t have to worry about this
  • 76. Advantages Much more powerful than LIKE Specific Ranking Performance Pre-computed ranking (FREETEXTTABLE) Configurable Population Schedule Continuously track changes, or index when the CPU is idle
  • 77. Quick tips - Podcasts Pluralcast - SQL Server Under the Covers http://shrinkster.com/1ff4 Dotnetrocks - Search for SQL Server http://www.dotnetrocks.com/archives.aspx RunAsRadio - Search for SQL Server http://www.runasradio.com/archives.aspx
  • 78. Session 5 Lab Full text search Download from Course Materials Site (to copy/paste scripts) or type manually: http://sharepoint.ssw.com.au/Training/UTSSQL/
  • 80. Thank You! Gateway Court Suite 10 81 - 91 Military Road Neutral Bay, Sydney NSW 2089 AUSTRALIA ABN: 21 069 371 900 Phone: + 61 2 9953 3000 Fax: + 61 2 9953 3105 info@ssw.com.auwww.ssw.com.au