Birnam Designs is a quality web design and development agency in Virginia

Archive for the 'database' Category

find out what version of SQL Server you (or your host) is running

Tuesday, January 23rd, 2007

Have you ever wondered if the SQL Server 2005 database your host is providing might actually be an Express installation? Or maybe you’re curious if they’re running the most recent service pack?

I’ve run into several methods of finding out the version information. The easiest, and my preferred method, is using sseutil — my command-line sql utility of choice. All you have to do is use the -version argument! For instance:

If you’re interested in the version number, that’s on the first line. This lets you see if the server is up to date. Here is a full list of SQL Server 2005 version numbers, up to the December CTP of Service Pack 2. (If you need the same info on an older server, ASPFAQ has is an extensive list of SQL Server 7 and SQL Server 2000 versions)

If you’re more interested in which edition you’re running, that’s on the last line. It might read “Express Edition” or “Express Edition with Advanced Services” for the free Express edition, or “Standard Edition,” “Workgroup Edition,” or “Enterprise Edition” for the $$$ editions.

But this is only one method! What if you don’t have sseutil? You can always run this sql command:

And finally, I found an alternate method on Microsoft’s KnowledgeBase, it goes like this:

Setting up Full Text Search with SQL Express 2005 and Management Studio Express

Friday, December 15th, 2006

Here’s one for the .NET/MSSQL/SQL Express crowd.

Management Studio Express is a nice interface for managing SQL Express databases. While I prefer Visual Studio for working with the data and stored procedures, MSE is essential for the more high level maintenance like database creation and attaching, managing users, and setting up Full Text Search indexes.

First, a brief primer on FTS. It’s a brilliant tool that will take a lot of the effort out of writing search queries. It allows for much more than just boolean searches. It can also search for inflectional variations. For instance, if you searched for “apply” it will also return results for “applying,” “applies,” and “applied.” It can also return search score information to help you rank results — to which you can also apply custom weighting. The first thing to know, though, is that it doesn’t come with the default SQL Express 2005 installation! You need to install SQL Express 2005 with Advanced Services in order to have access to FTS at all.

Once you’ve got it installed in order to get it working you need to:

  1. enable FTS on the database you want to use
  2. create a folder to store the FTS index (optional: it will use the default folder if you don’t specify a location, but if you do specify a location the folder has to already exist)
  3. create a fulltext catalog with a unique ID, optionally set to the path created in the previous step
  4. add the catalog to each table in the database that will utilize it
  5. specify the columns in the tables that will use the FTS data
  6. specify the language of each column (optional, but if you don’t set this inflectional won’t work)

The first two steps are easy. In MSE, just right click on the database you want to add FTS to and open the Properties dialog. Open the Files page, and check the box next to “Use full-text indexing.” Save that and you’re ready to go. If you’re going to specify the location for the index, create the folder using whatever tool you fancy.

The first problem you’re going to run into, though is actually creating the FTS catalog in the first place. This is something that you can’t do in MSE. At least, I’ve never been able to find out how! Fortunately there’s a handy command line tool called SSEUtil (from Microsoft). It’s a bit more user friendly than the standard sqlcmd utility, which you could also use.

When starting sseutil from the command line, give it the “-c” (console) and “-m” (main) arguments. That gives you a command line into the same databases you see listed in MSE. Don’t omit the “-m” or you are actually starting sseutil as a secondary process and you will probably not have access the database you’re trying to edit. Don’t ask me why, I have no idea what the mechanics are here. All I know is that it usually takes me four hours of banging my head on the desk before I remember that little “-m” and then suddenly everything works. If you can access your database with Windows Security, that’s all you need.

sseutil -c -m

Once in sseutil, you just run two very simple commands. Don’t forget you have to say “go” to commit each command before processing. (I’m sure you could run them both and say “go” once, but it’s nice to get confirmation at each point.)


This selects the database you are managing, so replace “db_name” with the right name. To list the databases available use the sp_databases command. (Don’t forget the “go.”) Once you have confirmation “Command completed successfully” you just need to run the sp_fulltext_catalog stored procedure. This is where you give the catalog a unique ID and the optional path. You also need to tell it that you’re wanting to create a catalog (the same sp is used for deleting or re-indexing a catalog).


Again this is using sample names so replace “dbname_fulltext” and “c:\fts\dbname” with whatever works for you.

After you get confirmation on this, you’re finished with the command line. Close sseutil and get back to MSE. Open the drop down list for the database you’re managing, and open Tables. Find the table you want to add FTS to, right click and select Modify. This will open the column editing page.

In order for FTS to work, the table has to have a unique primary key. If the table doesn’t have one yet, create one. Now right click on the key icon in the margin next to the primary key, and select “Full-text Index”. The first step is to add this table to the FTS catalog you just created. This is as easy as clicking on the “Add” button (which isn’t available if you haven’t successfully created a catalog on this database!), which will add the table using the default name of FullText_for_tablename.

Now you will see the properties box on the right fill up. The only properties that you need to worry about right now is the very top one, under General. Click on that, and you’ll notice an […] button appear on the far right of that field. Click this button to add the columns of the table to the index.

This interface is very easy, just select from the available columns in the dropdown box on the first cell. The datatype will automatically be added. The “Typed by Column” box can be ignored, but I recommend selecting the language from the Language cell. This will allow you to do inflectional searches — without knowing the language SQL can’t apply the inflectional variations.

And that’s it! Add each column that you want, and do this for every table that you want. The index itself will be created and updated automatically.

For further reference, here is Microsoft’s page detailing Full-Text Search concepts. I recommend starting with Simple Term searches, and then looking into the inflectional searches. The primary SQL commands (technically, two ‘predicates’ and two ‘functions’) that are used in FTS queries are CONTAINS, FREETEXT, CONTAINSTABLE, and FREETEXTTABLE. Good luck!

tip: reset auto_increment number in MySQL databases

Tuesday, January 24th, 2006

Have you ever deleted rows in your MySQL database and created gaps between your highest auto_increment field and the next auto_increment value? Here’s an example, say “user_id” is an auto_incremented field:

user_id first_name
1 John
2 Sarah
3 Malcolm
4 Steven
5 Elisabeth

After entering Elisabeth as the fifth row, the next auto_increment number is 6. The problem shows up if you delete Elisabeth — the next auto_increment number is still 6! Even if you delete all of them, the next auto_increment number is still 6! How frustrating!

Fortunately, you can reset the auto_increment number easily with a simple SQL statement:

ALTER TABLE tablename AUTO_INCREMENT = 1

Your auto_increment number will be reset to the highest auto_increment data value + 1.