I'm running Sql Server 2008 R2 and I need to enable Full-Text search on a view with a inner join. My problem is that I don't know how to create my Full-Text Index.
When I use the Full-Text Indexing Wizard I get this error.
A unique column must be defined on this table/view.
In order for you to better understand my problem, please see the following example from w3school http://www.w3schools.com/sql/sql_join_inner.asp The last select is just my view.
PersonOrderView - View
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo
FROM Persons
INNER JOIN Orders
ON Persons.P_Id=Orders.P_Id
ORDER BY Persons.LastName <- Order by is not important for me
Persons - Table
P_Id (PK, int, not null)
LastName(nvarchar(50), null)
FirstName(nvarchar(50), null)
Address(nvarchar(50), null)
City(nvarchar(50), null)
Orders - Table
O_Id(PK, int, not null)
P_Id(FK, int, not null)
OrderNo(nvarchar(50), not null)
To implement a full-text search in a SQL database, you must create a full-text index on each column you want to be indexed. In MySQL, this would be done with the FULLTEXT keyword. Then you will be able to query the database using MATCH and AGAINST.
A: You can determine if Full-Text Search is installed by querying the FULLTEXTSERVICEPROPERTY like you can see in the following query. If the query returns 1 then Full-Text Search is enabled.
You can only create a full text index on an indexed view, that is why you are getting the error. To create full-text search on a table or view, it must have a unique, single-column, non-nullable index.
In other words, you should create your view something like this:
CREATE VIEW ViewSearch WITH SCHEMABINDING AS
SELECT Persons.P_Id AS ID, Persons.LastName, Persons.FirstName, Orders.OrderNo
FROM Persons
INNER JOIN Orders ON Persons.P_Id=Orders.P_Id
GO
CREATE UNIQUE CLUSTERED INDEX IX_ViewSearch ON ViewSearch (ID)
SQL full-text search builds a full-text index through a process called population, which fills the index with words and the locations in which they occur in your tables and rows. That is why you need a field that will uniquely identify you each row and that is why you need to make the view indexed.
More information here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With