<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>SQL</title>
        <link>http://darkside.co.za/category/6.aspx</link>
        <description>SQL</description>
        <language>en-ZA</language>
        <copyright>Ryan Schreiber</copyright>
        <generator>Subtext Version 2.1.0.5</generator>
        <item>
            <title>T4 Text Template for Castle ActiveRecord</title>
            <link>http://www.darkside.co.za/archive/2010/08/18/t4-text-template-castle-activerecord.aspx</link>
            <description>&lt;p&gt;I was busy with a(nother) comparison of Castle ActiveRecord and the Microsoft offerings that have shipped with VS2010 just to make sure that I wasn’t missing out on anything. I ended up fiddling with EDMX files, and then custom generation, which then led me to downloading the ADO.Net POCO T4 generation templates and checking out what was in the files. &lt;/p&gt;
&lt;p&gt;I have to admit: when I saw what was in it, I got quite giddy with excitement, followed shortly by feeling like a tool. I can’t believe I’ve missed out on this excellent piece of functionality that has been around for ages. &lt;/p&gt;
&lt;p&gt;I decided to tackle making a template that generated output that matched what is generated by &lt;a target="_blank" href="http://generatorstudio.codeplex.com/"&gt;Generator Studio&lt;/a&gt;, which is an open source project I started with &lt;a target="_blank" href="http://www.fryhard.com/"&gt;FryHard&lt;/a&gt; a few years back, primarily to generate my ActiveRecord classes from my database model. I based my template on the ADO.Net POCO template from Microsoft and used it as my guideline.&lt;/p&gt;
&lt;p&gt;Explaining the code in the TT file is a little out of the scope of this article, but it is &lt;a title="Darkside Castle ActiveRecord CodeGen Template" target="_blank" href="http://www.darkside.co.za/files/DarksideCastleActiveRecordTemplate.zip"&gt;available here for download&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You can paste the zip file in&lt;/p&gt;
&lt;div class="Code"&gt;%userprofile%\Documents\Visual Studio 2010\Templates\ItemTemplates\Visual C#\ &lt;/div&gt;
&lt;p&gt;and then open the Visual Studio Command Prompt (as Administrator) and run:&lt;/p&gt;
&lt;div class="Code"&gt;devenv /installvstemplates &lt;/div&gt;
&lt;p&gt;The command above installs the new templates for Visual Studio.&lt;/p&gt;
&lt;p&gt;The quickest way to use it in much the same way as a generator is as follows:&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;Create a new class library or windows app project. &lt;/li&gt;
    &lt;li&gt;Add a reference to Castle.ActiveRecord.&lt;/li&gt;
    &lt;li&gt;Add an ADO.NET Entity Data Model to your project. &lt;/li&gt;
    &lt;li&gt;Choose the “Generate from Database” option in the wizard&lt;/li&gt;
    &lt;li&gt;Run through the rest of the wizard adding the tables you’d like to generate ActiveRecord classes from.&lt;/li&gt;
    &lt;li&gt;Open the entity model in the IDE, and change the “Code Generation Strategy” property in the properties tab to “None”. This remove all code from the designer class attached to the EDMX file.&lt;/li&gt;
    &lt;li&gt;Add a new “Castle ActiveRecord Basic Template” item to your project. This is the template contained in the download above. &lt;/li&gt;
    &lt;li&gt;Once the template has been added, you can look at the files generated by it, and there should be 1 each for each table in your database, as well as an additional file that has the same name as the template (except with a .CS extension), that has no functionality in it. This is created by the template (as it was in the original from MS), and I’ve left it there because I’ll most likely use for custom features/base classes as I build on the template.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;You should now be able to use the ActiveRecord classes generated as you normally would. &lt;/p&gt;
