<?xml version="1.0" encoding="utf-8"?>
			
			<rss version="2.0">
			<channel>
			<title>Rob Gonda&apos;s Blog - SQL</title>
			<link>http://www.robgonda.com/blog/index.cfm</link>
			<description>Rob Gonda&apos;s Interactive Strategy</description>
			<language>en-us</language>
			<pubDate>Mon, 06 Sep 2010 22:16:54 -0400</pubDate>
			<lastBuildDate>Mon, 19 Feb 2007 21:27:00 -0400</lastBuildDate>
			<generator>BlogCFC</generator>
			<docs>http://blogs.law.harvard.edu/tech/rss</docs>
			<managingEditor>rob@robgonda.com</managingEditor>
			<webMaster>rob@robgonda.com</webMaster>
			
			
			
			
			
			<item>
				<title>SQL Server 2005 Service Pack 2</title>
				<link>http://www.robgonda.com/blog/index.cfm/2007/2/19/SQL-Server-2005-Service-Pack-2</link>
				<description>
				
				Microsoft released &lt;a href=&quot;http://support.microsoft.com/kb/913089&quot; target=&quot;_blank&quot;&gt;service pack 2&lt;/a&gt; today for SQL Server 2005. As usual, this fixes a massive amount of bugs. In addition, customers running Vista must update their databases to be fully supported.. The update allows &amp;quot;unlimited virtual instances&amp;quot; to run on &amp;quot;fully licensed&amp;quot; SQL Server 2005 Enterprise Edition.&lt;br /&gt;There are many other perks included with the update, which I shall try shortly.
				
				</description>
						
				
				<category>SQL</category>				
				
				<pubDate>Mon, 19 Feb 2007 21:27:00 -0400</pubDate>
				<guid>http://www.robgonda.com/blog/index.cfm/2007/2/19/SQL-Server-2005-Service-Pack-2</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>Vertica: new RDMS claims to be 100x faster</title>
				<link>http://www.robgonda.com/blog/index.cfm/2007/2/15/Vertica-new-RDMS-claims-to-be-100x-faster</link>
				<description>
				
				&lt;p&gt;&amp;quot;&lt;a href=&quot;http://www.vertica.com/vertica_database&quot; target=&quot;_blank&quot;&gt;Vertica&lt;/a&gt; describes its offering as a &amp;ldquo;grid-enabled, column-oriented relational database management system&amp;rdquo; that runs on industry standard hardware. It is designed to handle data warehousing, business intelligence, fraud detection and other applications, even in environments with hundreds of terabytes of data. The company says its technology can be used to execute queries 100 times faster than traditional row-oriented relational database management systems&amp;quot; &lt;/p&gt;
Vertica&apos;s product is in beta testing and the company is &lt;a href=&quot;http://www.vertica.com/earlyadopter&quot; xmlns:w=&quot;urn:www.microsoft.com/word&quot; xmlns:st1=&quot;urn:www.microsoft.com/smarttags&quot; xmlns:o=&quot;urn:www.microsoft.com/office&quot; target=&quot;_blank&quot;&gt;inviting those who want to be early adopters&lt;/a&gt; to give it a whirl. [&lt;a href=&quot;http://www.networkworld.com/news/2007/021407-vertica-oracle.html&quot; target=&quot;_blank&quot;&gt;full story&lt;/a&gt;]
				
				</description>
						
				
				<category>SQL</category>				
				
				<pubDate>Thu, 15 Feb 2007 00:22:00 -0400</pubDate>
				<guid>http://www.robgonda.com/blog/index.cfm/2007/2/15/Vertica-new-RDMS-claims-to-be-100x-faster</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>Microsoft SQL Server Database Publishing Wizard</title>
				<link>http://www.robgonda.com/blog/index.cfm/2007/2/12/Microsoft-SQL-Server-Database-Publishing-Wizard</link>
				<description>
				
				The &lt;a href=&quot;http://www.microsoft.com/downloads/details.aspx?FamilyID=29b4ffd8-ac3a-4481-b352-9b185619a901&amp;amp;DisplayLang=en&quot; target=&quot;_blank&quot;&gt;SQL Server Database Publishing Wizard&lt;/a&gt; enables the deployment of SQL Server databases into a hosted environment on either a SQL Server 2000 or 2005 server. It generates a single SQL script file which can be used to recreate a database (both schema and data) in a shared hosting environment where the only connectivity to a server is through a web-based control panel with a script execution window. If supported by the hosting service provider, the Database Publishing Wizard can also directly upload databases to servers located at the shared hosting provider.
				
				</description>
						
				
				<category>SQL</category>				
				
				<pubDate>Mon, 12 Feb 2007 22:58:00 -0400</pubDate>
				<guid>http://www.robgonda.com/blog/index.cfm/2007/2/12/Microsoft-SQL-Server-Database-Publishing-Wizard</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>Leverage SQL Session at the South Florida CFUG</title>
				<link>http://www.robgonda.com/blog/index.cfm/2007/2/7/Leverage-SQL-Session-at-the-South-Florida-CFUG</link>
				<description>
				
				I will be speaking this coming February 22nd at the &lt;a href=&quot;http://www.cfug-sfl.org/&quot; target=&quot;_blank&quot;&gt;South Florida CFUG&lt;/a&gt;. For this month I chose a topic that will benefit you regardless of your programming language of preference, and should hopefully allow to you take back something that you can apply immediately. &lt;br /&gt;&lt;br /&gt;Topic:&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Leverage the power of SQL&lt;br /&gt;Description: &amp;nbsp;&amp;nbsp;&amp;nbsp; Many developers don&apos;t realize the power of SQL to perform data related tasks and computations. Learn how to utilize triggers, stored procedures, constraints, and user-defined-functions to their full potential, and see the huge impact this could have in your organization or day-to-day coding.&lt;br /&gt;&lt;br /&gt;Tell your friends.
				
				</description>
						
				
				<category>SQL</category>				
				
				<category>Coldfusion</category>				
				
				<pubDate>Wed, 07 Feb 2007 01:02:00 -0400</pubDate>
				<guid>http://www.robgonda.com/blog/index.cfm/2007/2/7/Leverage-SQL-Session-at-the-South-Florida-CFUG</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>ColdFusion Vs. SQL UUID</title>
				<link>http://www.robgonda.com/blog/index.cfm/2007/2/4/ColdFusion-Vs-SQL-UUID</link>
				<description>
				
				A few days ago I &lt;a href=&quot;/blog/index.cfm/2007/1/27/Database-Data-Integrity-The-Basics&quot;&gt;blogged&lt;/a&gt; about database level data integrity and promised a follow up concentrating in uuids. &lt;br /&gt;&lt;br /&gt;A UUID stands for Universally Unique Identifier. The intent of UUIDs is to enable distributed systems to uniquely identify information without significant central coordination. Thus, anyone can create a UUID and use it to identify something with reasonable confidence that the identifier will never be unintentionally used by anyone for anything else. Information labelled with UUIDs can therefore be later combined into a single database without needing to resolve name conflicts. The most widespread use of this standard is in Microsoft&apos;s Globally Unique Identifiers (GUIDs) which implement this standard (source: wikipedia).&lt;br /&gt;&lt;br /&gt;A UUID is essentially a 16-byte (128-bit) number. In its canonical form a UUID may look like this:&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx (8-4-4-4-12)&lt;br /&gt;&lt;br /&gt;However, for some reason ColdFusion&apos;s UUID looks like&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxx (8-4-4-16) &lt;br /&gt;&lt;br /&gt;Microsoft SQL has a native datatype called uniqueidentifier, which represents the 36-characters GUID. Many ColdFusion developers choose not to use the GUID because it cannot be implicitly validated by ColdFusion and it cannot be seamlessly moved to a different database like mysql, postgre, oracle. &lt;br /&gt;&lt;br /&gt;The most widely adopted solution is to use a 35-character primary key and insert a ColdFusion UUID, nonetheless, how do you validate a proper uuid at the database level? What if you want the database to generate the primary key? If the key gets altered, it will fail ColdFusions implicit UUID datatype validation.&lt;br /&gt;&lt;br /&gt;The solution is to add some constraints in the database level.&lt;br /&gt;&lt;br /&gt;Is it really simple to generate a UUID, since all it takes it just to remove the 4th hyphen.&lt;br /&gt;&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;CREATE FUNCTION dbo.newUUID(@GUID varchar(36))&lt;br /&gt;RETURNS varchar(35)&lt;br /&gt;AS&lt;br /&gt;BEGIN&lt;br /&gt;&amp;nbsp;RETURN left(@GUID, 23) + right(@GUID,12)&lt;br /&gt;END&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;Note that due to limitations and not being able to invoke a newID() function inside a user defined function, we need to pass the GUID. Now, that said, we can add a default value to our primary keys and let SQL Server generate them for us:&lt;br /&gt;&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;Default Value: dbo.newUUID(newid())&lt;/div&gt;
