<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6725016282509081212</id><updated>2011-11-27T17:28:54.970-08:00</updated><category term='Integration Services'/><category term='SQL Server Performance'/><category term='T-SQL'/><category term='.NET Architecture'/><title type='text'>whynot</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://gulappa.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://gulappa.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Gulappa</name><uri>http://www.blogger.com/profile/08215005201664988656</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>16</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6725016282509081212.post-2610067114303179277</id><published>2007-11-02T04:46:00.000-07:00</published><updated>2007-11-02T05:02:28.691-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='.NET Architecture'/><title type='text'>Web Architecture</title><content type='html'>I had worked on a web site for one of my client and I am sharing the web architecture diagram for latter use.  The web architecture diagram is developed using MS-VISIO tool and the flow for the web architecture is described. &lt;br /&gt; &lt;br /&gt;The requirement from the client is to allow the on-line customer to view their account status, contract &amp; payment details, create user, modify profile, send note to admin and subscribe newsletters.&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;a href="http://bp2.blogger.com/_2oH0Myof_I4/RysOnOnJKvI/AAAAAAAAABQ/ZvclQn0S8ig/s1600-h/Web+Architecture.png"&gt;&lt;img style="cursor:pointer; cursor:hand;" src="http://bp2.blogger.com/_2oH0Myof_I4/RysOnOnJKvI/AAAAAAAAABQ/ZvclQn0S8ig/s200/Web+Architecture.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5128208667791403762" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;strong&gt;Flow Descriptions&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;(1) Customer requests for the  account status page from the webserver.&lt;br /&gt;(2) ASP.NET renders the welcome page with the login screen and presents the web page to the customer.&lt;br /&gt;(3) Customer types their user id and password and clicks on the [submit] button on the webform.&lt;br /&gt;(4) ASP.NET calls the customer web services to call procedure in database via the sbl db components.&lt;br /&gt;(5) Stored procedure verify the username and password if it is exists in the database table and the result is sent back through the db components, webservice and to ASP.NET.&lt;br /&gt;(6) If the customer is not found within the database , the FEW will send the "Access Denied" screen to the customer.&lt;br /&gt;(7) If the customer is found in the database, FEW invokes a method from the customer web service to call procedure in database via the db components.&lt;br /&gt;(8) Stored procedure execute and retrieve the contract details that is belongs to the customer and the result is sent back through the db components, webservice and to ASP.NET.&lt;br /&gt;(9) ASP.NET renders contract details page and present(s) contract summary &amp; contract details in contract summary tab to the customer.&lt;br /&gt;(10) Customer clicks on either payment summary link, payment due link, send note tab, register tab, modify profile tab and sign up link.&lt;br /&gt;(11) ASP.NET retrieves data from web service that pertains to the selected link or tab via the db components in database and ,&lt;br /&gt;(12) Stored procedure execute (the action or select queries) and retrieve the results and the result is sent back through the db components, webservice and to ASP.NET.&lt;br /&gt;(13) ASP.NET renders the page for the selected link or tab to the customer.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6725016282509081212-2610067114303179277?l=gulappa.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gulappa.blogspot.com/feeds/2610067114303179277/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6725016282509081212&amp;postID=2610067114303179277' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/2610067114303179277'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/2610067114303179277'/><link rel='alternate' type='text/html' href='http://gulappa.blogspot.com/2007/11/web-architecture.html' title='Web Architecture'/><author><name>Gulappa</name><uri>http://www.blogger.com/profile/08215005201664988656</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp2.blogger.com/_2oH0Myof_I4/RysOnOnJKvI/AAAAAAAAABQ/ZvclQn0S8ig/s72-c/Web+Architecture.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6725016282509081212.post-5155348848175463537</id><published>2007-11-01T05:40:00.000-07:00</published><updated>2007-11-02T04:57:13.727-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Integration Services'/><title type='text'>SQL Server Integration Services Automation</title><content type='html'>&lt;strong&gt;Automation Process&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;I have created five SSIS package for five source systems. I have scheduled the SSIS package as a job using SQL Server Agent. The jobs have been scheduled to run on every hour on weekdays. You could change the frequency interval at your convenience. The primary (Control Report) job has been enabled by default and rest of jobs is not enabled &amp; rename with suffix as "-- Disabled". &lt;br /&gt;&lt;br /&gt;The enabled job would start execute, calculate &amp; set the schedule start date for the subsequent month, rename (suffix as "-- Disabled") &amp; disable the job on success. Rename (remove suffix as "-- Disabled") &amp; enable the next job for execution. The cycle spins for other jobs until the final job for a month. &lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;a href="http://bp0.blogger.com/_2oH0Myof_I4/RynKnOnJKuI/AAAAAAAAABI/jdLnvGRxM5k/s1600-h/processcycle.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;" src="http://bp0.blogger.com/_2oH0Myof_I4/RynKnOnJKuI/AAAAAAAAABI/jdLnvGRxM5k/s200/processcycle.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5127852426024004322" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;Let us &lt;a href="http://www.sqlservercentral.com/articles/Integration+Services/61260/"&gt;read further&lt;/a&gt; to find out how the "Thought Process" has been executed in SQL Server 2005 using integration services.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6725016282509081212-5155348848175463537?l=gulappa.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gulappa.blogspot.com/feeds/5155348848175463537/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6725016282509081212&amp;postID=5155348848175463537' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/5155348848175463537'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/5155348848175463537'/><link rel='alternate' type='text/html' href='http://gulappa.blogspot.com/2007/11/sql-server-integration-services.html' title='SQL Server Integration Services Automation'/><author><name>Gulappa</name><uri>http://www.blogger.com/profile/08215005201664988656</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp0.blogger.com/_2oH0Myof_I4/RynKnOnJKuI/AAAAAAAAABI/jdLnvGRxM5k/s72-c/processcycle.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6725016282509081212.post-3385381038145028312</id><published>2007-10-26T21:21:00.000-07:00</published><updated>2007-11-02T04:57:41.810-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='T-SQL'/><title type='text'>Display row value as a TABLE column using SQL select statement</title><content type='html'>&lt;strong&gt;Requirement:&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Summarize PIFAmt column divide by Summarize Factors column by StateName column and diplay prior &amp; current year data as a table column by auto and property business values.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Table Structure:&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp3.blogger.com/_2oH0Myof_I4/RyK-iunJKoI/AAAAAAAAAAc/ux3M1ktqC9k/s1600-h/tablestructure.PNG"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;" src="http://bp3.blogger.com/_2oH0Myof_I4/RyK-iunJKoI/AAAAAAAAAAc/ux3M1ktqC9k/s200/tablestructure.PNG" border="0" alt=""id="BLOGGER_PHOTO_ID_5125868829738084994" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;strong&gt;Table Data:&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp1.blogger.com/_2oH0Myof_I4/RyK_BOnJKqI/AAAAAAAAAAo/9Gl1S1fyWNI/s1600-h/tabledata.PNG"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;" src="http://bp1.blogger.com/_2oH0Myof_I4/RyK_BOnJKqI/AAAAAAAAAAo/9Gl1S1fyWNI/s200/tabledata.PNG" border="0" alt=""id="BLOGGER_PHOTO_ID_5125869353724095138" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;You could avoid the following errors when you execute the enclosed SQL select statement and display the result as I explained in my requirement.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Errors:&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Server: Msg 8134, Level 16, State 1, Line 1&lt;br /&gt;Divide by zero error encountered.&lt;br /&gt;&lt;br /&gt;Server: Msg 130, Level 15, State 1, Line 3&lt;br /&gt;Cannot perform an aggregate function on an expression containing an aggregate or a subquery.&lt;br /&gt;&lt;strong&gt;&lt;br /&gt;SQL Select Statement:&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;SELECT STATENAME,&lt;br /&gt;SUM(CASE WHEN EFFYEAR = 2006 AND BUSINESS = 'AUTO' THEN PIFAMT END) / &lt;br /&gt;SUM(CASE WHEN FACTORS &gt; 0 AND EFFYEAR = 2006 AND BUSINESS = 'AUTO' THEN FACTORS END) AS AUTO_PIF_PREV_YR,&lt;br /&gt;SUM(CASE WHEN EFFYEAR = 2007 AND BUSINESS = 'AUTO' THEN PIFAMT END) / &lt;br /&gt;SUM(CASE WHEN FACTORS &gt; 0 AND EFFYEAR = 2007 AND BUSINESS = 'AUTO' THEN FACTORS END) AS AUTO_PIF_CURR_YR,&lt;br /&gt;SUM(CASE WHEN EFFYEAR = 2006 AND BUSINESS = 'PROPERTY' AND SEGMENT = 'HOMEOWNERS' THEN PIFAMT END) / &lt;br /&gt;SUM(CASE WHEN FACTORS &gt; 0 AND EFFYEAR = 2006 AND BUSINESS = 'PROPERTY' AND SEGMENT = 'HOMEOWNERS' THEN FACTORS END) AS PROP_PIF_PREV_YR,&lt;br /&gt;SUM(CASE WHEN EFFYEAR = 2007 AND BUSINESS = 'PROPERTY' AND SEGMENT = 'HOMEOWNERS' THEN PIFAMT END) / &lt;br /&gt;SUM(CASE WHEN FACTORS &gt; 0 AND EFFYEAR = 2007 AND BUSINESS = 'PROPERTY' AND SEGMENT = 'HOMEOWNERS' THEN FACTORS END) AS PROP_PIF_CURR_YR&lt;br /&gt;FROM FACT&lt;br /&gt;WHERE BUSINESS IN ('AUTO', 'PROPERTY') AND EFFYEAR &gt;= 2006 AND &lt;br /&gt;SEGMENT = (CASE WHEN BUSINESS = 'AUTO' THEN SEGMENT ELSE 'HOMEOWNERS' END)&lt;br /&gt;GROUP BY STATENAME&lt;br /&gt;&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Results:&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp3.blogger.com/_2oH0Myof_I4/RyLEmunJKrI/AAAAAAAAAAw/PyJdsb1EDpc/s1600-h/results.PNG"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;" src="http://bp3.blogger.com/_2oH0Myof_I4/RyLEmunJKrI/AAAAAAAAAAw/PyJdsb1EDpc/s200/results.PNG" border="0" alt=""id="BLOGGER_PHOTO_ID_5125875495527328434" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6725016282509081212-3385381038145028312?l=gulappa.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gulappa.blogspot.com/feeds/3385381038145028312/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6725016282509081212&amp;postID=3385381038145028312' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/3385381038145028312'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/3385381038145028312'/><link rel='alternate' type='text/html' href='http://gulappa.blogspot.com/2007/10/requirement-summarize-pifamt-column.html' title='Display row value as a TABLE column using SQL select statement'/><author><name>Gulappa</name><uri>http://www.blogger.com/profile/08215005201664988656</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp3.blogger.com/_2oH0Myof_I4/RyK-iunJKoI/AAAAAAAAAAc/ux3M1ktqC9k/s72-c/tablestructure.PNG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6725016282509081212.post-1982670711600783833</id><published>2007-10-17T20:05:00.001-07:00</published><updated>2007-11-02T04:59:30.595-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server Performance'/><title type='text'>An Introduction to Clustered and Non-Clustered Index Data Structures</title><content type='html'>When I first started using SQL Server as a novice, I was initially confused as to the differences between clustered and non-clustered indexes. As a developer, and new DBA, I took it upon myself to learn everything I could about these index types, and when they should be used. This article is a result of my learning and experience, and explains the differences between clustered and non-clustered index data structures for the DBA or developer new to SQL Server. If you are new to SQL Server, I hope you find this article useful.&lt;br /&gt;&lt;br /&gt;As you read this &lt;a href="http://www.sql-server-performance.com/articles/per/index_data_structures_p1.aspx"&gt;article&lt;/a&gt;, if you choose, you can cut and paste the code I have provided in order to more fully understand and appreciate the differences between clustered and non-clustered indexes.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6725016282509081212-1982670711600783833?l=gulappa.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gulappa.blogspot.com/feeds/1982670711600783833/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6725016282509081212&amp;postID=1982670711600783833' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/1982670711600783833'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/1982670711600783833'/><link rel='alternate' type='text/html' href='http://gulappa.blogspot.com/2007/10/introduction-to-clustered-and-non.html' title='An Introduction to Clustered and Non-Clustered Index Data Structures'/><author><name>Gulappa</name><uri>http://www.blogger.com/profile/08215005201664988656</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6725016282509081212.post-6258930743429491350</id><published>2007-10-17T19:59:00.000-07:00</published><updated>2007-11-02T04:59:42.310-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server Performance'/><title type='text'>When To Use the Order By Clause</title><content type='html'>When I was using SQL Server, I was not using the "order by" clause properly. I always say myself that when I want the data in a particular order, I should use order by clause in select statement otherwise leave to the SQL Server. I presumed MS-SQL Server will return the data in its own order. I was not even thinking that am I using and doing correctly. In my initially days in my career, I was happy to retrieve the data and not knowing how it comes. It is the nature for the software engineers at the premature stage or using new command or tool or technology. They will not knowing properly or doing enough research of the each command before commence using the command. I would say it could be because of competition in the IT field and immature in IT field. &lt;br /&gt;&lt;br /&gt;Where do we get the word "Order?" I have heard and seen in so many places the use of "Order" word. I have come across the listed places the "Order" word used regularly.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;When an applicant applies for a student visa, visa officer will politely inform to the application order the applications and come back. &lt;br /&gt;When a procurer gives a draft to the registrar officer, officer will politely return back the draft and request to order the draft. &lt;br /&gt;Firm will display the designation in a proper order. &lt;br /&gt;Construct a house; we will clean and even the land before establishing the Pillar. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The ultimate aim is "First IN has to first come OUT" &lt;br /&gt;&lt;br /&gt;I have decided and kept in my mind that somewhere down the line in my IT career, I should know when I should use "order by" clause in the select statement. I know it will be on one FINE DAY". I will spend some time on "order by" command. That one fine day is TODAY to explore myself and find the ways to use the "order by" clause. This could be useful for a new developer and dba to SQL Server to avoid confusion on using "order by clause" and knowing when to use "order by" clause command. &lt;br /&gt;&lt;br /&gt;To come along with me in this article, I have paste the script and result of the output. Example of the script can be used in a sql server to understand completely after reading the &lt;a href="http://www.sqlservercentral.com/articles/Basic+Querying/whentousetheorderbyclause/1357/"&gt;article&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6725016282509081212-6258930743429491350?l=gulappa.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gulappa.blogspot.com/feeds/6258930743429491350/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6725016282509081212&amp;postID=6258930743429491350' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/6258930743429491350'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/6258930743429491350'/><link rel='alternate' type='text/html' href='http://gulappa.blogspot.com/2007/10/when-to-use-order-by-clause_17.html' title='When To Use the Order By Clause'/><author><name>Gulappa</name><uri>http://www.blogger.com/profile/08215005201664988656</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6725016282509081212.post-7315831526660092930</id><published>2007-10-17T19:12:00.000-07:00</published><updated>2007-11-02T05:00:04.474-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='T-SQL'/><title type='text'>User-defined data type dependencies</title><content type='html'>MSSQLServer has got sp_depends system sp to display the dependencies for a stored procedure, table and view.  sp_depends does not support to display the User-defined data type dependencies.  For custom database, we will create user defined data types (UDDT) and add this UDDT to a column/variable in a table/stored procedure.  This sp (UDTDepends) will help to display the User-defined data type dependencies in a database for a Tables and Stored Procedure.  &lt;br /&gt;&lt;br /&gt;Compile this sp in a database and execute the same.  It will display the dependencies for the user defined data types if it exists in a database.&lt;br /&gt;&lt;br /&gt;Criticize are welcome. &lt;br /&gt;&lt;br /&gt;if exists (select * from sysobjects where id = object_id(N'[dbo].[UDTDepends]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)&lt;br /&gt;drop procedure [dbo].[UDTDepends]&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;Create Proc UDTDepends &lt;br /&gt;As&lt;br /&gt;&lt;br /&gt;SET NOCOUNT ON&lt;br /&gt;&lt;br /&gt;    SELECT so.name As "ObjectName", sc.name As "ColumnName", type_name(st.xusertype) As "UserDefinedDataType", &lt;br /&gt;        type_name(sc.xtype) As "DataType", st.length As "DataLength"&lt;br /&gt;&lt;br /&gt;    FROM sysobjects so, syscolumns sc, systypes st&lt;br /&gt;&lt;br /&gt;    WHERE so.xtype In ('U', 'P') and sc.id = so.id and sc.xusertype = st.xusertype and &lt;br /&gt;    sc.usertype Not In (0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 19, 20, 21, 22, 23, 24, 80) &lt;br /&gt;&lt;br /&gt;    ORDER BY so.xtype desc, so.name, st.name&lt;br /&gt;&lt;br /&gt;SET NOCOUNT OFF&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6725016282509081212-7315831526660092930?l=gulappa.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gulappa.blogspot.com/feeds/7315831526660092930/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6725016282509081212&amp;postID=7315831526660092930' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/7315831526660092930'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/7315831526660092930'/><link rel='alternate' type='text/html' href='http://gulappa.blogspot.com/2007/10/user-defined-data-type-dependencies.html' title='User-defined data type dependencies'/><author><name>Gulappa</name><uri>http://www.blogger.com/profile/08215005201664988656</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6725016282509081212.post-1549915441658961851</id><published>2007-10-17T19:08:00.000-07:00</published><updated>2007-11-02T05:00:20.217-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='T-SQL'/><title type='text'>Stabilize Index</title><content type='html'>This sp is used to update index in a database.  This sp has got three optional varchar parameters.  &lt;br /&gt;First parameter will take the tablename. Second parameter will take the indexname.  Third parameter will take the fillfactor.  &lt;br /&gt;&lt;br /&gt;The following option we can execute the sp in a user database.&lt;br /&gt;&lt;br /&gt;1.    exec StabilizeIndex&lt;br /&gt;It will update all index in a user database&lt;br /&gt;&lt;br /&gt;2.    StabilizeIndex 'TableName'&lt;br /&gt;It will update all index in a table&lt;br /&gt;&lt;br /&gt;3.    StabilizeIndex 'TableName', 'IndexName'&lt;br /&gt;It will update an index in a table.&lt;br /&gt;&lt;br /&gt;4.StabilizeIndex 'TableName', 'IndexName', ‘FillFactor’&lt;br /&gt;It will update an index in a table with fill factor. &lt;br /&gt;&lt;br /&gt;Note: This is not used in system database.&lt;br /&gt;&lt;br /&gt;/* To Execute the sp in various options&lt;br /&gt;--StabilizeIndex &lt;br /&gt;--StabilizeIndex 'TableName'&lt;br /&gt;--StabilizeIndex 'TableName', 'IndexName'&lt;br /&gt;--StabilizeIndex 'TableName', 'IndexName', 'FillFactor'&lt;br /&gt;*/&lt;br /&gt;if exists (select * from sysobjects where id = object_id(N'[dbo].[StabilizeIndex]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)&lt;br /&gt;drop procedure [dbo].[StabilizeIndex]&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;Create Proc StabilizeIndex &lt;br /&gt;(&lt;br /&gt;            @TableName Varchar(100) = '', &lt;br /&gt;            @IndexName Varchar(100) = '', &lt;br /&gt;            @FillFactor Varchar(3) = ''&lt;br /&gt;) &lt;br /&gt;As&lt;br /&gt;&lt;br /&gt;Declare @TableID Int, @ObjectName Varchar(100), @IndName Varchar(100), @SQL Varchar(8000)&lt;br /&gt;&lt;br /&gt;SET NOCOUNT ON&lt;br /&gt;&lt;br /&gt;IF Len(@TableName) = 0&lt;br /&gt;    Begin&lt;br /&gt;        DECLARE table_cursor CURSOR FOR &lt;br /&gt;            SELECT id, name&lt;br /&gt;            FROM sysobjects&lt;br /&gt;            WHERE xtype = 'U'&lt;br /&gt;            ORDER BY name&lt;br /&gt;    End  &lt;br /&gt;Else&lt;br /&gt;    Begin&lt;br /&gt;        DECLARE table_cursor CURSOR FOR &lt;br /&gt;            SELECT id, name&lt;br /&gt;            FROM sysobjects&lt;br /&gt;            WHERE xtype = 'U' and id = object_id(@TableName)&lt;br /&gt;            ORDER BY name&lt;br /&gt;    End  &lt;br /&gt;&lt;br /&gt;OPEN table_cursor&lt;br /&gt;  &lt;br /&gt;FETCH NEXT FROM table_cursor &lt;br /&gt;INTO @TableID, @ObjectName&lt;br /&gt;  &lt;br /&gt;WHILE @@FETCH_STATUS = 0&lt;br /&gt;BEGIN&lt;br /&gt;  &lt;br /&gt;        IF Len(@IndexName) = 0 &lt;br /&gt;            Begin&lt;br /&gt;         DECLARE index_cursor CURSOR FOR &lt;br /&gt;             SELECT name &lt;br /&gt;                    FROM sysindexes&lt;br /&gt;             WHERE id = @TableID and indid &gt; 0&lt;br /&gt;            End&lt;br /&gt;        Else&lt;br /&gt;            Begin&lt;br /&gt;         DECLARE index_cursor CURSOR FOR &lt;br /&gt;             SELECT name &lt;br /&gt;                    FROM sysindexes&lt;br /&gt;             WHERE id = @TableID and name = @IndexName and indid &gt; 0&lt;br /&gt;            End&lt;br /&gt; OPEN index_cursor&lt;br /&gt; FETCH NEXT FROM index_cursor INTO @IndName&lt;br /&gt;&lt;br /&gt;        WHILE @@FETCH_STATUS = 0&lt;br /&gt; BEGIN&lt;br /&gt;                IF Len(@FillFactor) = 0 &lt;br /&gt;                    Begin&lt;br /&gt;                        Set @SQL  = 'DBCC DBREINDEX (' + @ObjectName + ',' + @IndName + ')'&lt;br /&gt;                    End       &lt;br /&gt;                Else&lt;br /&gt;                    Begin         &lt;br /&gt;                        Set @SQL  = 'DBCC DBREINDEX (' + @ObjectName + ',' + @IndName + ',' + @FillFactor + ')'&lt;br /&gt;                    End&lt;br /&gt;&lt;br /&gt;                    Exec (@SQL)&lt;br /&gt;&lt;br /&gt;  FETCH NEXT FROM index_cursor INTO @IndName&lt;br /&gt; &lt;br /&gt; END&lt;br /&gt;  &lt;br /&gt; CLOSE index_cursor&lt;br /&gt; DEALLOCATE index_cursor&lt;br /&gt; &lt;br /&gt; FETCH NEXT FROM table_cursor &lt;br /&gt; INTO @TableID, @ObjectName&lt;br /&gt;END&lt;br /&gt;  &lt;br /&gt;CLOSE table_cursor&lt;br /&gt;DEALLOCATE table_cursor&lt;br /&gt;&lt;br /&gt;SET NOCOUNT OFF&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6725016282509081212-1549915441658961851?l=gulappa.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gulappa.blogspot.com/feeds/1549915441658961851/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6725016282509081212&amp;postID=1549915441658961851' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/1549915441658961851'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/1549915441658961851'/><link rel='alternate' type='text/html' href='http://gulappa.blogspot.com/2007/10/stabilize-index.html' title='Stabilize Index'/><author><name>Gulappa</name><uri>http://www.blogger.com/profile/08215005201664988656</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6725016282509081212.post-7212644358667363823</id><published>2007-09-10T19:14:00.000-07:00</published><updated>2007-11-02T05:00:33.696-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='T-SQL'/><title type='text'>ClearData</title><content type='html'>We can use this sp to clear data in tables.  I mainly created this sp for two reason. 1.This is useful to commence the testing from scratch.  2.Whenever we ask the database backup from our customer.  They hesitant to give the production database because of confidential.  I have used Delete and Truncate statement to clear the data.  Please refer SQL Books online difference of Delete and Truncate statement. &lt;br /&gt;&lt;br /&gt;/* To Execute the sp &lt;br /&gt;--exec ClearTableData &lt;br /&gt;*/&lt;br /&gt;if exists (select * from sysobjects where id = object_id(N'[dbo].[ClearTableData]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)&lt;br /&gt;drop procedure [dbo].[ClearTableData]&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;Create Proc ClearTableData &lt;br /&gt;As&lt;br /&gt;&lt;br /&gt;Declare @TableName Varchar(1000), @Reference Varchar(4), @SQL Varchar(8000), @ObjectName Varchar(8000), &lt;br /&gt;        @TabName Varchar(1000)&lt;br /&gt;&lt;br /&gt;SET NOCOUNT ON&lt;br /&gt;&lt;br /&gt;If db_name() In ('master', 'model', 'msdb', 'tempdb')&lt;br /&gt;    Begin&lt;br /&gt;        Print 'system database are not allowed to clear'&lt;br /&gt;        return 0&lt;br /&gt;    End&lt;br /&gt;&lt;br /&gt;Set @ObjectName = ''&lt;br /&gt;Set @TabName = ''&lt;br /&gt;&lt;br /&gt;-- Delete data in Child Object and its Parent Object &lt;br /&gt;Begin&lt;br /&gt;    DECLARE ClearTableData_Cursor CURSOR FOR &lt;br /&gt;    Select SO.Name "ChildObject", &lt;br /&gt;            Case When (Select Count(*) From SysReferences Where rkeyid = SO.id) = 0 Then 'N' Else 'Y' End As Ref&lt;br /&gt;    From SysObjects SO, SysReferences SR, SysObjects SO1&lt;br /&gt;    Where SO.id = SR.fkeyid And SO.xtype = 'U' And SO1.ID = SR.rkeyid &lt;br /&gt;    Order By SO1.Name Desc, SO.Name &lt;br /&gt;    OPEN ClearTableData_Cursor&lt;br /&gt;  &lt;br /&gt;    FETCH NEXT FROM ClearTableData_Cursor &lt;br /&gt;    INTO @TableName, @Reference&lt;br /&gt;  &lt;br /&gt;    WHILE @@FETCH_STATUS = 0&lt;br /&gt;    BEGIN&lt;br /&gt;        If @Reference = 'Y'&lt;br /&gt;        Begin&lt;br /&gt;--    Concatenate Primary Key Table name&lt;br /&gt;            Set @ObjectName = @ObjectName + ',' + @TableName&lt;br /&gt;        End&lt;br /&gt;        Else If @Reference = 'N'&lt;br /&gt;        Begin&lt;br /&gt;            Begin&lt;br /&gt;--    Clear data from Foreign Key Tables(Child object)&lt;br /&gt;                Set @SQL = ''&lt;br /&gt;                Set @SQL = 'Truncate Table [' + @TableName + ']'&lt;br /&gt;                exec (@SQL)&lt;br /&gt;            End&lt;br /&gt;        End               &lt;br /&gt;    &lt;br /&gt;        FETCH NEXT FROM ClearTableData_Cursor &lt;br /&gt;        INTO @TableName, @Reference&lt;br /&gt;    END&lt;br /&gt;  &lt;br /&gt;    CLOSE ClearTableData_Cursor&lt;br /&gt;    DEALLOCATE ClearTableData_Cursor&lt;br /&gt;&lt;br /&gt;    If Len(@Reference) &gt; 0&lt;br /&gt;        Begin &lt;br /&gt;--    Clear data for Concatenated Primary Key Tables&lt;br /&gt;            Set @ObjectName = Right(@ObjectName,Len(@ObjectName)-1)&lt;br /&gt;&lt;br /&gt;            While Len(@ObjectName) &gt; 0&lt;br /&gt;                Begin&lt;br /&gt;                    If (CHARINDEX(',',@ObjectName) &gt; 0)&lt;br /&gt;                        Begin&lt;br /&gt;                            Set @TabName = Substring(@ObjectName, 1, CharIndex(',',@ObjectName)-1)&lt;br /&gt;                            Set @ObjectName = SUBSTRING(@ObjectName, Len(@TabName) + 2, Len(@ObjectName))&lt;br /&gt;                        End    &lt;br /&gt;                    Else&lt;br /&gt;                        Begin&lt;br /&gt;                            Set @TabName = @ObjectName&lt;br /&gt;                            Set @ObjectName = ''&lt;br /&gt;                        End&lt;br /&gt;                        Begin    &lt;br /&gt;                            Set @SQL = ''&lt;br /&gt;                            Set @SQL = 'DELETE From [' + @TabName + ']'&lt;br /&gt;                            exec (@SQL)&lt;br /&gt;                        End&lt;br /&gt;                End&lt;br /&gt;        End  &lt;br /&gt;End&lt;br /&gt;--Delete Data in Standalone Parent Object&lt;br /&gt;Begin&lt;br /&gt;    DECLARE ClearTableData_Cursor CURSOR FOR &lt;br /&gt;    Select Distinct SO.Name "ChildObject"&lt;br /&gt;    From SysObjects SO&lt;br /&gt;    Where (SO.id In (Select rkeyid From SysReferences))&lt;br /&gt;    And SO.xtype = 'U'  &lt;br /&gt;    Order By SO.Name &lt;br /&gt;    OPEN ClearTableData_Cursor&lt;br /&gt;  &lt;br /&gt;    FETCH NEXT FROM ClearTableData_Cursor &lt;br /&gt;    INTO @TableName&lt;br /&gt;  &lt;br /&gt;    WHILE @@FETCH_STATUS = 0&lt;br /&gt;    BEGIN&lt;br /&gt;        Begin&lt;br /&gt;            Set @SQL = ''&lt;br /&gt;            Set @SQL = 'DELETE From [' + @TableName + ']'&lt;br /&gt;            exec (@SQL)&lt;br /&gt;        End              &lt;br /&gt;    &lt;br /&gt;        FETCH NEXT FROM ClearTableData_Cursor &lt;br /&gt;        INTO @TableName&lt;br /&gt;    END&lt;br /&gt;  &lt;br /&gt;    CLOSE ClearTableData_Cursor&lt;br /&gt;    DEALLOCATE ClearTableData_Cursor&lt;br /&gt;End&lt;br /&gt;-- Delete data for BaseDate/Master Table&lt;br /&gt;Begin&lt;br /&gt;    DECLARE ClearTableData_Cursor CURSOR FOR &lt;br /&gt;    Select Distinct SO.Name "ChildObject"&lt;br /&gt;    From SysObjects SO&lt;br /&gt;    Where (SO.id Not In (Select rkeyid From SysReferences) And SO.id Not In (Select fkeyid From SysReferences))&lt;br /&gt;    And SO.xtype = 'U' &lt;br /&gt;    Order By SO.Name &lt;br /&gt;&lt;br /&gt;    OPEN ClearTableData_Cursor&lt;br /&gt;  &lt;br /&gt;    FETCH NEXT FROM ClearTableData_Cursor &lt;br /&gt;    INTO @TableName&lt;br /&gt;  &lt;br /&gt;    WHILE @@FETCH_STATUS = 0&lt;br /&gt;    BEGIN&lt;br /&gt;&lt;br /&gt;        Begin&lt;br /&gt;            Set @SQL = ''&lt;br /&gt;            Set @SQL = 'Truncate Table [' + @TableName + ']'&lt;br /&gt;            exec (@SQL)&lt;br /&gt;        End               &lt;br /&gt;    &lt;br /&gt;        FETCH NEXT FROM ClearTableData_Cursor &lt;br /&gt;        INTO @TableName&lt;br /&gt;    END&lt;br /&gt;  &lt;br /&gt;    CLOSE ClearTableData_Cursor&lt;br /&gt;    DEALLOCATE ClearTableData_Cursor&lt;br /&gt;End&lt;br /&gt;SET NOCOUNT OFF&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6725016282509081212-7212644358667363823?l=gulappa.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gulappa.blogspot.com/feeds/7212644358667363823/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6725016282509081212&amp;postID=7212644358667363823' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/7212644358667363823'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/7212644358667363823'/><link rel='alternate' type='text/html' href='http://gulappa.blogspot.com/2007/10/cleardata.html' title='ClearData'/><author><name>Gulappa</name><uri>http://www.blogger.com/profile/08215005201664988656</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6725016282509081212.post-5059236502119326535</id><published>2007-09-05T19:17:00.000-07:00</published><updated>2007-11-02T05:01:15.256-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='T-SQL'/><title type='text'>Convert Unique Identifier to Varchar data type</title><content type='html'>SET QUOTED_IDENTIFIER OFF&lt;br /&gt;&lt;br /&gt;DECLARE @ObjectID Int, @ObjectName Varchar(100),&lt;br /&gt; @EmptyString Char(1), @IsDefaultBound Char(1),&lt;br /&gt; @ExecuteScript Varchar(8000), @IndexName Varchar(256),&lt;br /&gt; @Loop Int&lt;br /&gt;&lt;br /&gt;set nocount on&lt;br /&gt;&lt;br /&gt;Create Table #TableInformation (ObjectID Int Not Null, ObjectName Varchar(100) Not Null, &lt;br /&gt;    Parent_ObjectID Int Not Null, Parent_ObjectName Varchar(100) Not Null,&lt;br /&gt;    ObjectType Char(2) Not Null)&lt;br /&gt;--    IsRowGuid Char(1) Not Null, IsDefaultBound Char(1) Null)&lt;br /&gt;DECLARE csrTableName CURSOR FOR &lt;br /&gt;SELECT SO.ID, SO.Name&lt;br /&gt;FROM SysObjects SO&lt;br /&gt;WHERE SO.xType = 'U' &lt;br /&gt;ORDER BY SO.Name&lt;br /&gt;&lt;br /&gt;Set @EmptyString = ''&lt;br /&gt;&lt;br /&gt;OPEN csrTableName&lt;br /&gt;&lt;br /&gt;FETCH NEXT FROM csrTableName &lt;br /&gt;INTO @ObjectID, @ObjectName&lt;br /&gt;&lt;br /&gt;PRINT @EmptyString&lt;br /&gt;&lt;br /&gt;WHILE @@FETCH_STATUS = 0&lt;br /&gt;BEGIN&lt;br /&gt;&lt;br /&gt;-- 36 = Unique Identifier data type&lt;br /&gt;&lt;br /&gt;--Generate Script to Drop Foreign Constraint &amp; Select statement will generate Foreign Key ID, Foreign Key Name, &lt;br /&gt;--Parent Object ID &amp; Name for Foreign Key and Object Type As "FK"&lt;br /&gt; Insert Into #TableInformation(ObjectID, ObjectName, Parent_ObjectID, Parent_ObjectName, ObjectType) &lt;br /&gt; Select Constid, Object_Name(Constid), fkeyid, Object_Name(fkeyid), 'C'&lt;br /&gt; From SysForeignKeys Where rkeyID = @ObjectID&lt;br /&gt; Union&lt;br /&gt; Select Constid, Object_Name(Constid), fkeyid, Object_Name(fkeyid), 'C'&lt;br /&gt; From SysForeignKeys Where fkeyID = @ObjectID&lt;br /&gt;&lt;br /&gt;--Generate Script to Drop Primary and Unique Constraint &amp; Select statement will generate  Primary Key ID, &lt;br /&gt;--Primary Key Name, Parent Object ID &amp; Name for Primary Key and Object Type As "PK"&lt;br /&gt; Insert Into #TableInformation(ObjectID, ObjectName, Parent_ObjectID, Parent_ObjectName, ObjectType) &lt;br /&gt; Select ID, Object_Name(ID), @ObjectID, @ObjectName, 'C'&lt;br /&gt; From SysObjects Where Parent_Obj = @ObjectID And xType In ('PK', 'UQ') &lt;br /&gt;&lt;br /&gt;--Generate Script to Default Constraint &amp; Select statement will generate Parent Object ID, Default Column Name &amp; &lt;br /&gt;--Parent Object ID &amp; Name for Default Column and Object Type As "D"&lt;br /&gt; Insert Into #TableInformation(ObjectID, ObjectName, Parent_ObjectID, Parent_ObjectName, ObjectType) &lt;br /&gt; Select cDefault, Object_Name(SC.cDefault), @ObjectID, @ObjectName, 'C' &lt;br /&gt; From SysColumns SC, SysComments SCM&lt;br /&gt; Where SC.ID = @ObjectID And SCM.ID = SC.cDefault And ObjectProperty(SC.cDefault, 'IsDefaultCnst') = 1 And&lt;br /&gt; SC.xType = 36 &lt;br /&gt;&lt;br /&gt;--Generate Script to Drop ROWGUID &amp; Select statement will generate RowGUID Column ID, RowGUID Column Name &amp; &lt;br /&gt;--Parent Object ID &amp; Name for RowGUID Column and Object Type As "RG"&lt;br /&gt; Insert Into #TableInformation(ObjectID, ObjectName, Parent_ObjectID, Parent_ObjectName, ObjectType) &lt;br /&gt; Select ID, Name, @ObjectID, @ObjectName, 'RG'&lt;br /&gt; From SysColumns Where ID = @ObjectID And Number = 0 And ColumnProperty(@ObjectID, Name, 'IsRowGuidCol') = 1&lt;br /&gt;&lt;br /&gt;--Generate Script to Alter Column to Varchar(38) &amp; Select statement will generate UniqueIdentifier Type ID, &lt;br /&gt;--UniqueIdentifier Column Name, Parent Object ID &amp; Name for UniqueIdentifier Column and Object Type As "UI"&lt;br /&gt; Insert Into #TableInformation(ObjectID, ObjectName, Parent_ObjectID, Parent_ObjectName, ObjectType) &lt;br /&gt; Select xType, Name, ID, Object_Name(ID), 'UI' &lt;br /&gt; From SysColumns Where ID = @ObjectID And xType = 36&lt;br /&gt; &lt;br /&gt;--Generate Script to UnBind Defaults for ID Column &amp; Select statement will generate Parent Object ID, &lt;br /&gt;--Default Column Name &amp; Parent Object ID &amp; Name for Default Column and Object Type As "DF"&lt;br /&gt; Insert Into #TableInformation(ObjectID, ObjectName, Parent_ObjectID, Parent_ObjectName, ObjectType) &lt;br /&gt; Select @ObjectID, SC.Name, @ObjectID, @ObjectName, 'DF'&lt;br /&gt; From SysColumns SC, SysComments SCM&lt;br /&gt; Where SC.ID = @ObjectID And SCM.ID = SC.cDefault And ObjectProperty(SC.cDefault, 'IsConstraint') = 0 And &lt;br /&gt; SC.xType = 36&lt;br /&gt;&lt;br /&gt;  Declare csrIndexName CURSOR FOR &lt;br /&gt;  Select Name From SysIndexes &lt;br /&gt;  Where ID = @ObjectID&lt;br /&gt;&lt;br /&gt;  OPEN csrIndexName&lt;br /&gt;  &lt;br /&gt;  FETCH NEXT FROM csrIndexName &lt;br /&gt;  INTO @IndexName&lt;br /&gt;  &lt;br /&gt;  WHILE @@FETCH_STATUS = 0&lt;br /&gt;  BEGIN&lt;br /&gt;   Set @Loop = 0&lt;br /&gt;   While @Loop &lt; 10&lt;br /&gt;    Begin&lt;br /&gt;     IF Exists (Select SC.Name, SC.ID From SysColumns SC, SysIndexes SI&lt;br /&gt;         Where SC.ID = SI.ID And SI.ID = @ObjectID And &lt;br /&gt;       SI.Name = @IndexName And SC.xtype = 36 And SI.Name Not Like '%_WA_%' And&lt;br /&gt;       SC.Name = Index_col(Object_Name(@ObjectID), SI.indid,@Loop))&lt;br /&gt;     Begin&lt;br /&gt;--Generate Script to drop Index &amp; Select statement will generate Parent Object ID of the Index Column, &lt;br /&gt;--IndexName, Parent Object ID &amp; Name of the Table Name, and Object Type As "I"&lt;br /&gt;      Insert Into #TableInformation(ObjectID, ObjectName, Parent_ObjectID, Parent_ObjectName, ObjectType) &lt;br /&gt;      Select @ObjectID, @IndexName, @ObjectID, @ObjectName, 'I'&lt;br /&gt;      Break&lt;br /&gt;     End    &lt;br /&gt;     Set @Loop = @Loop + 1&lt;br /&gt;    End&lt;br /&gt;    &lt;br /&gt;   FETCH NEXT FROM csrIndexName &lt;br /&gt;   INTO @IndexName&lt;br /&gt;  END&lt;br /&gt;  &lt;br /&gt;  CLOSE csrIndexName&lt;br /&gt;  DEALLOCATE csrIndexName&lt;br /&gt;  &lt;br /&gt; FETCH NEXT FROM csrTableName &lt;br /&gt; INTO @ObjectID, @ObjectName&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;CLOSE csrTableName&lt;br /&gt;DEALLOCATE csrTableName&lt;br /&gt;&lt;br /&gt;PRINT @EmptyString&lt;br /&gt; &lt;br /&gt; Select * From #TableInformation Order By ObjectType&lt;br /&gt; &lt;br /&gt; PRINT @EmptyString&lt;br /&gt;  &lt;br /&gt; DECLARE csrScript CURSOR FOR &lt;br /&gt; &lt;br /&gt;&lt;br /&gt; Select  Case  When ObjectType = 'DF' Then &lt;br /&gt;   'If Exists (Select ID From SysColumns Where ID = Object_ID("[' + Parent_ObjectName + ']") And Name = "' + ObjectName + '" And cDefault &gt; 0 )' + Char(13) + &lt;br /&gt;   'Exec sp_unbindefault "[' + Parent_ObjectName + '].' + ObjectName + '"' + Char(13) --+ 'GO' &lt;br /&gt;&lt;br /&gt;   When ObjectType = 'RG' Then &lt;br /&gt;   'If Exists (Select ID From SysColumns Where ID = Object_ID("[' + Parent_ObjectName + ']") And Number = 0 And&lt;br /&gt;   Name = "' + ObjectName + '" And ColumnProperty(Object_ID ("[' + Parent_ObjectName + ']")' + ', Name, "IsRowGuidCol") = 1 )' + Char(13) + &lt;br /&gt;   'ALTER TABLE [' + Parent_ObjectName + '] ALTER COLUMN [' + ObjectName + '] DROP ROWGUIDCOL' + Char(13) --+ 'GO' &lt;br /&gt;   &lt;br /&gt;   When ObjectType = 'C' Then &lt;br /&gt;   'If Exists (Select ID From SysObjects Where ID = Object_ID("[' + ObjectName + ']") And Parent_Obj = Object_Id("[' + Parent_ObjectName + ']"))' + Char(13) + &lt;br /&gt;   'ALTER TABLE [' + Parent_ObjectName + '] DROP CONSTRAINT [' + ObjectName + ']' + Char(13) --+ 'GO'&lt;br /&gt;   &lt;br /&gt;   When ObjectType = 'I' Then &lt;br /&gt;   'If Exists (Select ID From SysIndexes Where Name = "' + ObjectName + '" And ID = Object_Id("[' + Parent_ObjectName + ']"))' + Char(13) + &lt;br /&gt;   'DROP INDEX [' + Parent_ObjectName + '].' + ObjectName + + Char(13) --+ 'GO'&lt;br /&gt;&lt;br /&gt;   When ObjectType = 'UI' Then &lt;br /&gt;   'ALTER TABLE [' + Parent_ObjectName + '] ALTER COLUMN [' + ObjectName + '] Varchar(38)' + Char(13) --+ 'GO' &lt;br /&gt;&lt;br /&gt;  End As "Script"&lt;br /&gt; From #TableInformation Order By ObjectType&lt;br /&gt; &lt;br /&gt; Set @ExecuteScript = ''&lt;br /&gt; &lt;br /&gt; OPEN csrScript&lt;br /&gt; &lt;br /&gt; FETCH NEXT FROM csrScript &lt;br /&gt; INTO @ExecuteScript&lt;br /&gt; &lt;br /&gt; PRINT @EmptyString&lt;br /&gt; &lt;br /&gt; WHILE @@FETCH_STATUS = 0&lt;br /&gt; BEGIN&lt;br /&gt;  --Print (@ExecuteScript)&lt;br /&gt;  Exec (@ExecuteScript)&lt;br /&gt;  FETCH NEXT FROM csrScript &lt;br /&gt;  INTO @ExecuteScript&lt;br /&gt; END&lt;br /&gt; &lt;br /&gt; CLOSE csrScript&lt;br /&gt; DEALLOCATE csrScript&lt;br /&gt;&lt;br /&gt;Drop Table #TableInformation&lt;br /&gt;&lt;br /&gt;set nocount off&lt;br /&gt;&lt;br /&gt;GO&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6725016282509081212-5059236502119326535?l=gulappa.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gulappa.blogspot.com/feeds/5059236502119326535/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6725016282509081212&amp;postID=5059236502119326535' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/5059236502119326535'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/5059236502119326535'/><link rel='alternate' type='text/html' href='http://gulappa.blogspot.com/2007/10/convert-unique-identifier-to-varchar.html' title='Convert Unique Identifier to Varchar data type'/><author><name>Gulappa</name><uri>http://www.blogger.com/profile/08215005201664988656</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6725016282509081212.post-1345151699484734015</id><published>2007-09-02T20:04:00.000-07:00</published><updated>2007-11-02T05:01:47.157-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server Performance'/><title type='text'>Pros &amp; Cons of Using SELECT, Views, and Stored Procedures in SQL Server</title><content type='html'>When I first started using SQL Server as a novice, I was initially confused as to the differences between the SELECT statement, views, and stored procedures. They all seemed to perform more or less the same task (retrieve data), and I wanted to know the pros and cons of using each. &lt;br /&gt;&lt;br /&gt;Why would SQL Server offer three different options to retrieve data from database? As a developer and new DBA, I took it upon myself to learn everything I could about these options, why they may be required, and when they should be used. This article is a result of my learning and experience, and explains the differences between SELECT statements, views, and stored procedures for the DBA or developer new to SQL Server. I hope you find this article useful. &lt;br /&gt;&lt;br /&gt;As you read this article, if you choose, you can cut and paste the code into Query Analyzer I have provided in order to more fully understand and appreciate the differences between the SELECT statement, views, and stored procedures. I have divided this &lt;a href="http://www.sql-server-performance.com/articles/dba/sp_views_selects_p1.aspx"&gt;article&lt;/a&gt; into three parts to better explain this information.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6725016282509081212-1345151699484734015?l=gulappa.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gulappa.blogspot.com/feeds/1345151699484734015/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6725016282509081212&amp;postID=1345151699484734015' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/1345151699484734015'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/1345151699484734015'/><link rel='alternate' type='text/html' href='http://gulappa.blogspot.com/2007/10/pros-cons-of-using-select-views-and.html' title='Pros &amp; Cons of Using SELECT, Views, and Stored Procedures in SQL Server'/><author><name>Gulappa</name><uri>http://www.blogger.com/profile/08215005201664988656</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6725016282509081212.post-5377916763331573344</id><published>2007-08-31T20:00:00.000-07:00</published><updated>2007-11-02T05:01:47.157-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server Performance'/><title type='text'>Stored Procedure vs Triggers</title><content type='html'>Last time, I wrote an article and focussed on Using SELECT, Views and Stored Procedures in SQL Server.  I was quite glad to differentiate the three and its Pros &amp; Cons.  I was not even given much importance of Trigger not because of NO TIME.  To be honest, I was just a beginner in use of Triggers.  In this article I decided to write about Triggers and its difference with Stored Procedure.  We had a team meeting to incorporate the audit information in our organization.  &lt;br /&gt;&lt;br /&gt;After a few months, we had a debate to incorporate the audit information either in Stored Procedure or Trigger.  In the meeting, the set of team member has suggested having audit statements in Triggers and another set of team member has recommended having audit statements in Stored Procedures.  I was totally confused to take a decision.  Then, I told my team members to stop the debate.  I requested my team members to involve in R&amp;D for few days before come to the conclusion and judge the Pros &amp; Cons of the two.  This is how the article has been born to have audit information in our project.  I devoted my influence to write an article on Stored ProcedureVsTrigger and to differentiate the two and its Pros &amp; Cons.&lt;br /&gt;&lt;br /&gt;So, how do I start!  I decided to use some information from my previous article http://www.sql-server-performance.com/gv_sp_views_selects.asp.  I have introduced the characters that would be involving in the article before the initiative.  These characters would play important role in the &lt;a href="http://www.sqlservercentral.com/articles/Performance+Tuning+and+Scaling/storedprocedurevstriggers/1449/"&gt;article&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6725016282509081212-5377916763331573344?l=gulappa.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gulappa.blogspot.com/feeds/5377916763331573344/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6725016282509081212&amp;postID=5377916763331573344' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/5377916763331573344'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/5377916763331573344'/><link rel='alternate' type='text/html' href='http://gulappa.blogspot.com/2007/10/stored-procedure-vs-triggers.html' title='Stored Procedure vs Triggers'/><author><name>Gulappa</name><uri>http://www.blogger.com/profile/08215005201664988656</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6725016282509081212.post-1538817351734405666</id><published>2007-08-31T19:59:00.000-07:00</published><updated>2007-11-02T05:01:52.824-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server Performance'/><title type='text'>When To Use the Order By Clause</title><content type='html'>When I was using SQL Server, I was not using the "order by" clause properly. I always say myself that when I want the data in a particular order, I should use order by clause in select statement otherwise leave to the SQL Server. I presumed MS-SQL Server will return the data in its own order. I was not even thinking that am I using and doing correctly. In my initially days in my career, I was happy to retrieve the data and not knowing how it comes. It is the nature for the software engineers at the premature stage or using new command or tool or technology. They will not knowing properly or doing enough research of the each command before commence using the command. I would say it could be because of competition in the IT field and immature in IT field. &lt;br /&gt;&lt;br /&gt;Where do we get the word "Order?" I have heard and seen in so many places the use of "Order" word. I have come across the listed places the "Order" word used regularly.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;When an applicant applies for a student visa, visa officer will politely inform to the application order the applications and come back. &lt;br /&gt;When a procurer gives a draft to the registrar officer, officer will politely return back the draft and request to order the draft. &lt;br /&gt;Firm will display the designation in a proper order. &lt;br /&gt;Construct a house; we will clean and even the land before establishing the Pillar. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The ultimate aim is "First IN has to first come OUT" &lt;br /&gt;&lt;br /&gt;I have decided and kept in my mind that somewhere down the line in my IT career, I should know when I should use "order by" clause in the select statement. I know it will be on one FINE DAY". I will spend some time on "order by" command. That one fine day is TODAY to explore myself and find the ways to use the "order by" clause. This could be useful for a new developer and dba to SQL Server to avoid confusion on using "order by clause" and knowing when to use "order by" clause command. &lt;br /&gt;&lt;br /&gt;To come along with me in this article, I have paste the script and result of the output. Example of the script can be used in a sql server to understand completely after reading the &lt;a href="http://www.sqlservercentral.com/articles/Basic+Querying/whentousetheorderbyclause/1357/"&gt;article&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6725016282509081212-1538817351734405666?l=gulappa.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gulappa.blogspot.com/feeds/1538817351734405666/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6725016282509081212&amp;postID=1538817351734405666' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/1538817351734405666'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/1538817351734405666'/><link rel='alternate' type='text/html' href='http://gulappa.blogspot.com/2007/10/when-to-use-order-by-clause.html' title='When To Use the Order By Clause'/><author><name>Gulappa</name><uri>http://www.blogger.com/profile/08215005201664988656</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6725016282509081212.post-5212798852422761249</id><published>2007-08-15T19:16:00.000-07:00</published><updated>2007-11-02T05:01:15.256-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='T-SQL'/><title type='text'>DisplayColumnNames</title><content type='html'>This sp will return the column names for a table(s) and form a "Select Statement" for a table(s).  We can pass a table name as a parameter to display a "Select Statement" for that table. &lt;br /&gt;&lt;br /&gt;if exists (select * from sysobjects where id = object_id(N'[dbo].[spDisplayColumnName]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)&lt;br /&gt;drop procedure [dbo].[spDisplayColumnName]&lt;br /&gt;GO&lt;br /&gt;Create Proc spDisplayColumnName (@TableName Varchar(100)='') As&lt;br /&gt;--Exec spDisplayColumnName 'Account'&lt;br /&gt;--Or&lt;br /&gt;--Exec spDisplayColumnName&lt;br /&gt;Declare @ColumnName Varchar(8000), @TableID Int&lt;br /&gt;&lt;br /&gt;Set Nocount On&lt;br /&gt;&lt;br /&gt;If Len(@TableName) = 0 &lt;br /&gt; Begin  &lt;br /&gt;  DECLARE DisplayColumnName_Cursor CURSOR FOR &lt;br /&gt;  Select SO.ID From SysObjects SO Where xType = 'U' Order By SO.Name &lt;br /&gt; End&lt;br /&gt;Else&lt;br /&gt; Begin&lt;br /&gt;  If Not Exists(Select 1 From SysObjects Where ID = Object_ID(@TableName) And xType = 'U') &lt;br /&gt;   Begin&lt;br /&gt;    Print 'Passed parameter [' + @TableName + '] is not an User table' &lt;br /&gt;    Return 0&lt;br /&gt;   End&lt;br /&gt;  Else&lt;br /&gt;   Begin&lt;br /&gt;    DECLARE DisplayColumnName_Cursor CURSOR FOR &lt;br /&gt;    Select SO.ID From SysObjects SO Where ID = Object_ID(@TableName) &lt;br /&gt;    And xType = 'U' Order By SO.Name &lt;br /&gt;   End&lt;br /&gt; End&lt;br /&gt;&lt;br /&gt; OPEN DisplayColumnName_Cursor&lt;br /&gt; &lt;br /&gt; FETCH NEXT FROM DisplayColumnName_Cursor &lt;br /&gt; INTO @TableID&lt;br /&gt; &lt;br /&gt; WHILE @@FETCH_STATUS = 0&lt;br /&gt;  Begin&lt;br /&gt;   Set @ColumnName = ''&lt;br /&gt;   Select @ColumnName = @ColumnName + ', ' +Name&lt;br /&gt;   From SysColumns Where ID = @TableID&lt;br /&gt;   Order By Name&lt;br /&gt;   Print Object_Name(@TableID)&lt;br /&gt;   Select 'Select ' + Right(@ColumnName,Len(@ColumnName)-1) + ' From ' + Object_Name(@TableID)&lt;br /&gt;&lt;br /&gt;   FETCH NEXT FROM DisplayColumnName_Cursor &lt;br /&gt;   INTO @TableID&lt;br /&gt;  End&lt;br /&gt; CLOSE DisplayColumnName_Cursor&lt;br /&gt; DEALLOCATE DisplayColumnName_Cursor&lt;br /&gt; &lt;br /&gt;Set Nocount Off&lt;br /&gt;Return 0&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6725016282509081212-5212798852422761249?l=gulappa.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gulappa.blogspot.com/feeds/5212798852422761249/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6725016282509081212&amp;postID=5212798852422761249' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/5212798852422761249'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/5212798852422761249'/><link rel='alternate' type='text/html' href='http://gulappa.blogspot.com/2007/10/displaycolumnnames.html' title='DisplayColumnNames'/><author><name>Gulappa</name><uri>http://www.blogger.com/profile/08215005201664988656</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6725016282509081212.post-6695889294232239469</id><published>2007-07-23T19:55:00.000-07:00</published><updated>2007-11-02T05:01:15.256-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='T-SQL'/><title type='text'>SQL Server: Execution Plans</title><content type='html'>When I started using SQL Server, I was not using the “Show Execution Plan” properly to analyse the query. I always thought that when I compose a query, it is the best it can be; I never even think of performance on my query and I did not give much importance to looking at the “Execution Plan” on my query.  In the initial days of my career, I was happy to retrieve the data, not even knowing how it was returned to me and what sort of “Execution Plan” was used on the query. I presumed SQL Server would handle the query performance. I think it is the nature for software engineers, when starting out, or when first learning new technology, not to take the time to learn everything they really need to know before writing a code. Perhaps this is because of competition and immaturity in the IT field.&lt;br /&gt;&lt;br /&gt;Days are starting moving and data has been growing on the database file.  On one fine day, my customer was not happy with the performance on the query using the application. He has come to me with an unhappy face stating that he was spending extra time to finish his office work due to the slowness of the queries.  Initially, I told the customer to increase the system resources, like increase the hard disk in the machine as a temporary solution. Albeit, hard disk cost is cheap but it is not the permanent solution for the performance degradation in the query. He agreed in half-mind that he will do the required things from his side but he asked me to re-look and fine-tune the queries for a permanent solution instead of suggesting he keep on increasing the system resources.  I have to consider his personal opinion because customer satisfaction is important in the IT industry.  I have promised to my customer that I will re-look and fine-tune the queries.&lt;br /&gt;&lt;br /&gt;HOW?&lt;br /&gt;&lt;br /&gt;In the initial days of my career, I know the basic things in MS-SQL Server.   To be frank, I was not having any idea on my mind whilst doing promise to my customer.  But, I personally felt that I would do something to achieve the task with the help of “GOOGLE” and “BOL”.  Thanks to “GOOGLE” and “BOL”.&lt;br /&gt;&lt;br /&gt;I was reading MS-SQL books, BOL help and searching on websites.   I have heard and crossed the concept of “Show Execution Plan”.  We can set this option ON using SQL Query Analyzer.  Show Execution Plan is an important graphical tool that enables the developer and DBA to analyse, assist and optimise the query and improve the performance of the query.&lt;br /&gt;&lt;br /&gt;Show Execution Plan displays different icons for a different task.   I am mainly interested on “Table Scan”, “Index Scan” &amp; “Index Seek” &amp; “Clustered Index Scan” &amp; “Clustered Index Seek” icons in this article.   May be I could be writing in my future article on other icons.  &lt;br /&gt;&lt;br /&gt;As the days and years have moved along like a formula 1 race car, I have decided that it is time for me to fully understand how “Table Scan”, “Index Scan” &amp; “Index Seek” &amp; “Clustered Index Scan” &amp; “ClusteredIndex Seek” icons work. &lt;br /&gt;&lt;br /&gt;Now, I am ready to analyse the queries and upgrade the performance on my queries.   Before analysing the queries, a few questions have been raised in my mind.&lt;br /&gt;&lt;br /&gt;When did MS-SQL Server use “Table Scan”?&lt;br /&gt;&lt;br /&gt;When did MS-SQL Server use “Index Scan”?&lt;br /&gt;&lt;br /&gt;When did MS-SQL Server use “Index Seek”?&lt;br /&gt;&lt;br /&gt;When did MS-SQL Server use “Clustered Index Scan”?&lt;br /&gt;&lt;br /&gt;When did MS-SQL Server use “Clustered Index Seek”?&lt;br /&gt;&lt;br /&gt;I am mainly concern that in what bases MS-SQL Server would use one of this option to analyse the query.  I now have taken that time, and here is what I learned. This information should be useful to new developers and DBAs. I have decided to write this article to share my knowledge to help other to get better idea on these methods.&lt;br /&gt;&lt;br /&gt;If you like, you can read this &lt;a href="http://www.sqlservercentral.com/articles/Administering/executionplans/1345/"&gt;article&lt;/a&gt; as is, or in front of a SQL Server, following along with my exercises.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6725016282509081212-6695889294232239469?l=gulappa.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gulappa.blogspot.com/feeds/6695889294232239469/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6725016282509081212&amp;postID=6695889294232239469' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/6695889294232239469'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/6695889294232239469'/><link rel='alternate' type='text/html' href='http://gulappa.blogspot.com/2007/10/sql-server-execution-plans.html' title='SQL Server: Execution Plans'/><author><name>Gulappa</name><uri>http://www.blogger.com/profile/08215005201664988656</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6725016282509081212.post-6479432698207860745</id><published>2007-07-23T19:15:00.000-07:00</published><updated>2007-11-02T05:05:21.960-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='T-SQL'/><title type='text'>DependencyDetails</title><content type='html'>This sp will return the dependency details of the select table or all tables as a resultset.  This resultset will &lt;br /&gt;display the dependency details if it is used in &lt;br /&gt;1. select * from table or&lt;br /&gt;2. insert/delete/update dml statement or &lt;br /&gt;3. select col1, col2 from table. &lt;br /&gt;&lt;br /&gt;if exists (select * from sysobjects where id = object_id(N'[dbo].[DependencyDetails]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)&lt;br /&gt;drop procedure [dbo].[DependencyDetails]&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;Create Proc DependencyDetails (@TableName As Varchar(100)='')&lt;br /&gt;As&lt;br /&gt;&lt;br /&gt;SET NOCOUNT ON&lt;br /&gt;&lt;br /&gt;Declare @MinTableID Int, @MaxTableID Int&lt;br /&gt;&lt;br /&gt;IF Len(@TableName) = 0&lt;br /&gt; Begin&lt;br /&gt;  Select @MinTableID = Min(ID), @MaxTableID = Max(ID) From SysObjects Where xType = 'U' &lt;br /&gt; End&lt;br /&gt;Else IF Len(@TableName) &gt; 0&lt;br /&gt; Begin&lt;br /&gt;  IF Exists (Select ID From SysObjects Where Name = @TableName And xType = 'U')&lt;br /&gt;   Begin&lt;br /&gt;    Select @MinTableID = ID, @MaxTableID = ID &lt;br /&gt;    From SysObjects Where Name = @TableName And xType = 'U'&lt;br /&gt;   End&lt;br /&gt;  Else&lt;br /&gt;   Begin&lt;br /&gt;    Print 'Passed parameter [' + @TableName + '] is not an User Table'&lt;br /&gt;    Return 0&lt;br /&gt;   End&lt;br /&gt; End&lt;br /&gt;Select &lt;br /&gt; Distinct SO.Name, SO1.Name "Referred Object", 'Select *' As "Used for" &lt;br /&gt;From &lt;br /&gt; SysDepends SD, SysObjects SO, SysObjects SO1&lt;br /&gt;Where &lt;br /&gt; SO.ID = SD.DepID And &lt;br /&gt; SelAll = 1 And&lt;br /&gt; SD.ID = SO1.ID And&lt;br /&gt; SD.DepID &gt;= @MinTableID And SD.DepID &lt;= @MaxTableID&lt;br /&gt;Union &lt;br /&gt;Select &lt;br /&gt; Distinct SO.Name, SO1.Name "Referred Object", 'Insert/Update/Delete' As "Used for" &lt;br /&gt;From &lt;br /&gt; SysDepends SD, SysObjects SO, SysObjects SO1&lt;br /&gt;Where &lt;br /&gt; SO.ID = SD.DepID And &lt;br /&gt; SD.ResultObj = 1  And&lt;br /&gt; SD.ID = SO1.ID And&lt;br /&gt; SD.DepID &gt;= @MinTableID And SD.DepID &lt;= @MaxTableID&lt;br /&gt;Union &lt;br /&gt;Select &lt;br /&gt; Distinct SO.Name, SO1.Name "Referred Object", 'Selected Columns' As "Used for" &lt;br /&gt;From &lt;br /&gt; SysDepends SD, SysObjects SO, SysObjects SO1&lt;br /&gt;Where &lt;br /&gt; SO.ID = SD.DepID And &lt;br /&gt; SD.ReadObj = 1  And&lt;br /&gt; SD.ID = SO1.ID And&lt;br /&gt; SD.DepID &gt;= @MinTableID And SD.DepID &lt;= @MaxTableID&lt;br /&gt;Order By SO.Name&lt;br /&gt;&lt;br /&gt;SET NOCOUNT OFF&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6725016282509081212-6479432698207860745?l=gulappa.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gulappa.blogspot.com/feeds/6479432698207860745/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6725016282509081212&amp;postID=6479432698207860745' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/6479432698207860745'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/6479432698207860745'/><link rel='alternate' type='text/html' href='http://gulappa.blogspot.com/2007/10/dependencydetails.html' title='DependencyDetails'/><author><name>Gulappa</name><uri>http://www.blogger.com/profile/08215005201664988656</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6725016282509081212.post-1243352267453791761</id><published>2007-07-21T19:18:00.000-07:00</published><updated>2007-11-02T05:01:15.257-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='T-SQL'/><title type='text'>Replace Object Owner</title><content type='html'>This SP is used to identify and replace the owner of the database objects. This SP will give display object id, &lt;br /&gt;object name, owner id, owner name and concatenate object + owner name with brackets. SP does change the owner for the following objects. SP should available in "master" database to execute in more than one database. &lt;br /&gt;&lt;br /&gt;--$History: $ sp_ReplaceObjectOwner&lt;br /&gt;--------------------------------------------------------------------------------------------------------------------------------------------&lt;br /&gt;-- Drop Procedure&lt;br /&gt;--------------------------------------------------------------------------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;IF EXISTS (SELECT name FROM sysobjects WHERE name = 'sp_ReplaceObjectOwner' AND type = 'P')&lt;br /&gt;   DROP PROCEDURE sp_ReplaceObjectOwner&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;--------------------------------------------------------------------------------------------------------------------------------------------&lt;br /&gt;-- Create procedure &lt;br /&gt;--------------------------------------------------------------------------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;CREATE PROC sp_ReplaceObjectOwner As&lt;br /&gt;&lt;br /&gt;--------------------------------------------------------------------------------------------------------------------------------------------&lt;br /&gt;-- OBJECT NAME:  sp_ReplaceObjectOwner&lt;br /&gt;--------------------------------------------------------------------------------------------------------------------------------------------&lt;br /&gt;-- AUTHOR:  Vijayakumar G&lt;br /&gt;--------------------------------------------------------------------------------------------------------------------------------------------&lt;br /&gt;-- CREATED:  04-04-2005&lt;br /&gt;--------------------------------------------------------------------------------------------------------------------------------------------&lt;br /&gt;/* DESCRIPTION:     This SP is used to identify and replace the owner of the database objects. This SP will give display object id, &lt;br /&gt;object name, owner id, owner name and concatenate object + owner name with brackets.  SP does change the owner for the following objects.&lt;br /&gt;SP should available in "master" database to execute in more than one database.  &lt;br /&gt;1. Table&lt;br /&gt;2.  Stored Procedures&lt;br /&gt;3.  Function&lt;br /&gt;4. View&lt;br /&gt;We can later add / modify the filter condition */&lt;br /&gt;--------------------------------------------------------------------------------------------------------------------------------------------&lt;br /&gt;-- PARAMETERS:      None&lt;br /&gt;--   &lt;br /&gt;--------------------------------------------------------------------------------------------------------------------------------------------&lt;br /&gt;-- RETURNS:        0                -  success&lt;br /&gt;--                 &lt;To be Retrieves&gt;&lt;br /&gt;--                 returns from SQL Server&lt;br /&gt;--------------------------------------------------------------------------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;-- VERSION: $Revision: $   UPDATED: $Modtime: $ &lt;br /&gt;--------------------------------------------------------------------------------------------------------------------------------------------&lt;br /&gt;set nocount on&lt;br /&gt;&lt;br /&gt;DECLARE @Object_ID Int, @Object_Name Sysname, &lt;br /&gt; @Owner_ID Int, @Owner_Name Sysname, @Owner_Object_Name Sysname &lt;br /&gt;&lt;br /&gt;Declare @New_Owner_Name Sysname&lt;br /&gt;Set @New_Owner_Name = 'dbo'&lt;br /&gt;DECLARE CUR_ReplaceObjectOwner CURSOR FOR &lt;br /&gt;&lt;br /&gt;Select &lt;br /&gt; SO.ID As "Object ID", SO.Name As "Object Name", &lt;br /&gt; SO.UID As "Owner ID", SU.Name As "Owner Name",&lt;br /&gt; '[' + SU.Name + '].' + '[' + SO.Name + ']' As "Owner + Object Name"&lt;br /&gt;From &lt;br /&gt; SysObjects SO, SysUsers SU&lt;br /&gt;Where &lt;br /&gt; SO.UID = SU.UID And &lt;br /&gt; SO.xType In ('U','P', 'FN','V') And &lt;br /&gt; SO.Name Not Like '%dt_%' And &lt;br /&gt; SO.Name Not In ('syssegments', 'sysconstraints')&lt;br /&gt;Order By xType&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;OPEN CUR_ReplaceObjectOwner&lt;br /&gt;&lt;br /&gt;FETCH NEXT FROM CUR_ReplaceObjectOwner &lt;br /&gt;INTO @Object_ID, @Object_Name, @Owner_ID, @Owner_Name, @Owner_Object_Name&lt;br /&gt;&lt;br /&gt;WHILE @@FETCH_STATUS = 0&lt;br /&gt;BEGIN&lt;br /&gt; If @New_Owner_Name != @Owner_Name&lt;br /&gt; exec sp_changeobjectowner @Owner_Object_Name, @New_Owner_Name&lt;br /&gt; If @@Error != 0&lt;br /&gt; Begin&lt;br /&gt;  Return 1&lt;br /&gt; End &lt;br /&gt;   -- Get the next author.&lt;br /&gt;   FETCH NEXT FROM CUR_ReplaceObjectOwner &lt;br /&gt;   INTO @Object_ID, @Object_Name, @Owner_ID, @Owner_Name, @Owner_Object_Name&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;CLOSE CUR_ReplaceObjectOwner&lt;br /&gt;DEALLOCATE CUR_ReplaceObjectOwner&lt;br /&gt;&lt;br /&gt;set nocount off&lt;br /&gt;return 0&lt;br /&gt;&lt;br /&gt;GO&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6725016282509081212-1243352267453791761?l=gulappa.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gulappa.blogspot.com/feeds/1243352267453791761/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6725016282509081212&amp;postID=1243352267453791761' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/1243352267453791761'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6725016282509081212/posts/default/1243352267453791761'/><link rel='alternate' type='text/html' href='http://gulappa.blogspot.com/2007/10/replace-object-owner.html' title='Replace Object Owner'/><author><name>Gulappa</name><uri>http://www.blogger.com/profile/08215005201664988656</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
