<?xml version="1.0" encoding="utf-8"?>
			
			<rss version="2.0">
			<channel>
			<title>ClickCulture Blog - SQL</title>
			<link>http://www.clickculture.com/blog/index.cfm</link>
			<description>ClickCulture Raleigh Web Design Blog</description>
			<language>en-us</language>
			<pubDate>Mon, 06 Sep 2010 16:18:23 -0400</pubDate>
			<lastBuildDate>Tue, 16 Oct 2007 18:02:00 -0400</lastBuildDate>
			<generator>BlogCFC</generator>
			<docs>http://blogs.law.harvard.edu/tech/rss</docs>
			<managingEditor>anson@clickculture.com</managingEditor>
			<webMaster>anson@clickculture.com</webMaster>
			
			
			
			
			
			<item>
				<title>List all user tables and columns in a database.</title>
				<link>http://www.clickculture.com/blog/index.cfm/2007/10/16/Finding-tables-or-columns</link>
				<description>
				
				List all columns in all tables in a SQL Server 2000 database.&lt;br&gt;
&lt;div class=&quot;code&quot;&gt;
SELECT SO.NAME, SC.NAME&lt;br&gt;
FROM SYSOBJECTS SO INNER JOIN SYSCOLUMNS SC &lt;br&gt;
    ON SO.ID = SC.ID&lt;br&gt;
WHERE SO.XTYPE = &apos;U&apos;&lt;br&gt;
ORDER BY SO.NAME, SC.NAME&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;br&gt;
List all columns in all tables in a SQL Server 2005 database.&lt;br&gt;
&lt;div class=&quot;code&quot;&gt;
SELECT SO.NAME, SC.NAME&lt;br&gt;
FROM SYS.OBJECTS SO INNER JOIN SYS.COLUMNS SC&lt;br&gt;
    ON SO.OBJECT_ID = SC.OBJECT_ID &lt;br&gt;