&lt;p&gt;If you make changes to your model in the EDMX designer, you can simply right-click on the template file in the solution and select the “Run Custom Tool” to regenerate your classes.&lt;/p&gt;&lt;img src="http://www.darkside.co.za/aggbug/116.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Schreiber</dc:creator>
            <guid>http://www.darkside.co.za/archive/2010/08/18/t4-text-template-castle-activerecord.aspx</guid>
            <pubDate>Wed, 18 Aug 2010 09:32:35 GMT</pubDate>
            <wfw:comment>http://www.darkside.co.za/comments/116.aspx</wfw:comment>
            <comments>http://www.darkside.co.za/archive/2010/08/18/t4-text-template-castle-activerecord.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://www.darkside.co.za/comments/commentRss/116.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Table designer in SQL 2008 Management Studio prevents saving table changes</title>
            <link>http://www.darkside.co.za/archive/2009/10/08/table-designer-sql-2008-saving-tables.aspx</link>
            <description>&lt;p&gt;If you get an error message along the lines of “Saving changes is not permitted. The changes you have made…”, it’s actually an option that can be toggled. Go to Tools-&amp;gt;Options-&amp;gt;Designers-&amp;gt;Table and Database Designers and toggle the “Prevent saving changes..” option.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.darkside.co.za/files/images/TabledesignerinSQL2008ManagementStudiopr_A0A1/image.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.darkside.co.za/files/images/TabledesignerinSQL2008ManagementStudiopr_A0A1/image_thumb.png" width="595" height="344" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://www.darkside.co.za/aggbug/107.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Schreiber</dc:creator>
            <guid>http://www.darkside.co.za/archive/2009/10/08/table-designer-sql-2008-saving-tables.aspx</guid>
            <pubDate>Thu, 08 Oct 2009 09:25:09 GMT</pubDate>
            <comments>http://www.darkside.co.za/archive/2009/10/08/table-designer-sql-2008-saving-tables.aspx#feedback</comments>
            <wfw:commentRss>http://www.darkside.co.za/comments/commentRss/107.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Using SQL triggers for audit trails</title>
            <link>http://www.darkside.co.za/archive/2009/03/13/sql-triggers-audit-trails.aspx</link>
            <description>&lt;p&gt;In my &lt;a target="_blank" href="http://www.darkside.co.za/archive/2009/03/12/castle-activerecord-class-hierarchy.aspx"&gt;previous post&lt;/a&gt; I looked at using Castle ActiveRecord and class hierarchies &amp;amp; inheritance to automate some tasks related to implementing audit trails in your application. The foundation was laid to ensure some required information, namely the current user and date and time of editing data, was seamlessly integrated into the domain logic. In this post I'd like to show the next step in this process - that of implementing triggers and the tables required to store this audit trail information.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Download&lt;/strong&gt; - &lt;a target="_blank" href="http://www.darkside.co.za/files/Darkside.AuditTrail.Part2.zip"&gt;Darkside.AuditTrail.Part2.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;To start off, lets take a look at the database structure created by ActiveRecord from the sample in the previous post.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://www.darkside.co.za/files/images/sqltrigger01.jpg" /&gt; &lt;/p&gt;