&lt;br /&gt; &lt;br /&gt; To validate a proper UUID is a little more complicated, since SQL has no native isUUID or isGUID function. I chose to use a regular expression, but guess what? SQL Server 2000 has no regular expression capabilities.&lt;br /&gt;&lt;br /&gt;So step one is to create a regular expression evaluator function&lt;br /&gt;&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;CREATE FUNCTION dbo.find_regular_expression&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; @source varchar(5000),&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; @regexp varchar(1000),&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; @ignorecase bit = 0&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;br /&gt;RETURNS bit&lt;br /&gt;AS&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; BEGIN&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; DECLARE @hr integer&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; DECLARE @objRegExp integer&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; DECLARE @objMatches integer&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; DECLARE @objMatch integer&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; DECLARE @count integer&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; DECLARE @results bit&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC @hr = sp_OACreate &apos;VBScript.RegExp&apos;, @objRegExp OUTPUT&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; IF @hr &amp;lt;&amp;gt; 0 BEGIN&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; SET @results = 0&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; RETURN @results&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; END&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC @hr = sp_OASetProperty @objRegExp, &apos;Pattern&apos;, @regexp&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; IF @hr &amp;lt;&amp;gt; 0 BEGIN&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; SET @results = 0&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; RETURN @results&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; END&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC @hr = sp_OASetProperty @objRegExp, &apos;Global&apos;, false&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; IF @hr &amp;lt;&amp;gt; 0 BEGIN&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; SET @results = 0&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; RETURN @results&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; END&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC @hr = sp_OASetProperty @objRegExp, &apos;IgnoreCase&apos;, @ignorecase&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; IF @hr &amp;lt;&amp;gt; 0 BEGIN&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; SET @results = 0&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; RETURN @results&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; END&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC @hr = sp_OAMethod @objRegExp, &apos;Test&apos;, @results OUTPUT, @source&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; IF @hr &amp;lt;&amp;gt; 0 BEGIN&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; SET @results = 0&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; RETURN @results&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; END&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC @hr = sp_OADestroy @objRegExp&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; IF @hr &amp;lt;&amp;gt; 0 BEGIN&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; SET @results = 0&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; RETURN @results&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; END&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; RETURN @results&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; END&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;Now that we have this, all we need is the UUID regEx pattern and call this function. &lt;br /&gt;&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;CREATE FUNCTION dbo.isUUID (@uuid varchar(35))&amp;nbsp; &lt;br /&gt;RETURNS bit AS&amp;nbsp; &lt;br /&gt;BEGIN &lt;br /&gt;&lt;br /&gt;DECLARE @uuidRegex varchar(50)&lt;br /&gt;SET @uuidRegex = &apos;^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{16}$&apos;&lt;br /&gt;&lt;br /&gt;RETURN dbo.find_regular_expression(@uuid,@uuidRegex ,0)&lt;br /&gt;&lt;br /&gt;END&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;Alright! now we have a isUUID function, which you can easily invoke from everywhere... open a sql script and execute &lt;br /&gt;&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;SELECT [dbo].[isUUID](&apos;D929E4FB-537C-495F-BB3F31B8E42C0FBB&apos;) &lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;Now that we tested it and know how it works, all we need is to add a constraint to your primary key:&lt;br /&gt;&lt;br /&gt;Open your table in design mode, click constraints, new, and add this line:&lt;br /&gt;&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;([dbo].[isUUID]([ID]) = 1)&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;where ID is the name of the primary key.&lt;br /&gt;&lt;br /&gt;So you learned how to generate a UUID, default your primary key to use one, validate a UUID regEx, and add a constraint to enforce db data integrity.
				
				</description>
						
				
				<category>SQL</category>				
				
				<category>Coldfusion</category>				
				
				<pubDate>Sun, 04 Feb 2007 14:44:00 -0400</pubDate>
				<guid>http://www.robgonda.com/blog/index.cfm/2007/2/4/ColdFusion-Vs-SQL-UUID</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>Database Data Integrity: The Basics</title>
				<link>http://www.robgonda.com/blog/index.cfm/2007/1/27/Database-Data-Integrity-The-Basics</link>
				<description>
				
				Applications have usually multiple tiers, such as user interface, business model, and data. It is not an uncommon practice to rely on the application level for data validation, since in most cases, it is a single application that interacts with one particular database. However, what would happen if one field got &apos;corrupt&apos;, because of a bug in the application? What would happen if multiple applications accessed the same data, and but one was missing a particular validation rule? &lt;br /&gt;&lt;br /&gt;The data is held in a database, and it should be the database that maintained and verified integrity. You must be thinks, of course, you define datatypes and&amp;nbsp; table relations, but that&apos;s not enough. How many times have you -- or your dba -- defined a gender field as a char(1), or a uuid primary key as a char(35)? What makes you think that somehow, let&apos;s call it glitch, the gender field couldn&apos;t end up with a &apos;x&apos; value, when you&apos;re only accepting &apos;m&apos; or &apos;f&apos;? or the id key could end up with &apos;400&apos;, when taking only uuids. Chances are in fact, that your application in fact may be validating a uuid datatype, since it&apos;s native to ColdFusion, and anything other than a uuid key will break your application. &lt;br /&gt;&lt;br /&gt;In fact, and without pointing at anyone, I&apos;ve downloaded and played with dozens of open-source applications that use a uuid as a primary key, providing a sql schema script that does not validate that a proper uuid is being placed.&lt;br /&gt;&lt;br /&gt;What is the solution? Constraints; and they should always be used. A constraint is nothing but a rule that all data have to comply, enforced at the database level. The most common constraints is the foreign key, where the database automatically enforce one column value (fk) to match any column value of a different table (pk), which are automatically created when you declare foreign keys&lt;br /&gt;&lt;br /&gt;However, you can also create your own constraints, for example, gender have to be &apos;m&apos;, or &apos;f&apos;; a credit card expiration have to be between 2005 and 2020, number of children have to be between 0 and 20, and so on. Your datatype can only restrict so much, but you can add additional validation to ensure that if falls into your business logic.&lt;br /&gt;&lt;br /&gt;You can add constrains using sql scripts, or using sql GUI.&lt;br /&gt;&lt;br /&gt;The following examples are for Microsoft SQL, but should be able to adapt them to any database that supports constraints.&lt;br /&gt;&lt;br /&gt;To add a constraint to a gender field with datatype char(1), simple open the table in design mode, click the constraint icon (top toolbar, right icon, shape of a grid) and click the new button. The constraint expression must return a boolean; type ([gender] = &apos;f&apos; or [gender] = &apos;m&apos;). Following, you may assign any name to this constraint, commonly prefixed by CK_ for check. (&lt;a href=&quot;/blog/files/robGonda/UserFiles/Image/mssql constraints1.jpg&quot; target=&quot;_blank&quot;&gt;see screen shot&lt;/a&gt;)&lt;br /&gt;&lt;br /&gt;To add the same constraints by scripting, you may open a script window or the query analyzer and type the following&lt;br /&gt;&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;ALTER TABLE [dbo].[users] ADD &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CONSTRAINT [CK_users_gender] CHECK ([gender] = &apos;f&apos; or [gender] = &apos;m&apos;)&lt;br /&gt;GO&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;After this is in place, anytime you try to insert or alter the gender field with any character other than &apos;f&apos; or &apos;m&apos;, the database will throw an error, which you can catch with the constraint name.&lt;br /&gt;&lt;br /&gt;Tomorrow I will post how to validate regular expressions, including UUID datatypes.
				
				</description>
						
				
				<category>SQL</category>				
				
				<pubDate>Sat, 27 Jan 2007 14:08:00 -0400</pubDate>
				<guid>http://www.robgonda.com/blog/index.cfm/2007/1/27/Database-Data-Integrity-The-Basics</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>SQL: A Case For CROSS JOIN</title>
				<link>http://www.robgonda.com/blog/index.cfm/2006/12/27/SQL-A-Case-For-CROSS-JOIN</link>
				<description>
				
				Sometimes we have to select data from two or more tables to make our result complete. We have to perform a join. It is usually an INNER JOIN or [LEFT | RIGHT | FULL] OUTER JOIN, but SQL also provides a CROSS JOIN ... The CROSS JOIN takes all entries of one table and combine them with all entries of a second table; because of this, it does not allow for an ON clause. There are rare occasions when you would use it, so I decided to illustrate one.&lt;br /&gt;&lt;br /&gt;Imagine a schema where you have the following tables: contentKeys, languages, and content. This db allows you to store content in various languages. contentKeys will store the unique keys for content pieces, which after combined with languages, will return a unique piece of content in a particular language. The schema looks as follows:&lt;br /&gt;&lt;img src=&quot;/blog/files/robGonda/UserFiles/Image/cross-join-db-schema.jpg&quot; alt=&quot;&quot; /&gt;&lt;br /&gt;The content table has a unique contraint for FK_key and FK_language (FK denotes it&apos;s a forgeign key).&lt;br /&gt;&lt;br /&gt;Now, what if you need to know which keys exist for one language and not for others, or even which keys exist and contain content in no languages at all? We&apos;ll build a query to show this information.&lt;br /&gt;&lt;br /&gt;The first step is to find all combinations of keys and languages. To do this we need to combine all entries in they contentKeys table with all entries in the languages table.&lt;br /&gt;&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;SELECT * FROM contentKeys CROSS JOIN languages&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;The next step is understanding OUTER JOINs. An outer join selects all of the records from one database table and only those records in the second table that have matching values in the joined field. In a left outer join, the selected records will include all of the records in the first database table. In a right outer join, the selected records will include all records of the second database table.&lt;br /&gt;&lt;br /&gt;That said, if you OUTER JOIN the combination of all possible keys in all possible languages with your content table, the resulting query will let you know which keys have been translated, and which ones have not.&lt;br /&gt;&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;SELECT * from [CROSS-JOINED-QUERY] helper LEFT OUTER JOIN dbo.content &lt;br /&gt;ON helper.pk_language = dbo.content.fk_language AND helper.pk_key = dbo.content.fk_key&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;We called the cross-joined table &apos;helper&apos;, and this query will return all rows there, matching them to the content table. All the exiting content/language combinations will have data in the content table, and those what do not exist will have null values. You may enter an additional where clause to filter only null values, which will indicate exactly which content keys / language combination are missing.&lt;br /&gt;&lt;br /&gt;So for the full query, we&apos;ll take advantage of the dynamic table aliasing capabilities of sql and it looks like this:&lt;br /&gt;&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;SELECT helper.content_key, helper.code, helper.[language],&lt;br /&gt;content.pk_content, helper.pk_key, helper.pk_language, &lt;br /&gt;content.content&lt;br /&gt;FROM (SELECT * FROM contentKeys CROSS JOIN languages) helper &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; LEFT OUTER JOIN dbo.content &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ON helper.pk_language = dbo.content.fk_language AND helper.pk_key = dbo.content.fk_key&lt;br /&gt;ORDER BY helper.content_key, helper.[language]&lt;/div&gt;
				
				</description>
						
				
				<category>SQL</category>				
				
				<pubDate>Wed, 27 Dec 2006 13:17:00 -0400</pubDate>
				<guid>http://www.robgonda.com/blog/index.cfm/2006/12/27/SQL-A-Case-For-CROSS-JOIN</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>SQL Views and Performance</title>
				<link>http://www.robgonda.com/blog/index.cfm/2006/12/6/SQL-Views-and-Performance</link>
				<description>
				
				After my last post of SQL, Case sensitivity, and views, Brian Kotek brought up an excellent point, bringing up performance concerns.&lt;br /&gt;&lt;br /&gt;It turns out that views are very handy, but not very optimized for performance. Tables are generally indexed. SQL has the ability to index data of particular columns so it doesn&apos;t have to deep-scan the data each time you query that table. All primary keys are indexed, but you can create as many additional indexes as you want (when and why for another post). &lt;br /&gt;If you use a view, your columns will not be indexed automatically. With SQL 2000, Microsoft introduced View Indexes; SQL Server View Indexes are dynamic and changes to the data in the base tables are automatically reflected in the indexed view. Your columns will be automatically indexded only if your view complies with certain pre-requisites:&lt;br /&gt;&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt; Must be created the WITH SCHEMABINDING view option&lt;/li&gt;
    &lt;li&gt;May only refer to base tables in the same database.&lt;/li&gt;
    &lt;li&gt;If there is a GROUP BY clause, the view may not have a HAVING, CUBE, or ROLLUP.&lt;/li&gt;
    &lt;li&gt;May not have an OUTER JOIN clause.&lt;/li&gt;
    &lt;li&gt;May not have a UNION.&lt;/li&gt;
    &lt;li&gt;May not have DISTINCT or TOP clauses&lt;/li&gt;
    &lt;li&gt;May not have full-text predicates such as CONATINSTABLE&lt;/li&gt;
    &lt;li&gt;May not have a ROWSET function such as OPENROWSET&lt;/li&gt;
    &lt;li&gt;May not use derived tables or subqueries.&lt;/li&gt;
    &lt;li&gt;Must be created with ANSI_NULLS ON and QUOTED_IDENTIFIER ON&lt;/li&gt;