WHERE SO.TYPE = &apos;U&apos;&lt;br&gt;
ORDER BY SO.NAME, SC.NAME&lt;br&gt;
&lt;/div&gt;
				
				</description>
						
				
				<category>SQL</category>				
				
				<pubDate>Tue, 16 Oct 2007 18:02:00 -0400</pubDate>
				<guid>http://www.clickculture.com/blog/index.cfm/2007/10/16/Finding-tables-or-columns</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>Useful MSSQL Scripts</title>
				<link>http://www.clickculture.com/blog/index.cfm/2006/5/10/Useful-MSSQL-Scripts</link>
				<description>
				
				I use these SQL scripts quite a bit - they work on Microsoft SQL2000.&lt;br /&gt;&lt;br /&gt;These are mostly to modify users/owners - usually when moving databases from one box to another.&#xa0; Open up the Query Manager - paste these in (make sure you have the correct database selected and run them.&lt;br /&gt;&lt;br /&gt;This will change the owner on all tables back to the dbo:&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;&lt;br /&gt;DECLARE @old sysname, @new sysname, @sql varchar(1000)&lt;br /&gt; &lt;br /&gt; SELECT&lt;br /&gt; &#xa0; @old = &apos;username you want to remap&apos;&lt;br /&gt; &#xa0; , @new = &apos;dbo&apos;&lt;br /&gt; &#xa0; , @sql = &apos;&lt;br /&gt; &#xa0; IF EXISTS (SELECT NULL FROM INFORMATION_SCHEMA.TABLES&lt;br /&gt; &#xa0; WHERE&lt;br /&gt; &#xa0;&#xa0;&#xa0;&#xa0;&#xa0; QUOTENAME(TABLE_SCHEMA)+&apos;&apos;.&apos;&apos;+QUOTENAME(TABLE_NAME) = &apos;&apos;?&apos;&apos;&lt;br /&gt; &#xa0;&#xa0;&#xa0;&#xa0;&#xa0; AND TABLE_SCHEMA = &apos;&apos;&apos; + @old + &apos;&apos;&apos;&lt;br /&gt; &#xa0; )&lt;br /&gt; &#xa0; EXECUTE sp_changeobjectowner &apos;&apos;?&apos;&apos;, &apos;&apos;&apos; + @new + &apos;&apos;&apos;&apos;&lt;br /&gt; &lt;br /&gt; EXECUTE sp_MSforeachtable @sql&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt; Occasionally you will restore a database where the users may not be in sync between SQL Server and the database...&#xa0; Say you restore a database on your local development machine - the database has a user &quot;Joe Smith&quot; but there is no such user on your local machine. If you try to create that user and grant it permission to the database that already has a user by that name - SQL Server will throw an error.&#xa0; Run the following to find these &apos;orphaned&apos; users - and re-sync them.&lt;br /&gt;&lt;br /&gt;To get list of users:&lt;br /&gt;&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;&lt;br /&gt;SP_CHANGE_USERS_LOGIN REPORT&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;To sync users:&lt;br /&gt;&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;&lt;br /&gt;SP_CHANGE_USERS_LOGIN &apos;Update_One&apos;, &apos;joesmith&apos;,&apos;joesmith&apos;&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
				
				</description>
						
				
				<category>SQL</category>				
				
				<pubDate>Wed, 10 May 2006 17:39:00 -0400</pubDate>
				<guid>http://www.clickculture.com/blog/index.cfm/2006/5/10/Useful-MSSQL-Scripts</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>CSS Organization, ColdFusion Cookbook and Database Models</title>
				<link>http://www.clickculture.com/blog/index.cfm/2006/2/10/CSS-Organization-ColdFusion-Cookbook-and-Database-Models</link>
				<description>
				
				Short list these week - too busy to surf much!&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;http://erraticwisdom.com/2006/01/18/5-tips-for-organizing-your-css&quot;&gt;CSS Organization&lt;/a&gt; - some good tips&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;http://www.coldfusioncookbook.com/&quot;&gt;ColdFusion Cookbook&lt;/a&gt; Ray Camdens - super cool CF resource!&lt;br /&gt;&lt;br /&gt;A huge list of &lt;a href=&quot;http://www.databaseanswers.org/data_models/index.htm&quot;&gt;Database models&lt;/a&gt; - nicely laid out by use&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;http://www.gdoss.com/web_info/information_architecture_deliverables.php&quot;&gt;Information Architecture Deliverables&lt;/a&gt;&amp;nbsp; - good read&lt;br /&gt;
				
				</description>
						
				
				<category>SQL</category>				
				
				<category>Developer Links</category>				
				
				<category>CSS</category>				
				
				<pubDate>Fri, 10 Feb 2006 19:06:00 -0400</pubDate>
				<guid>http://www.clickculture.com/blog/index.cfm/2006/2/10/CSS-Organization-ColdFusion-Cookbook-and-Database-Models</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>Using Access To Cascade Delete A Parent/Child Relationship</title>
				<link>http://www.clickculture.com/blog/index.cfm/2006/1/12/Using-Access-To-Cascade-Delete-A-ParentChild-Relationship</link>
				<description>
				
				&lt;ul&gt;
    &lt;li class=&quot;level1&quot;&gt;
    &lt;div class=&quot;li&quot;&gt;Database: Access&lt;/div&gt;
    &lt;/li&gt;
    &lt;li class=&quot;level1&quot;&gt;
    &lt;div class=&quot;li&quot;&gt;Language: ColdFusion/&lt;acronym title=&quot;Structured Query Language&quot;&gt;SQL&lt;/acronym&gt;&lt;/div&gt;
    &lt;/li&gt;
