CONTAINS function is not working in SQL Server 2014 - sql-server

The following query is written using SQL Server 2014 CONTAINS function.
SELECT
Org1.OrganizationPK
,*
FROM Organization Org1
WHERE Org1.Deleted = 0
AND CONTAINS (Org1.NAME,'"chris6*"')
AND org1.OrgDomainInd = 1
But, the above query is NOT working.
I have followed this article to understand more about CONTAINS function. I have verified those examples as-they-are. Even here also, I am not getting any results.
I have verified this post from stackoverflow, but I could not apply for my requirement.
Hence, I am getting doubt whether I need to do anything more to configure SQL Server 2014 to work with CONTAINS fuction? Please let me know if there is anything I need to do to make SQL Server 2014 ready to use CONTAINS function.
If there is nothing like that, please suggest me the solution.
Please don't suggest me to use LIKE operator. I am telling this why because, most of my colleagues suggested me same; hence, as a precautionary matter I am writing this statement here.
I am running behind my schedule to complete this task.

Before CONTAINS will work against a column you need setup full text index. This is actually a different engine which runs as a separate service in SQL Server, so make sure it is installed an running.
Once you're sure the component is installed (it may already be installed) You need to do the following:
Create a Full-Text Catalogue
Create a Full-Text Index (you can have multiple of these in the same catalogue) against the tables/columns you want to be able to use full-text keywords
Run a Population which will crawl the index created & populate the catalogue (these are seperate files which SQL Server needs to maintain in addition to mdf/ldf )
There's an ok tutorial on how to do this by using SSMS in SQL Server 2008 by Pinal Dave on CodeProject. SQL Server 2014 should be very similar.
You can also perform these steps with TSQL:
CREATE FULLTEXT CATALOG
CREATE FULLTEXT INDEX
ALTER FULLTEXT INDEX

I believe that contains functionality can only be used in tables configured to use/support Full Text Search -- an elderly feature of SQL Server that I have little experience with. If you are not using Full Text Search, I'm pretty sure contains will not work.

Related

Retrieving text from FileTable SQL Server

Is it possible to retrieve the actual text from a File Table in SQL Server 2014?
I want to implement some hit-highlighting functionality, but in order to do so, I need to retrieve the actual text in the file I indexed, since the content is in a varbinary column.
If it's not possible, I suppose the only alternative to do this is forgetting about FileTables and implementing an application-side "document reader", so that I'll have real text inside my "file_stream" column instead of the varbinary. Or maybe even defining an UDF that uses iFilters behind some C# code, right?
Please, any advice would be really useful.
Before you do start with your own implementation, take a look at the very similar question:
SQL Server 2012 FTS with Hit-Highlighting?
Also this blog entry from 2012 is still current:
Hit-Highlighting in Full-Text Search
I would take a look at the mentioned HitHighlight function (which is actually a commercial product, ThinkHighlight). Most likely it's not worth the effort to build your own solution. But if you do so - tell me ;)

Querying multiple MS SQL database instances on the same machine

I am new to MS SQL and I am trying to do something that seems simple but is driving me crazy.
I want to write a query to pull data from two databases. Each database is on a different instance on the same DEV machine. (one is MS SQL 2008 and the other MS SQL 2005). I am using the Microsoft SQL Server Management Studio (MSSMS).
I have the basics figured out. I know the format of the query and what I need to do. My big problem is figuring out what the NAME of each server is?
SELECT LastName
FROM [servername1].CHA2.dbo.Customer
UNION
SELECT LastName
FROM [servername2].OBXKites.dbo.Contact
ORDER BY LastName
I used the server name that I connect to MSSMS (DLPT\HENRY) with and what is also returned by ##SERVERNAME
SELECT ##SERVERNAME returns DLPT\HENRY
I tried
DLPT\HENRY.CHA2.dbo.Customer
did not work
I tried it without the DLPT HENRY.CHA2.dbo.Customer
did not work
I need to future out what the NAME of the server is to use in the query.
[DLPT\HENRY].CHA2.dbo.Customer
The namo contains a backslash which is normally illegal in an identifier. You surround illegal names with brackets.
Note that you surround just the server name. In other words, it is [DLPT\HENRY].CHA2.dbo.Customer, not [DLPT\HENRY.CHA2.dbo.Customer].
You have to configure Linked servers. Then only different instances of SQL Server are able to communicate with each other.
Unfortunately you can't access tables in databases in separate SQL Server instances by default. You have a couple of options here - neither are simple and might require help from a DBA:
1) Use linked servers like this:
http://technet.microsoft.com/en-us/library/ff772782(v=sql.110).aspx
Then you will be able to refer to the second table in the format INSTANCENAME.DatabaseName.SchemaName.TableName
2) Use replication to get the table from the second database into the first database. Then the contents of the second table will be synched to the first database in more or less real time
Read about SQL Replication here

Full Text Search Auto-Partition Schemes and Functions

We have some full text searches running on our SQL Server 2012 Development (Enterprise) database. We noticed that partition schemes and functions are being (periodically) added to the DB. I can only assume that the partitions are for FTS as they have the following form:
Scheme:
CREATE PARTITION SCHEME [ifts_comp_fragment_data_space_46093FC3] AS PARTITION [ifts_comp_fragment_partition_function_46093FC3] TO ([FTS], [FTS], [FTS])
Function:
CREATE PARTITION FUNCTION [ifts_comp_fragment_partition_function_46093FC3](varbinary(128)) AS RANGE LEFT FOR VALUES (0x00330061007A00660073003200360036, 0x0067006F00730066006F00720064)
The problem is that our production servers are running SQL Server 2012 Standard which does not support partitions. Thus it adds an extra admin burden on our schema compares (using SSDT) to exclude these partitions every time. When one does (inevitably) creep in it is a pain to remove. We have done some extensive research and have not been able to come up with any answer as to why this is even happening. Any ideas?
Yes, those are internal to the fulltext search functionality. You have no control over them.
However, I would consider it a bug that they show up in your schema compares. You'll never create/alter/drop them yourselves, and they completely maintained by sql server, so I would file a bug report on http://connect.microsoft.com