&lt;/ul&gt;
You can create an index manually like this:&lt;br /&gt;&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;
&lt;pre&gt;&lt;font&gt;&lt;font&gt;&lt;font size=&quot;-1&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;&gt;&lt;font size=&quot;-1&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;&gt;&lt;font color=&quot;blue&quot;&gt;CREATE VIEW&lt;/font&gt; OrderDetailsXSB   &lt;font color=&quot;blue&quot;&gt;WITH SCHEMABINDING &lt;br /&gt;AS&lt;br /&gt;SELECT&lt;/font&gt; OD.OrderID, OD.ProductID, P.ProductName , OD.UnitPrice&lt;br /&gt;     , OD.Quantity, OD.Discount&lt;br /&gt;&lt;font color=&quot;blue&quot;&gt;FROM&lt;/font&gt; dbo.Products P&lt;br /&gt;    &lt;font color=&quot;blue&quot;&gt;INNER JOIN&lt;/font&gt; dbo.[Order Details] OD&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;
&lt;pre&gt;&lt;font&gt;&lt;font&gt;&lt;font size=&quot;-1&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;&gt;&lt;font size=&quot;-1&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;&gt;&lt;font color=&quot;blue&quot;&gt;SET QUOTED_IDENTIFIER ON&lt;br /&gt;SET ANSI_NULLS ON&lt;/font&gt;&lt;br /&gt;GO&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;font&gt;&lt;font&gt;&lt;font size=&quot;-1&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;&gt;&lt;font size=&quot;-1&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font&gt;&lt;font&gt;&lt;font size=&quot;-1&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;&gt;&lt;font size=&quot;-1&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;&gt;&lt;font color=&quot;blue&quot;&gt;CREATE UNIQUE CLUSTERED INDEX&lt;/font&gt; [IDX_Order_Details_X] &lt;br /&gt;       ON OrderDetailsXSB (OrderID, ProductID&lt;br /&gt;                         , ProductName, Quantity)&lt;br /&gt;GO&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;br /&gt;&lt;font&gt;&lt;font&gt;&lt;font size=&quot;-1&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;&gt;&lt;font size=&quot;-1&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;&gt;         &lt;font color=&quot;blue&quot;&gt;ON&lt;/font&gt; P.ProductID = OD.ProductID&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;
&lt;br /&gt;For more information on Indexed Views, check out Microsoft&apos;s &lt;a target=&quot;_blank&quot; href=&quot;http://www.microsoft.com/technet/prodtechnol/sql/2005/ipsql05iv.mspx&quot;&gt;official documentation&lt;/a&gt;.
				
				</description>
						
				
				<category>SQL</category>				
				
				<pubDate>Wed, 06 Dec 2006 00:01:00 -0400</pubDate>
				<guid>http://www.robgonda.com/blog/index.cfm/2006/12/6/SQL-Views-and-Performance</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>SQL Automated Insert Statements</title>
				<link>http://www.robgonda.com/blog/index.cfm/2006/12/4/SQL-Automated-Insert-Statements</link>
				<description>
				
				Generating SQL scripts from ms-sql can sometimes be painful. SQL does a great job in generating sql schema scripts, including tables, views, functions, stored procedures, triggers, constraints, and indexes, but where&apos;s my data? SQL DTS (Data transformation services) can help if you&apos;re moving the data between databases, but what if you need to send someone a change script? or simply generate install scripts? I can&apos;t believe SQL provides no options for that.&lt;br /&gt;Behold, I proses the solution! While researching this problem, I finally found a flexible stored procedure that will generate insert statements. &lt;br /&gt;&lt;br /&gt;Check out this list of examples:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;Example 1:&amp;nbsp;&amp;nbsp;&amp;nbsp; To generate INSERT statements for table &apos;titles&apos;:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC sp_generate_inserts &apos;titles&apos;&lt;br /&gt;&lt;br /&gt;Example 2: &amp;nbsp;&amp;nbsp;&amp;nbsp; To ommit the column list in the INSERT statement: (Column list is included by default)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; IMPORTANT: If you have too many columns, you are advised to ommit column list, as shown below,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; to avoid erroneous results&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC sp_generate_inserts &apos;titles&apos;, @include_column_list = 0&lt;br /&gt;&lt;br /&gt;Example 3:&amp;nbsp;&amp;nbsp;&amp;nbsp; To generate INSERT statements for &apos;titlesCopy&apos; table from &apos;titles&apos; table:&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC sp_generate_inserts &apos;titles&apos;, &apos;titlesCopy&apos;&lt;br /&gt;&lt;br /&gt;Example 4:&amp;nbsp;&amp;nbsp;&amp;nbsp; To generate INSERT statements for &apos;titles&apos; table for only those titles &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; which contain the word &apos;Computer&apos; in them:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; NOTE: Do not complicate the FROM or WHERE clause here. It&apos;s assumed that you are good with T-SQL if you are using this parameter&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC sp_generate_inserts &apos;titles&apos;, @from = &amp;quot;from titles where title like &apos;%Computer%&apos;&amp;quot;&lt;br /&gt;&lt;br /&gt;Example 5: &amp;nbsp;&amp;nbsp;&amp;nbsp; To specify that you want to include TIMESTAMP column&apos;s data as well in the INSERT statement:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; (By default TIMESTAMP column&apos;s data is not scripted)&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC sp_generate_inserts &apos;titles&apos;, @include_timestamp = 1&lt;br /&gt;&lt;br /&gt;Example 6:&amp;nbsp;&amp;nbsp;&amp;nbsp; To print the debug information:&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC sp_generate_inserts &apos;titles&apos;, @debug_mode = 1&lt;br /&gt;&lt;br /&gt;Example 7: &amp;nbsp;&amp;nbsp;&amp;nbsp; If you are not the owner of the table, use @owner parameter to specify the owner name&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; To use this option, you must have SELECT permissions on that table&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC sp_generate_inserts Nickstable, @owner = &apos;Nick&apos;&lt;br /&gt;&lt;br /&gt;Example 8: &amp;nbsp;&amp;nbsp;&amp;nbsp; To generate INSERT statements for the rest of the columns excluding images&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; When using this otion, DO NOT set @include_column_list parameter to 0.&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC sp_generate_inserts imgtable, @ommit_images = 1&lt;br /&gt;&lt;br /&gt;Example 9: &amp;nbsp;&amp;nbsp;&amp;nbsp; To generate INSERT statements excluding (ommiting) IDENTITY columns:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; (By default IDENTITY columns are included in the INSERT statement)&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC sp_generate_inserts mytable, @ommit_identity = 1&lt;br /&gt;&lt;br /&gt;Example 10: &amp;nbsp;&amp;nbsp;&amp;nbsp; To generate INSERT statements for the TOP 10 rows in the table:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC sp_generate_inserts mytable, @top = 10&lt;br /&gt;&lt;br /&gt;Example 11: &amp;nbsp;&amp;nbsp;&amp;nbsp; To generate INSERT statements with only those columns you want:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC sp_generate_inserts titles, @cols_to_include = &amp;quot;&apos;title&apos;,&apos;title_id&apos;,&apos;au_id&apos;&amp;quot;&lt;br /&gt;&lt;br /&gt;Example 12: &amp;nbsp;&amp;nbsp;&amp;nbsp; To generate INSERT statements by omitting certain columns:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC sp_generate_inserts titles, @cols_to_exclude = &amp;quot;&apos;title&apos;,&apos;title_id&apos;,&apos;au_id&apos;&amp;quot;&lt;br /&gt;&lt;br /&gt;Example 13:&amp;nbsp;&amp;nbsp;&amp;nbsp; To avoid checking the foreign key constraints while loading data with INSERT statements:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC sp_generate_inserts titles, @disable_constraints = 1&lt;br /&gt;&lt;br /&gt;Example 14: &amp;nbsp;&amp;nbsp;&amp;nbsp; To exclude computed columns from the INSERT statement:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC sp_generate_inserts MyTable, @ommit_computed_cols = 1&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Download here the version for &lt;a href=&quot;/blog/files/robGonda/UserFiles/File/generate_inserts.txt&quot; target=&quot;_blank&quot;&gt;ms-sql 2000&lt;/a&gt; or &lt;a href=&quot;/blog/files/robGonda/UserFiles/File/generate_inserts_2005.txt&quot; target=&quot;_blank&quot;&gt;ms-sql 2005&lt;/a&gt;. I am sure there are some nice commercial solutions I should check out, so if you know any good one, please comment below.
				
				</description>
						
				
				<category>SQL</category>				
				
				<pubDate>Mon, 04 Dec 2006 21:27:00 -0400</pubDate>
				<guid>http://www.robgonda.com/blog/index.cfm/2006/12/4/SQL-Automated-Insert-Statements</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>Select * from Ben</title>
				<link>http://www.robgonda.com/blog/index.cfm/2006/12/4/Select--from-Ben</link>
				<description>
				
				Ben Forta has been &lt;a target=&quot;_blank&quot; href=&quot;http://www.forta.com/blog/index.cfm/SQL&quot;&gt;blogging about mssql&lt;/a&gt; lately, but we shall thank him since it&apos;s useful information.&lt;br /&gt;For example, here&apos;s a &lt;a target=&quot;_blank&quot; href=&quot;http://www.forta.com/blog/index.cfm/2006/11/20/SQL-Server-Temporary-Tables-Versus-Table-Variables&quot;&gt;comparison between temp tables and table variables&lt;/a&gt;. I always use table variables -- a lot -- and they&apos;re quite useful. I never ran into any of the restrictions Ben mentioned, but it&apos;s good to know that if I run into any of them, there is an alternative; for example, I never had to Select Into a table variable, but I do see where it can be extremely handy. &lt;br /&gt;&lt;br /&gt;Another nice post mentions how to perform &lt;a href=&quot;http://www.forta.com/blog/index.cfm/2006/11/29/Case-Sensitive-SQL-Searches&quot; target=&quot;_blank&quot;&gt;case sensitive searches&lt;/a&gt; w/o changing the collation for the entire database. As you may know, you may define different collations when creating a database which will indicate the character set and case sensitivity among other properties, but you can use a different collation in run time; I actually did not know that. Ben shows two examples:&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;SELECT *&lt;br /&gt; FROM MyTable&lt;br /&gt; WHERE Col3 COLLATE SQL_Latin1_General_CP1_CS_AS LIKE &apos;%foo%&apos;&lt;br /&gt;--- or ---&lt;br /&gt;CRETE VIEW MyTableCS AS&lt;br /&gt; SELECT Col1, Col2, Col3 COLLATE SQL_Latin1_General_CP1_CS_AS as Col3&lt;br /&gt; FROM MyTable&lt;/div&gt;