&lt;p&gt;You'll notice that the fields in the base class &lt;strong&gt;ObjectBase&amp;lt;T&amp;gt;&lt;/strong&gt; are included in every table. Using the &lt;a target="_blank" href="http://www.codeplex.com/generatorstudio"&gt;Generator Studio&lt;/a&gt; application (shameless plug), I pointed to this database and these three tables, and selected two of the templates included with the default installation, &lt;strong&gt;AuditTablesTemplate_Guid&lt;/strong&gt; and &lt;strong&gt;AuditTriggersTemplate_Guid&lt;/strong&gt;. After generating the files - there are 6 scripts generated altogether, 3 for the audit tables, and 3 for the triggers - I ran the scripts in SQL. The resulting tables look almost exactly the same as the tables above, barring 1 extra field which is added to be a surrogate primary key. &lt;/p&gt;
&lt;p&gt;The scripts for the triggers look like something like this:&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div class="CodeCollapse"&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;IF &lt;/span&gt; &lt;span style="COLOR: blue"&gt;EXISTS &lt;/span&gt;(&lt;span style="COLOR: blue"&gt;SELECT &lt;/span&gt;* &lt;span style="COLOR: blue"&gt;FROM &lt;/span&gt;sys.triggers &lt;span style="COLOR: blue"&gt;WHERE object_id &lt;/span&gt;= &lt;span style="COLOR: blue"&gt;OBJECT_ID&lt;/span&gt;(N&lt;span style="COLOR: #a31515"&gt;'[dbo].[tr_Customer_Audit]'&lt;/span&gt;))&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;DROP TRIGGER &lt;/span&gt;[dbo].[tr_Customer_Audit]&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;SET &lt;/span&gt;ANSI_NULLS &lt;span style="COLOR: blue"&gt;ON&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;GO&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;SET QUOTED_IDENTIFIER ON&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;GO&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;CREATE TRIGGER &lt;/span&gt;[dbo].[tr_Customer_Audit] &lt;span style="COLOR: blue"&gt;ON &lt;/span&gt;[dbo].[Customer] &lt;span style="COLOR: blue"&gt;FOR INSERT&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;UPDATE&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;AS&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;IF EXISTS &lt;/span&gt;(&lt;span style="COLOR: blue"&gt;SELECT &lt;/span&gt;* &lt;span style="COLOR: blue"&gt;FROM &lt;/span&gt;inserted)&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;BEGIN&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;INSERT INTO &lt;/span&gt;&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;    Customer_Audit (&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;    Customer_Audit_Id,&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;    [CustomerId],&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;    [IsDeleted],&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;    [EditedById],&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;    [EditedDateTime],&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;    [FirstName],&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;    [LastName],&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;    [Age]&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;    )&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="COLOR: blue"&gt;SELECT &lt;/span&gt;&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="COLOR: blue"&gt;newid&lt;/span&gt;(),&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;    inserted.[CustomerId],&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;    inserted.[IsDeleted],&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;    inserted.[EditedById],&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;    inserted.[EditedDateTime],&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;    inserted.[FirstName],&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;    inserted.[LastName],&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;    inserted.[Age]&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="COLOR: blue"&gt;FROM &lt;/span&gt;&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;        inserted &lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;END&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Very simply, the triggers select information from the &lt;strong&gt;inserted&lt;/strong&gt; table and insert it into the audit table. Because the code updated the EditedById and EditedDateTime fields, the audit information always has the correct data in the fields. &lt;/p&gt;
&lt;p&gt;The resulting data in the xxxx_Audit tables will be a line-by-line history of the inserts and updates made to the corresponding tables. &lt;/p&gt;&lt;img src="http://www.darkside.co.za/aggbug/97.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Schreiber</dc:creator>
            <guid>http://www.darkside.co.za/archive/2009/03/13/sql-triggers-audit-trails.aspx</guid>
            <pubDate>Fri, 13 Mar 2009 19:31:53 GMT</pubDate>
            <comments>http://www.darkside.co.za/archive/2009/03/13/sql-triggers-audit-trails.aspx#feedback</comments>
            <wfw:commentRss>http://www.darkside.co.za/comments/commentRss/97.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Killing all processes on a database</title>
            <link>http://www.darkside.co.za/archive/2008/08/08/killing-all-processes-on-a-database.aspx</link>
            <description>&lt;p&gt;If you're using a database in any of your unit tests (or dropping/recreating) on a regular basis, you'll inevitably get an error alongs the lines of "Cannot drop database 'Test' because it's in use".&lt;/p&gt;