&lt;/ul&gt;
For a recent project I built a links application which had a parent/child relationship via one table:
&lt;p&gt;CatID &amp;gt; ParentID. &lt;/p&gt;
&lt;p&gt;The problem was if you deleted a link category - you would need to also delete any categories under that category (child) as well as any links associated with those categories. &lt;/p&gt;
&lt;p&gt;Another negative was there was no way to know the depth of the parent/child relationship so it would take a complex loop to delete everything. &lt;/p&gt;
&lt;p&gt;I remember reading something about using the database to do a &amp;lsquo;cascading&amp;rsquo; delete so I dug into this and came up with the following solution which lets the database do the heavy work: &lt;/p&gt;
&lt;p&gt;First I setup my table as such (notice tblLinkCategory relates to itself - tblLinkCategory_1) &lt;/p&gt;
&lt;br /&gt;&lt;img alt=&quot;Screenshot&quot; src=&quot;http://www.clickculture.com/blog/images/sql_1.gif&quot; /&gt;
&lt;p&gt;&lt;a class=&quot;media&quot; onkeypress=&quot;return svchk()&quot; title=&quot;relationship.gif&quot; onclick=&quot;return svchk()&quot; href=&quot;http://www.thecrumb.com/wiki/lib/exe/fetch.php?cache=cache&amp;amp;media=relationship.gif&quot;&gt;&lt;br /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The key to initially setting this relationship is the first record in tblLinkCategory MUST have a NULL value in parentID - since it&amp;rsquo;s the first record there is nothing to relate to - so a NULL must be used. &lt;/p&gt;
&lt;p&gt;Next we just need to setup the cascade - right click on the relationship line between each table to get the properties: &lt;/p&gt;
&lt;img alt=&quot;Screenshot&quot; src=&quot;http://www.clickculture.com/blog/images/sql_2.gif&quot; /&gt;
&lt;p&gt;&lt;span class=&quot;media&quot;&gt;&lt;/span&gt;&lt;a class=&quot;media&quot; onkeypress=&quot;return svchk()&quot; title=&quot;relationship1.gif&quot; onclick=&quot;return svchk()&quot; href=&quot;http://www.thecrumb.com/wiki/lib/exe/fetch.php?cache=cache&amp;amp;media=relationship1.gif&quot;&gt;&lt;br /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Select &amp;ldquo;Enforce Referential Integrity&amp;rdquo; and &amp;ldquo;Cascade Delete Related Records&amp;rdquo; &lt;/p&gt;
&lt;p&gt;Once you do this you can no longer delete rows with Access open (you will get a &amp;lsquo;table locked&amp;rsquo; error) but it works fine via a delete query from ColdFusion. &lt;/p&gt;
&lt;p&gt;Now by doing a single delete from the tblLinkCategory table: &lt;/p&gt;
&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;delete&lt;br /&gt;from tblLink&lt;br /&gt;where id = &amp;lt;cfqueryparam value=&amp;quot;#attributes.id#&amp;quot; cfsqltype=&amp;quot;CF_SQL_INTEGER&amp;quot; maxlength=&amp;quot;5&amp;quot;&amp;gt;&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;p&gt;It will delete the category, any sub-categories and any related links to those categories. &lt;/p&gt;
				
				</description>
						
				
				<category>SQL</category>				
				
				<category>ColdFusion</category>				
				
				<pubDate>Thu, 12 Jan 2006 18:05:00 -0400</pubDate>
				<guid>http://www.clickculture.com/blog/index.cfm/2006/1/12/Using-Access-To-Cascade-Delete-A-ParentChild-Relationship</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>Performance Tuning CF, OpenCD 3.1, SQLServer Tips</title>
				<link>http://www.clickculture.com/blog/index.cfm/2005/11/23/Performance-Tuning-CF-OpenCD-31-SQLServer-Tips</link>
				<description>
				
				&lt;a href=&quot;http://www.sitepoint.com/article/bulletproof-web-design-contract&quot;&gt;Bulletproof Web Design Contracts&lt;/a&gt;&lt;br /&gt; &lt;br /&gt; How sites (&lt;a href=&quot;http://colorfilter.wickline.org/?a=1;r=www.google.com/search%3Fsourceid%3Dnavclient%26ie%3DUTF-8%26rls%3DGGLD%2CGGLD%3A2004-29%2CGGLD%3Aen%26q%3Dcolor%2Bblindness;l=0;j=1;u=www.clickculture.com;t=p&quot;&gt;our site in particular&lt;/a&gt;) look to color blind people&lt;br /&gt; &lt;br /&gt; &amp;quot;&lt;a href=&quot;http://www.sqlteam.com/item.asp?ItemID=23162&quot;&gt;What I Wish Developers Knew About SQL Server&lt;/a&gt;&amp;quot; Great presentation&lt;br /&gt; &lt;br /&gt; YACSG (Yet another &lt;a href=&quot;http://www.steeldolphin.com/color_scheme.html&quot;&gt;color scheme generator&lt;/a&gt;)&lt;br /&gt; &lt;br /&gt; The &lt;a href=&quot;http://theopencd.org/&quot;&gt;OpenCD&lt;/a&gt;&amp;nbsp; v3.1 is out - great open source software for Windows!&lt;br /&gt; &lt;br /&gt; &lt;a href=&quot;http://www.bullzip.com/products/msa2mys/info.php&quot;&gt;Access to MySQL Converter&lt;/a&gt;&lt;br /&gt; &lt;br /&gt; Great &lt;a href=&quot;http://wilshipley.com/blog/2005/02/free-programming-tips-are-worth-every.html&quot;&gt;General Programming Tips&lt;/a&gt;&lt;br /&gt; &lt;br /&gt; &lt;a href=&quot;http://www.bpurcell.org/blog/index.cfm?mode=entry&amp;amp;entry=1068&quot;&gt;Perfomance Testing ColdFusion&lt;/a&gt;
				
				</description>
						
				
				<category>SQL</category>				
				
				<category>Developer Links</category>				
				
				<category>ColdFusion</category>				
				
				<pubDate>Wed, 23 Nov 2005 17:17:00 -0400</pubDate>
				<guid>http://www.clickculture.com/blog/index.cfm/2005/11/23/Performance-Tuning-CF-OpenCD-31-SQLServer-Tips</guid>
				
			</item>
			
		 	
			</channel></rss>