&lt;br /&gt;This reminds me that I should blog more about SQL ... you may expect some coming soon.
				
				</description>
						
				
				<category>SQL</category>				
				
				<pubDate>Mon, 04 Dec 2006 21:11:00 -0400</pubDate>
				<guid>http://www.robgonda.com/blog/index.cfm/2006/12/4/Select--from-Ben</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>Database diagram support objects cannot be installed</title>
				<link>http://www.robgonda.com/blog/index.cfm/2006/10/29/Database-diagram-support-objects-cannot-be-installed</link>
				<description>
				
				If you ever get a message like this when trying to create a diagram in SQL 2005&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;&amp;quot;Database diagram support objects cannot be installed because this database does not have a valid owner. To continue, first use the Files page of the Database Properties dialog box or the ALTER AUTHORIZATION statement to set the database owner to a valid login, then add the database diagram support objects.&amp;quot;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Here&apos;s step by step what you have to do:&lt;br /&gt;&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;EXEC sp_dbcmptlevel &apos;yourDB&apos;, &apos;90&apos;;&lt;br /&gt;go&lt;br /&gt;ALTER AUTHORIZATION ON DATABASE::yourDB TO &amp;quot;yourLogin&amp;quot;&lt;br /&gt;go&lt;br /&gt;use [yourDB]&lt;br /&gt;go&lt;br /&gt;EXECUTE AS USER = N&apos;dbo&apos; REVERT&lt;br /&gt;go&lt;/div&gt;
				
				</description>
						
				
				<category>SQL</category>				
				
				<pubDate>Sun, 29 Oct 2006 22:44:00 -0400</pubDate>
				<guid>http://www.robgonda.com/blog/index.cfm/2006/10/29/Database-diagram-support-objects-cannot-be-installed</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>SQL Prompt: Free SQL Code Completion Tool</title>
				<link>http://www.robgonda.com/blog/index.cfm/2006/6/1/SQL-Prompt-Free-SQL-Code-Completion-Tool</link>
				<description>
				
				Brian posted today a &lt;a target=&quot;_blank&quot; href=&quot;http://www.remotesynthesis.com/blog/index.cfm/2006/6/1/Free-SQL-Code-Completion-Tool-Limited-Time&quot;&gt;small review&lt;/a&gt; on &lt;a target=&quot;_blank&quot; href=&quot;http://www.red-gate.com/products/SQL_Prompt/index.htm&quot;&gt;Red Gate&apos;s SQL Prompt, and SQL Completion Tool&lt;/a&gt;... the best part: it&apos;s free for a limited time! I haven&apos;t checked it yet, but it looks amazing, a must have I would say. SQL Prompt works with Microsoft Query Analyzer, SQL Server 2005 Management Studio, Visual Studio 2005, Visual Studio .NET 2003, SQL Server 2000 Enterprise Manager, and UltraEdit32.&lt;br /&gt; &lt;blockquote&gt;SQL Prompt provides Intellisense? style auto-completion for Microsoft SQL Server editors. It will tell you the exact formatting you should use for your SQL commands, while you are writing them and will therefore help you write fast, perfectly formatted SQL statements.&lt;/blockquote&gt;  &lt;br /&gt;&lt;img alt=&quot;&quot; src=&quot;/blog/files/robGonda/UserFiles/Image/SQL_Prompt_Animated_Image.gif&quot; /&gt;
				
				</description>
						
				
				<category>SQL</category>				
				
				<category>Software</category>				
				
				<pubDate>Thu, 01 Jun 2006 20:32:00 -0400</pubDate>
				<guid>http://www.robgonda.com/blog/index.cfm/2006/6/1/SQL-Prompt-Free-SQL-Code-Completion-Tool</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>MSSQL and Pagination</title>
				<link>http://www.robgonda.com/blog/index.cfm/2006/4/25/MSSQL-and-Pagination</link>
				<description>
				
				Ray posted a &lt;a href=&quot;http://ray.camdenfamily.com/index.cfm/2006/4/24/ColdFusion-and-Pagination&quot; target=&quot;_blank&quot;&gt;nice entry about ColdFusion and Pagination&lt;/a&gt;, useful and easy to implement. I commented that it should only be used for small recordsets, because even if you do not show all records, transferring 100k entries from the DB to the application server to only display 10 or 20 is not efficient at all. &lt;br /&gt;&lt;br /&gt;Some people suggested using LIMIT and OFFSET, which can only by done with mysql.... I hate to admit it, but mssql is so much better than mysql, expect for that ... I can&apos;t believe that we still don&apos;t have that functionality... anyways, Adam also posted a link to an &lt;a target=&quot;_blank&quot; href=&quot;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/scalenethowto05.asp&quot;&gt;msdn article&lt;/a&gt; explaining a couple of different approaches to tackle this problem. &lt;br /&gt;&lt;br /&gt;I, on the other hand, have been using a stored procedure for years to achieve this goal. I have it in production retrieving pages out of a table with over 5 million records... at it works flawlessly. Let me add that you do need indexes, defragging, maintenance, lots of RAM ... this SP doesn&apos;t do miracles :)&lt;br /&gt;&lt;br /&gt;You can download the SP &lt;a href=&quot;/blog/files/robGonda/UserFiles/File/sp_selectnextn.txt&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;. It works perfectly with mssql 2000 / 2005. Let me emphasize that I did not write this. I got it from a sql exchange article a few years ago. Yes, it can be improved I guess, since one of its major limitations is lacking of a way to query over left/right outer joins. You can query aggregated functions, embedded&amp;nbsp; selects, inner joins (ansi format) ... You can still get around them using views, which is how I&apos;ve done it in the past... in fact, if the query is too complicated, you might as well write a view for it anyways. &lt;br /&gt;&lt;br /&gt;As far as the ColdFusion side, here&apos;s an invocation I have to one of my tables:&lt;br /&gt;&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!--- &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; get multiple users in pagination&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ---&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cffunction name=&amp;quot;getUsers&amp;quot; access=&amp;quot;public&amp;quot; output=&amp;quot;No&amp;quot; returntype=&amp;quot;struct&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfargument name=&amp;quot;UserName&amp;quot; required=&amp;quot;No&amp;quot; type=&amp;quot;string&amp;quot; default=&amp;quot;&amp;quot; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfargument name=&amp;quot;Alias&amp;quot; required=&amp;quot;No&amp;quot; type=&amp;quot;string&amp;quot; default=&amp;quot;&amp;quot; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfargument name=&amp;quot;ageFrom&amp;quot; required=&amp;quot;No&amp;quot; type=&amp;quot;numeric&amp;quot; default=&amp;quot;0&amp;quot; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfargument name=&amp;quot;ageTo&amp;quot; required=&amp;quot;No&amp;quot; type=&amp;quot;numeric&amp;quot; default=&amp;quot;0&amp;quot; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfargument name=&amp;quot;gender&amp;quot; required=&amp;quot;No&amp;quot; type=&amp;quot;string&amp;quot; default=&amp;quot;0&amp;quot; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfargument name=&amp;quot;Race&amp;quot; required=&amp;quot;No&amp;quot; type=&amp;quot;string&amp;quot; default=&amp;quot;0&amp;quot; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfargument name=&amp;quot;Admin&amp;quot; required=&amp;quot;No&amp;quot; type=&amp;quot;numeric&amp;quot; default=&amp;quot;0&amp;quot; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfargument name=&amp;quot;groupNumber&amp;quot; required=&amp;quot;No&amp;quot; type=&amp;quot;numeric&amp;quot; default=&amp;quot;1&amp;quot; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfargument name=&amp;quot;groupSize&amp;quot; required=&amp;quot;No&amp;quot; type=&amp;quot;numeric&amp;quot; default=&amp;quot;5&amp;quot; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfset var returnStruct = structNew() /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfset var qGetUsers = &apos;&apos; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfset var recordcount = &apos;&apos; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfset var SqlCols = &apos;&apos; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfset var SqlWhere = &apos;&apos; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfset var OrderBy = &apos;&apos; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!--- columns ---&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfsavecontent variable=&amp;quot;SqlCols&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; pk_users, UserName, Alias, gender, Age, race&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/cfsavecontent&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!--- condition ---&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfoutput&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfsavecontent variable=&amp;quot;SqlWhere&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; 0 = 0&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfif arguments.Admin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; AND&amp;nbsp;&amp;nbsp;&amp;nbsp; Admin = 1&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfelse&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; AND&amp;nbsp;&amp;nbsp;&amp;nbsp; Admin = 0&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/cfif&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfif len(arguments.UserName)&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; AND UserName like &apos;#arguments.UserName#%&apos;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/cfif&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfif len(arguments.Alias)&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; AND Alias like &apos;#arguments.Alias#%&apos;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/cfif&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfif arguments.ageFrom&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; AND AGE &amp;gt;= #arguments.ageFrom#&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/cfif&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfif arguments.ageTo&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; AND AGE &amp;lt;= #arguments.ageTo#&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/cfif&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfif arguments.gender neq &apos;0&apos;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; AND gender like &apos;#arguments.gender#%&apos;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/cfif&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfif arguments.Race neq &apos;0&apos;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; AND Race = &apos;#arguments.Race#&apos;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/cfif&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/cfsavecontent&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/cfoutput&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!--- order ---&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfsavecontent variable=&amp;quot;OrderBy&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; UserName&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/cfsavecontent&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!--- query ---&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfstoredproc procedure=&amp;quot;sp_selectnextn&amp;quot; datasource=&amp;quot;#variables.instance.dsn#&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfprocresult name=&amp;quot;qGetUsers&amp;quot; resultset=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfprocresult name=&amp;quot;recordcount&amp;quot; resultset=&amp;quot;2&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;cfprocparam type=&amp;quot;In&amp;quot; cfsqltype=&amp;quot;CF_SQL_VARCHAR&amp;quot; dbvarname=&amp;quot;TableName&amp;quot; value=&amp;quot;users&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;cfprocparam type=&amp;quot;In&amp;quot; cfsqltype=&amp;quot;CF_SQL_VARCHAR&amp;quot; dbvarname=&amp;quot;Columns&amp;quot; value=&amp;quot;#SqlCols#&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;cfprocparam type=&amp;quot;In&amp;quot; cfsqltype=&amp;quot;CF_SQL_VARCHAR&amp;quot; dbvarname=&amp;quot;IdentityColumn&amp;quot; value=&amp;quot;pk_users&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;cfprocparam type=&amp;quot;In&amp;quot; cfsqltype=&amp;quot;CF_SQL_VARCHAR&amp;quot; dbvarname=&amp;quot;GroupNumber&amp;quot; value=&amp;quot;#arguments.groupNumber#&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;cfprocparam type=&amp;quot;In&amp;quot; cfsqltype=&amp;quot;CF_SQL_VARCHAR&amp;quot; dbvarname=&amp;quot;GroupSize&amp;quot; value=&amp;quot;#arguments.groupSize#&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;cfprocparam type=&amp;quot;In&amp;quot; cfsqltype=&amp;quot;CF_SQL_VARCHAR&amp;quot; dbvarname=&amp;quot;SqlWhere&amp;quot; value=&amp;quot;#SqlWhere#&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;cfprocparam type=&amp;quot;In&amp;quot; cfsqltype=&amp;quot;CF_SQL_VARCHAR&amp;quot; dbvarname=&amp;quot;SqlOrderBy&amp;quot; value=&amp;quot;#OrderBy#&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/cfstoredproc&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfset returnStruct.rs = qGetUsers /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfset returnStruct.rc = recordcount.countAll /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;cfreturn returnStruct /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/cffunction&amp;gt;&lt;/div&gt;
