At work I was given the task to write descriptions on all the tables and their columns on the project I'm working on. I spoke with my boss about writing the descriptions on the SQL server instead of using Visio due to prior "challenges" with Visio. The advantage of writing the descriptions on the SQL server is that if the database was reverse engineered in Visio, Visio would include the descriptions when reverse engineering and the same should be possible with other database design systems. Luckily my boss could see the advantage and gave me green light.
Anyway, it all went very well and a lot quicker than I first imagined until I got to the point where I needed to describe two computed columns. Enterprise Manager had disabled the description column for those two columns so it wasn't possible to change their description. At first I just added the missing descriptions as a text object in a SQL server diagram object which contained the owning table. But then I changed my mind and started investigating where the descriptions were stored on the server.
I found out that a table named "sysproperties" was storing the descriptions. "Easy as pie" I thought to my self, "I'll just insert a new row for each of the two columns". But it didn't take long to find out that I wasn't allowed to insert new rows into the table. But since when have that stopped anyone?
After a quick Google search I found the solution:
RECONFIGURE WITH OVERRIDE
INSERT INT [sysproperties] VALUES ( @tableId, @columnId, 4, 'MS_Description', @description )
SP_CONFIGURE 'ALLOW UPDATES', 0
RECONFIGURE WITH OVERRIDE
@tableId
This variable represents the ID of the table who owns the columns in question. You can find the ID of the table by selecting it from "sysobjects" using the statement:
FROM [sysobjects]
WHERE [name] = '<your table name>' AND [xtype] = 'U'
@columnId
This variable represents the ID of the column in question. You can find the ID of the column by selecting it from "syscolumns" using the statement:
FROM [syscolumns]
WHERE [id] = @tableId
@description
This variable contains the description that you would like to store.
OK, so now the descriptions were in place, and although Enterprise Manager didn't show the descriptions they were still included when reverse engineering in Visio.
NOTE #1: In Microsoft SQL server 2005 you are able to change the description of a computed column.
NOTE #2: Although you might get the idea that I approve the existence of Visio, I can assure you it is not true! I only use Visio at work to see if the department would gain anything by switching to Visio in the future.
Saturday, September 29, 2007
Descriptions on MS SQL 2000 computed columns
SP_CONFIGURE 'ALLOW UPDATES', 1
SELECT *
SELECT *
Posted by
Robin Theilade
at
15:55
Labels: columns, descriptions, microsoft, server, sql, sysproperties
Subscribe to:
Post Comments (Atom)

0 comments:
Post a Comment