Have you ever needed to find something in a SQL table that you couldn’t quite remember the name? You know a certain part of it, or think you do, but you don’t know the whole thing? Maybe you want to be sure that you have changed all of a certain name in the table? Well, here’s how:

In SQL, there is this nifty concept of a “like” search, also many times called a “contains” search. What it does is gives you things “like” whatever you tell it.

Let’s say you have a table full of popular Tweets (twitter messages) and you want to find all the ones that have “Bieber” in them. Now I have no idea why you would store tweets in a database (there are usually much more elegant ways) especially ones that are related to Justin Bieber. I guess you would if you are a big fan. I’m not, I only added this to see if Bieber is good for my website traffic, as I have heard it is. Lil test for myself right here.

You could find all those tweets with “Bieber” somewhere in the tweet field by doing this:

SELECT tweet from tweets WHERE tweet like ‘%bieber%’

The ‘%searchtermhere%’ portion is the real magic, because it tells SQL to find a text string (inside the quotes) and the % (percents) are what tell it to find anything before and after the search term.

Of course you could leave off one or both of the % signs, to get only those matches in the field that have nothing before your term, and/or nothing after your term. So:

–this will only give you a list of results that have bieber at the very beginning of the text in that field. If there are matches that have any text BEFORE bieber, they won’t be included.
SELECT tweet from tweets WHERE tweet like ‘bieber%’

–this will do just the opposite, giving you only matches in the field that have something before bieber, but not after it.
SELECT tweet from tweets WHERE tweet like ‘%bieber’

You can remove both % to get only matches that the whole field’s contents are simply bieber.

You can also use these methods to find parts of words, especially if you don’t know how it is spelled. Simply replace bieber with bie or ber and it should still find it, though you might get things you don’t expect to. You can always find a correct spelling and rerun the query with the longer word to narrow it down. Works like a charm.

Hope this helps and makes sense, but if not, let me know and I will fix it or improve it. Thanks!

 

If you’ve ever worked with SQL Server or another database system, you’ve likely run into a situation where you need a way to sync changes from one database to another. If you develop with databases, you may want to do things like sync a dev database to a production database, and the ability to sync only certain objects and data could be very valuable, allowing you to selectively update parts of a database. I have looked at a lot of tools to help accomplish this, and there really aren’y many that are free especially, and few that perform this task well.

A tool that I just started using and have already fallen in love with is SQL Delta. It has a friendly, simple interface (which is weird in the IT world) that gets the job done with style, and makes things too easy to do. It is helpful, descriptive so there is little confusion, and has a bunch of tools that make the process cake.

You sign in to both databases from Delta, it compares everything (structure and data, though on different tabs) and tells you what differences there are between servers. It is literally the first-cousin of subversion or Visual Source Safe’s Diff tools, but it makes way more sense than that. I was able to sync 2 databases in minutes and it saved a project I was working on a lot of time and agony.

The single user license for Delta is $330 at present, which is nothing compared to the value it provides. They offer a 14 day trial — where everything seems to work as it would when purchased — as opposed to the trials that are “full featured” and only let you sync 4 records to “try it out” (ludicrously inadequate). They also have an Oracle version as well, which I haven’t tried but expect is just as good as the SQL version. This is for Windows only, but since you need windows to use SQL Server, it makes sense. If you’re looking for a database management tool to diff and sync all that juicy yummy data, consider this tool. It is a keeper.

SQL Delta