&lt;br /&gt;It basically takes the table(s), columns, primary key to use for pagination, page size and number, where statement, and order by statement. There is a limitation of size of your statements ... You won&apos;t be able to use a Where clause larger than 4000 characters.&lt;br /&gt;&lt;br /&gt;The original SP did not have the full recordcount, which allows to calculate the number of pages. It does require more CPU, but I didn&apos;t want to just guess if there&apos;s a next page given the count in one particular page.&lt;br /&gt;&lt;br /&gt;If you have any comments or suggestions, feel free to add them below. &lt;br /&gt;&lt;br /&gt;Enjoy!&lt;br /&gt;&lt;br /&gt;
				
				</description>
						
				
				<category>SQL</category>				
				
				<category>Coldfusion</category>				
				
				<pubDate>Tue, 25 Apr 2006 23:24:00 -0400</pubDate>
				<guid>http://www.robgonda.com/blog/index.cfm/2006/4/25/MSSQL-and-Pagination</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>SQL: better than select count(*)</title>
				<link>http://www.robgonda.com/blog/index.cfm/2006/4/10/SQL-better-than-select</link>
				<description>
				
				If you need to count all rows from a table without any conditional, there&apos;s a much better and faster way than select count(*). This code works with Microsoft SQL 2000 and 2005.&lt;br /&gt;&lt;br /&gt;