&lt;p&gt;I've created this stored proc on my master DB which allows me to quickly kill all processes on a database. I originally got the idea from a post on the net some time back, but I honestly can't remeber who from. If it's yours, drop me a mail and I'll attribute the idea accordingly :)&lt;/p&gt;
&lt;p&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;CAUTION: There is no "Are you sure?" message. Processes are killed. Quickly.&lt;/strong&gt;&lt;/font&gt; &lt;/p&gt;
&lt;div class="CodeCollapse"&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;USE &lt;/span&gt;MASTER&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;GO&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;IF &lt;/span&gt; &lt;span style="COLOR: blue"&gt;EXISTS &lt;/span&gt;(&lt;span style="COLOR: blue"&gt;SELECT &lt;/span&gt;* &lt;span style="COLOR: blue"&gt;FROM &lt;/span&gt;sys.objects &lt;span style="COLOR: blue"&gt;WHERE object_id &lt;/span&gt;= &lt;span style="COLOR: blue"&gt;OBJECT_ID&lt;/span&gt;(N&lt;span style="COLOR: #a31515"&gt;'[dbo].[sp_KillDatabaseProcesses]'&lt;/span&gt;) &lt;span style="COLOR: blue"&gt;AND &lt;/span&gt;type &lt;span style="COLOR: blue"&gt;in &lt;/span&gt;(N&lt;span style="COLOR: #a31515"&gt;'P'&lt;/span&gt;, N&lt;span style="COLOR: #a31515"&gt;'PC'&lt;/span&gt;))&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;DROP PROCEDURE &lt;/span&gt;[dbo].[sp_KillDatabaseProcesses]&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;GO&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;CREATE PROCEDURE &lt;/span&gt;dbo.sp_KillDatabaseProcesses&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;( @databaseName &lt;span style="COLOR: blue"&gt;varchar&lt;/span&gt;(100))&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;AS&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;DECLARE &lt;/span&gt;@databaseId &lt;span style="COLOR: blue"&gt;int&lt;/span&gt;,&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;        @sysProcessId &lt;span style="COLOR: blue"&gt;int&lt;/span&gt;,&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;        @cmd &lt;span style="COLOR: blue"&gt;varchar&lt;/span&gt;(1000)&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;EXEC &lt;/span&gt;(&lt;span style="COLOR: #a31515"&gt;'USE MASTER'&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;SELECT &lt;/span&gt;@databaseId = dbid &lt;span style="COLOR: blue"&gt;FROM &lt;/span&gt;master..sysdatabases&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;  &lt;span style="COLOR: blue"&gt;WHERE &lt;/span&gt;[name] = @databaseName&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;DECLARE &lt;/span&gt;sysProcessIdCursor &lt;span style="COLOR: blue"&gt;CURSOR FOR&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;   &lt;span style="COLOR: blue"&gt;SELECT &lt;/span&gt;spid &lt;span style="COLOR: blue"&gt;FROM &lt;/span&gt;[master]..[sysprocesses] &lt;span style="COLOR: blue"&gt;WHERE &lt;/span&gt;[dbid] = @databaseId&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;OPEN &lt;/span&gt;sysProcessIdCursor&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;FETCH NEXT FROM &lt;/span&gt;sysProcessIdCursor &lt;span style="COLOR: blue"&gt;INTO &lt;/span&gt;@sysProcessId&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;WHILE &lt;/span&gt;@@fetch_status = 0&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;  &lt;span style="COLOR: blue"&gt;BEGIN&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="COLOR: blue"&gt;SET &lt;/span&gt;@cmd = &lt;span style="COLOR: #a31515"&gt;'KILL '&lt;/span&gt;+ &lt;span style="COLOR: blue"&gt;convert&lt;/span&gt;(nvarchar(30),@sysProcessId)&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="COLOR: blue"&gt;PRINT &lt;/span&gt;@cmd&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="COLOR: blue"&gt;EXEC&lt;/span&gt;(@cmd)&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="COLOR: blue"&gt;FETCH NEXT FROM &lt;/span&gt;sysProcessIdCursor &lt;span style="COLOR: blue"&gt;INTO &lt;/span&gt;@sysProcessId&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;END&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;DEALLOCATE &lt;/span&gt;sysProcessIdCursor            &lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;GO&lt;/pre&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;img src="http://www.darkside.co.za/aggbug/43.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Darksider</dc:creator>
            <guid>http://www.darkside.co.za/archive/2008/08/08/killing-all-processes-on-a-database.aspx</guid>
            <pubDate>Fri, 08 Aug 2008 09:56:31 GMT</pubDate>
            <comments>http://www.darkside.co.za/archive/2008/08/08/killing-all-processes-on-a-database.aspx#feedback</comments>
            <wfw:commentRss>http://www.darkside.co.za/comments/commentRss/43.aspx</wfw:commentRss>
        </item>
        <item>
            <title>List of SQL Types</title>
            <link>http://www.darkside.co.za/archive/2007/09/06/list-of-sql-types.aspx</link>
            <description>&lt;p&gt;I'm not sure if this has much practical application, but I thought it may be useful for information's sake. The following script will return a list of data type id's with the SQL data name representing the type. I used the &lt;span style="COLOR: fuchsia"&gt;&lt;font face="Courier New"&gt;type_name&lt;/font&gt;&lt;/span&gt; function when querying the syscolumns tables and needed a plain english column type.&lt;/p&gt;
&lt;div&gt;&lt;font face="Courier New"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;
&lt;div style="BORDER-RIGHT: 1px solid; BORDER-TOP: 1px solid; PADDING-LEFT: 3px; FONT-SIZE: 9pt; BACKGROUND: #ffff99; BORDER-LEFT: 1px solid; COLOR: black; BORDER-BOTTOM: 1px solid; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;DECLARE &lt;/span&gt;@typeid &lt;span style="COLOR: blue"&gt;int&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;DECLARE &lt;/span&gt;@typename &lt;span style="COLOR: blue"&gt;varchar&lt;/span&gt;(50)&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;SET &lt;/span&gt;@typeid =0&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;WHILE &lt;/span&gt;(@typeid &amp;lt; 500)&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;BEGIN&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;      &lt;span style="COLOR: blue"&gt;SELECT &lt;/span&gt;@typename = type_name (@typeid )&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;      &lt;span style="COLOR: blue"&gt;IF &lt;/span&gt;(@typename &lt;span style="COLOR: blue"&gt;IS NOT NULL&lt;/span&gt;)&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: blue"&gt;PRINT convert&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;varchar&lt;/span&gt;(5), @typeid ) + &lt;span style="COLOR: #a31515"&gt;' ' &lt;/span&gt;+ @typename  &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;SET &lt;/span&gt;@typeid = @typeid + 1&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;END&lt;/span&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;This script will also return the names and id's of all a db's user defined types, if any have been created.&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;The result set looks something like this&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="1"&gt;&lt;font face="Courier New"&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;0, void type&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;1, table&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;31, void type&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;34, image&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;35, text&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;36, uniqueidentifier&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;48, tinyint&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;52, smallint&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;56, int&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;58, smalldatetime&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;59, real&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;60, money&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;61, datetime&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;62, float&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;98, sql_variant&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;99, ntext&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;104, bit&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;106, decimal&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;108, numeric&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;122, smallmoney&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;127, bigint&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;165, varbinary&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;167, varchar&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;173, binary&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;175, char&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;189, timestamp&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;231, nvarchar&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;239, nchar&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;241, xml&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;242, xml&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;250, cursor&lt;/span&gt;&lt;/div&gt;
&lt;div style="LINE-HEIGHT: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;256, sysname&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0cm 0cm 10pt"&gt;&lt;span style="FONT-SIZE: 8pt; LINE-HEIGHT: 115%"&gt;257, StringGuid (A UDT I added for the demo)&lt;/span&gt;&lt;/div&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;img src="http://www.darkside.co.za/aggbug/15.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Darksider</dc:creator>
            <guid>http://www.darkside.co.za/archive/2007/09/06/list-of-sql-types.aspx</guid>
            <pubDate>Thu, 06 Sep 2007 17:20:34 GMT</pubDate>
            <comments>http://www.darkside.co.za/archive/2007/09/06/list-of-sql-types.aspx#feedback</comments>
            <wfw:commentRss>http://www.darkside.co.za/comments/commentRss/15.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>