MS Access 2007 queries does't run on SQL Server 2008

I am developing an application in C# VS 2010 past 4 months. I used MS Access 2007 to store my nearly 20 tables successfully.
Today I realized that my data base cannot be handled consistently by MS Access 2007. Hence I decided to go for SQL Server 2008 R2 Express with Upsizing wizard and it worked really great!
However, when I tried to run various options of my already well developed application, It kept throwing error each time when a query is fired to SQL Server.
I understood that Many of the stuffs of SQL supported by MS Access are not supported by MS SQL Server
For example: query with date, for representing date format when we use '#', SQL Server 2008 won' t recognize it.
Also, for Bool value, MS Access stores it as True and False where as SQL Server uses 0.
These all queries worked perfect with Access 07
I am sure that there must be some method so that SQL Server can understand MS access queries.
Or will I have to edit my whole application?? It will be as good as digging a mine for earning gold..
I have changed all data access objects such as reader, adapter, command, connection to SQL data objects using System.Data.SqlClient.
So, It is not the problem.
Please help me asap.
Thank you.
You cannot force SQL Server to run the MS Access queries. These queries will need to be rewritten to use T-SQL instead of the query language that MS Access uses.
I feel your pain, I just had to rewrite a large MS Access application (over 1k queries) that needed to be recreated to be used in SQL Server.
There will be some queries that might be able to be ported over directly but as you noticed queries with date, and even some of the aggregate functions (First(), etc) are not used in SQL Server and those queries will need to be changed.
Here is a link with some info on converting Access to SQL
Converting Access Queries to SQL Server
You are right that, most of the time, you cannot just take the SQL of a query from Access and run it within SQL Server. It may work for very simple queries, but usually you need to tweak them.
There are a few steps I would take:
Extract your queries (which I presume are in your code), and re-create them in your Access database. Make sure they work there as normal Access queries.
(you can for instance simply add some code to your app to print all queries to files so you don't have to mess with parameters, then just copy/paste them in your Access DB).
The point is simply to have working queries within Access.
Use SSMA from Microsoft for helping you to move your queries to SQL Server. It does a good job of translating them into T-SQL.
You may still have to convert some troublesome queries by hand, but it shouldn't be that many and usually the conversion is not difficult.
Once converted to T-SQL, just re-inject these working queries into your code, or keep the complex queries in SQL Server as views (which it usually be faster as SQL Server will have already created its execution plan, rather than your application sending raw SQL that the server needs to analyse).
As you pointed out, there could be some issues if your fields use some features that don't cross-over to SQL Server properly.
Look at your tables in Access and do some cleanup before attempting to convert:
For booleans fields:
Make sure you set their default values to 0 or 1 (they should not be empty).
Required fields must be non-null:
Make sure that any fields that you have set as 'Required' does not contain any NULL values in its data.
Unique indexes cannot ignore Null:
Check that your indexes are not set to be both 'Unique' and 'Ignore null'.
All tables must have clean primary keys:
Make sure all your tables have a unique primary key that doesn't have Null values in their data.

sys.dm_db_missing_index_details returns no rows

I have tried to look at sys.dm_db_missing_index_details to check for missing indexes on my SQL Server 2005 database. It is returning no rows.
It is possible that it should be empty but highly unlikely as I have not added ANY indices on any table (except the ones you get by creating primary keys). I am also running unit tests as well as adhoc development tests (using Linq to SQL) against it so there is some activity against it.
Do I need to turn on the capturing of this data?
Is this only supported on certain editions of SQL Server 2005?
Thanks in advance for any efforts to help.
It appears that it's on by default - although check any shortcut you are using to launch and make sure it's not launching with a -x
From http://msdn.microsoft.com/en-us/library/ms345524(v=SQL.90).aspx
This feature can only be disabled if an instance of SQL Server is started by using the -x argument with the sqlservr command-prompt utility.
Also you'll want to know that the table is populated as queries are run if SQL Server uses the query optimizer - this table is cleared when you restart SQL Server.
From http://msdn.microsoft.com/en-us/library/ms345434(v=SQL.90).aspx
Information returned by sys.dm_db_missing_index_details is updated when a query is optimized by the query optimizer, and is not persisted. Missing index information is kept only until SQL Server is restarted. Database administrators should periodically make backup copies of the missing index information if they want to keep it after server recycling.
Lastly there is an article that goes into the limitations here that you may or may not know about, but I'll post in case someone else happens across this post and needs: http://msdn.microsoft.com/en-us/library/ms345485(v=SQL.90).aspx
I didn't see anything about the feature being missing in some versions but you WILL need certain permissions:
Users must be granted the VIEW SERVER STATE permission or any permission that implies the VIEW SERVER STATE permission to query this dynamic management view.
Another option is to query the plan cache directly -- this also has the benefit that it can get you the query that wants the index. There's a related question here on SO -- the answer from BankZ has a complete SQL script that does the job.
It may run slowly though - the plans are in XML format, so with this query, we're asking SQL Server to do lots of XML work rather than table work. But it does work :-)
And as with the main missing index table, the plan cache is cleared down if SQL Server is restarted.

Resources