&lt;div class=&quot;code&quot;&gt;CREATE FUNCTION [dbo].[FASTCOUNT] (@Table sysname)&lt;br /&gt;&lt;br /&gt;RETURNS INT&lt;br /&gt;&lt;br /&gt;AS&lt;br /&gt;BEGIN&lt;br /&gt;&lt;br /&gt;&amp;nbsp; DECLARE @Rows int&lt;br /&gt;&lt;br /&gt;&amp;nbsp; SELECT&amp;nbsp; @Rows = rows &lt;br /&gt;&amp;nbsp; FROM sysindexes&lt;br /&gt;&amp;nbsp; WHERE id = OBJECT_ID(@Table)&lt;br /&gt;&amp;nbsp; AND indid &amp;lt; 2&lt;br /&gt;&lt;br /&gt;&amp;nbsp; RETURN @Rows &lt;br /&gt;&lt;br /&gt;END&lt;/div&gt;
&lt;br /&gt;p.s. I&apos;ve been using this code for so long, I don&apos;t even remember who to give credit to :) thanks!
				
				</description>
						
				
				<category>SQL</category>				
				
				<pubDate>Mon, 10 Apr 2006 22:17:00 -0400</pubDate>
				<guid>http://www.robgonda.com/blog/index.cfm/2006/4/10/SQL-better-than-select</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>sql: view problems after altering a table</title>
				<link>http://www.robgonda.com/blog/index.cfm/2006/4/6/sql-view-problems-after-altering-a-table</link>
				<description>
				
				This is old news, I know ... but many people don&apos;t know it ... When using Views in Microsoft SQL 2000 (haven&apos;t checked 2005), after altering a table the view will not update itself automatically ... it will get completely messed up ... the views point to the column number, not name, therefore after adding a field, some of your columns will be shifted. &lt;br /&gt;&lt;br /&gt;The solution is simple, yet confusing if you&apos;re not aware of it ... you can click edit the view, and all your columns will show fine, but if you open the view they&apos;ll be wrong ... all you have to do is &lt;strong&gt;edit the view, save it again, and close&lt;/strong&gt; ... simple, but necessary ... &lt;br /&gt;&lt;br /&gt;A co-worker ran into this today and lost precious hours until he chose to ask :) now you know, and knowing is half of the battle.
				
				</description>
						
				
				<category>SQL</category>				
				
				<pubDate>Thu, 06 Apr 2006 23:49:00 -0400</pubDate>
				<guid>http://www.robgonda.com/blog/index.cfm/2006/4/6/sql-view-problems-after-altering-a-table</guid>
				
			</item>
			
		 	
			</channel></rss>