<?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-342028597261074516</id><updated>2012-01-23T10:26:57.929-08:00</updated><category term='persisted'/><category term='clear'/><category term='row count'/><category term='tsql'/><category term='server configuration'/><category term='rights'/><category term='get numbers'/><category term='integration service'/><category term='dbname'/><category term='offline'/><category term='encrypted'/><category term='storage'/><category term='rdbms'/><category term='column'/><category term='grant'/><category term='dbid'/><category term='full text search'/><category term='outer join'/><category term='insert'/><category term='query'/><category term='grow'/><category term='truncate'/><category term='self join'/><category term='restore'/><category term='leap year'/><category term='location'/><category term='union'/><category term='first word'/><category term='inner join'/><category term='dbcc'/><category term='function'/><category term='seek'/><category term='shortcuts'/><category term='video'/><category term='link'/><category term='visit to lahore'/><category term='corrupted'/><category term='busiest'/><category term='jd'/><category term='2008'/><category term='generate'/><category term='backup'/><category term='difference'/><category term='offset'/><category term='tcl dcl'/><category term='table'/><category term='rebuild'/><category term='price'/><category term='clustered'/><category term='sequence'/><category term='schema'/><category term='guid'/><category term='informatica'/><category term='alter'/><category term='memory'/><category term='loginfo'/><category term='concurrency'/><category term='olap'/><category term='move'/><category term='physical file name'/><category term='scan'/><category term='int'/><category term='oracle'/><category term='visit to lahore office'/><category term='online'/><category term='not null'/><category term='split'/><category term='user databases'/><category term='ldf'/><category term='mdf'/><category term='dml'/><category term='optimization'/><category term='learners'/><category term='session'/><category term='8170'/><category term='stats'/><category term='datetime'/><category term='text files'/><category term='disable'/><category term='architecture'/><category term='consatraints'/><category term='error'/><category term='account'/><category term='sys.stats'/><category term='remove'/><category term='advantage'/><category term='label'/><category term='space'/><category term='iran'/><category term='value'/><category term='indexfile'/><category term='enable'/><category term='list'/><category term='isolation'/><category term='cache'/><category term='workflow'/><category term='dual'/><category term='powermart command prompt'/><category term='add'/><category term='visit'/><category term='sp_spaceused'/><category term='reorganize'/><category term='import'/><category term='computed'/><category term='change'/><category term='paging'/><category term='dump'/><category term='r2'/><category term='kill'/><category term='triggers'/><category term='blocking'/><category term='concatenate'/><category term='string'/><category term='shrink'/><category term='buffer'/><category term='drop'/><category term='data files'/><category term='duplicate'/><category term='delete'/><category term='log files'/><category term='comparison'/><category term='union all'/><category term='script'/><category term='versions'/><category term='pmcmd'/><category term='smalldatetime'/><category term='csv'/><category term='file'/><category term='default'/><category term='repository'/><category term='update'/><category term='recommendations'/><category term='database'/><category term='merge'/><category term='dmv'/><category term='fragmentation'/><category term='personal'/><category term='stored procedure'/><category term='without identity'/><category term='process'/><category term='tutorial'/><category term='sys'/><category term='dba'/><category term='biggest'/><category term='configure'/><category term='contained'/><category term='oltp'/><category term='target'/><category term='better'/><category term='rename'/><category term='precision'/><category term='mapping'/><category term='statements'/><category term='instance'/><category term='join'/><category term='sql server'/><category term='create'/><category term='tempdb'/><category term='column into row'/><category term='proper case'/><category term='time'/><category term='source'/><category term='nocache'/><category term='running'/><category term='sql'/><category term='identify'/><category term='identity'/><category term='history'/><category term='log'/><category term='search'/><category term='features'/><category term='index'/><category term='server'/><category term='article'/><category term='ddl'/><category term='all dbs'/><category term='data'/><category term='datawarehouse'/><category term='password'/><category term='fk'/><category term='wildcard'/><category term='expiry'/><category term='profile'/><category term='calculator'/><category term='checksum'/><title type='text'>Muhammad Abbas - DB &amp; BI Professional</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default?start-index=101&amp;max-results=100'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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>163</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-342028597261074516.post-1844348373968498096</id><published>2012-01-23T10:26:00.000-08:00</published><updated>2012-01-23T10:26:57.951-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='pmcmd'/><category scheme='http://www.blogger.com/atom/ns#' term='informatica'/><category scheme='http://www.blogger.com/atom/ns#' term='mapping'/><title type='text'>[Informatica] How to execute one or more mappings from workflow</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;There may be scenarios that you need to execute one or more mapping from eniter workflow which may contains number of mappings.&lt;br /&gt;&lt;br /&gt;Here is the way of doing that&lt;br /&gt;&lt;br /&gt;dos2unix olapjoblist.properties&lt;br /&gt;cd $INFA_HOME/bin/&lt;br /&gt;while read line&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp; do &lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; test=$( ./pmcmd starttask -sv $INTEGRATION_SERVICE -d $DOMAIN_NAME -uv INFA_USER -pv INFA_PASS -f $FOLDER_NAME -paramfile $parameterFile -w wf_olapconsolidation -wait $line)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; if [ "$?" != 0 ]; then&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # handle error&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo "Summary: Could not execute task."&lt;br /&gt;&amp;nbsp;&amp;nbsp; else&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # no error&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo "Summary: Task executed successfully."&lt;br /&gt;&amp;nbsp;&amp;nbsp; fi&lt;br /&gt;&amp;nbsp;&amp;nbsp; echo "Error Code:$?"&lt;br /&gt;&amp;nbsp;&amp;nbsp; echo "Description: $test"&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;done &amp;lt; $currentpath/olapjoblist.properties&lt;br /&gt;&lt;br /&gt;so olapjoblist.properties if a file will all the session names with it&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-1844348373968498096?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/1844348373968498096/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=1844348373968498096' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/1844348373968498096'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/1844348373968498096'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2012/01/informatica-how-to-execute-one-or-more.html' title='[Informatica] How to execute one or more mappings from workflow'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-3342292108814070722</id><published>2012-01-12T00:49:00.001-08:00</published><updated>2012-01-12T00:49:46.483-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='query'/><category scheme='http://www.blogger.com/atom/ns#' term='optimization'/><title type='text'>[Oracle] How to optimize queries - for Beginners</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div class="sect1"&gt;&lt;a href="" id="sthref504" name="sthref504"&gt;&lt;/a&gt; &lt;h2&gt;&lt;span style="color: #330099; font-family: arial, helvetica, sans-serif;"&gt;D.1 Optimizing  Single-Table Queries &lt;/span&gt;&lt;/h2&gt;To improve the performance of a query that selects rows of a table based on a  specific column value, create an index on that column. For example, the  following query performs better if the NAME column of the &lt;code&gt;EMP&lt;/code&gt; table  has an index. &lt;br /&gt;&lt;pre&gt;SELECT * &lt;br /&gt;FROM EMP &lt;br /&gt;WHERE NAME = 'Smith'; &lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;a href="" id="i631204" name="i631204"&gt;&lt;/a&gt; &lt;br /&gt;&lt;div class="sect1"&gt;&lt;a href="" id="sthref505" name="sthref505"&gt;&lt;/a&gt; &lt;h2&gt;&lt;span style="color: #330099; font-family: arial, helvetica, sans-serif;"&gt;D.2 Optimizing Join  Queries &lt;/span&gt;&lt;/h2&gt;The following can improve the performance of a join query (a query with more  than one table reference in the FROM clause). &lt;br /&gt;&lt;div class="sect2"&gt;&lt;a href="" id="sthref506" name="sthref506"&gt;&lt;/a&gt; &lt;h3&gt;&lt;span style="color: #330099; font-family: arial, helvetica, sans-serif;"&gt;D.2.1 Create an  Index on the Join Column(s) of the Inner Table &lt;/span&gt;&lt;/h3&gt;In the following example, the inner table of the join query is DEPT and the  join column of DEPT is &lt;code&gt;DEPT#&lt;/code&gt;. An index on &lt;code&gt;DEPT.DEPT#&lt;/code&gt;  improves the performance of the query. In this example, since &lt;code&gt;DEPT#&lt;/code&gt;  is the primary key of DEPT, an index is implicitly created for it. The optimizer  will detect the presence of the index and decide to use DEPT as the inner table.  In case there is also an index on EMP.WORKS_IN column the optimizer evaluates  the cost of both orders of execution;DEPT followed by EMP (where EMP is the  inner table) and EMP followed by DEPT (where DEPT is the inner table) and picks  the least expensive execution plan. &lt;br /&gt;&lt;pre&gt;SELECT e.SS#, e.NAME, d.BUDGET&lt;br /&gt;FROM EMP e, DEPT d &lt;br /&gt;WHERE e.WORKS_IN = DEPT.DEPT# &lt;br /&gt;AND e.JOB_TITLE = 'Manager'; &lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="sect2"&gt;&lt;a href="" id="sthref507" name="sthref507"&gt;&lt;/a&gt; &lt;h3&gt;&lt;span style="color: #330099; font-family: arial, helvetica, sans-serif;"&gt;D.2.2 Bypassing the  Query Optimizer &lt;/span&gt;&lt;/h3&gt;&lt;a href="" id="sthref508" name="sthref508"&gt;&lt;/a&gt;Normally optimizer picks the best  execution plan, an optimal order of tables to be joined. In case the optimizer  is not producing a good execution plan you can control the order of execution  using the HINTS feature SQL. For more information see the &lt;em&gt;Oracle9i Lite SQL  Reference&lt;/em&gt;. &lt;br /&gt;For example, if you want to select the name of each department along with the  name of its manager, you can write the query in one of two ways. In the first  example which follows, the hint &lt;code&gt;/++ordered++/&lt;/code&gt; says to do the join  in the order the tables appear in the &lt;code&gt;FROM&lt;/code&gt; clause with attempting  to optimize the join order. &lt;br /&gt;&lt;pre&gt;SELECT /++ordered++/ d.NAME, e.NAME&lt;br /&gt;FROM DEPT d, EMP e&lt;br /&gt;WHERE d.MGR = e.SS# &lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;or: &lt;br /&gt;&lt;pre&gt;SELECT /++ordered++/ d.NAME, e.NAME &lt;br /&gt;FROM EMP e, DEPT d &lt;br /&gt;WHERE d.MGR = e.SS# &lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;Suppose that there are 10 departments and 1000 employees, and that the inner  table in each query has an index on the join column. In the first query, the  first table produces 10 qualifying rows (in this case, the whole table). In the  second query, the first table produces 1000 qualifying rows. The first query  will access the EMP table 10 times and scan the DEPT table once. The second  query will scan the EMP table once but will access the DEPT table 1000 times.  Therefore the first query will perform much better. As a rule of thumb, tables  should be arranged from smallest effective number rows to largest effective  number of rows. The effective row size of a table in a query is obtained by  applying the logical conditions that are resolved entirely on that table. &lt;br /&gt;In another example, consider a query to retrieve the social security numbers  and names of employees in a given location, such as New York. According to the  sample schema, the query would have three table references in the FROM clause.  The three tables could be ordered in six different ways. Although the result is  the same regardless of which order you choose, the performance could be quite  different. &lt;br /&gt;Suppose the effective row size of the LOCATION table is small, for example  &lt;code&gt;select count(*) from LOCATION where LOC_NAME = 'New York'&lt;/code&gt; is a  small set. Based on the above rules, the LOCATION table should be the first  table in the FROM clause. There should be an index on LOCATION.LOC_NAME. Since  LOCATION must be joined with DEPT, DEPT should be the second table and there  should be an index on the LOC column of DEPT. Similarly, the third table should  be EMP and there should be an index on &lt;code&gt;EMP#&lt;/code&gt;. You could write this  query as: &lt;br /&gt;&lt;pre&gt;SELECT /++ordered++/ e.SS#, e.NAME &lt;br /&gt;FROM LOCATION l, DEPT d, EMP e &lt;br /&gt;WHERE l.LOC_NAME = 'New York' AND &lt;br /&gt;l.LOC# = d.LOC AND &lt;br /&gt;d.DEPT# = e.WORKS_IN;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;a href="" id="i631241" name="i631241"&gt;&lt;/a&gt; &lt;br /&gt;&lt;div class="sect1"&gt;&lt;a href="" id="sthref509" name="sthref509"&gt;&lt;/a&gt; &lt;h2&gt;&lt;span style="color: #330099; font-family: arial, helvetica, sans-serif;"&gt;D.3 Optimizing with  Order By and Group By Clauses &lt;/span&gt;&lt;/h2&gt;Various performance improvements have been made so that SELECT statements run  faster and consume less memory cache. Group by and Order by clauses attempt to  avoid sorting if a suitable index is available. &lt;br /&gt;&lt;div class="sect2"&gt;&lt;a href="" id="sthref510" name="sthref510"&gt;&lt;/a&gt; &lt;h3&gt;&lt;span style="color: #330099; font-family: arial, helvetica, sans-serif;"&gt;D.3.1 IN subquery  conversion &lt;/span&gt;&lt;/h3&gt;Converts IN subquery to a join when the select list in the subquery is  uniquely indexed. &lt;br /&gt;For example, the following IN subquery statement is converted to its  corresponding join statement. This assumes that c1 is the primary key of table  t2: &lt;br /&gt;&lt;pre&gt;SELECT c2 FROM t1 WHERE &lt;br /&gt;c2 IN (SELECT c1 FROM t2);&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;becomes: &lt;br /&gt;&lt;pre&gt;SELECT c2 FROM t1, t2 WHERE t1.c2 = t2.c1;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="sect2"&gt;&lt;a href="" id="sthref511" name="sthref511"&gt;&lt;/a&gt; &lt;h3&gt;&lt;span style="color: #330099; font-family: arial, helvetica, sans-serif;"&gt;D.3.2 ORDER BY  optimization with no GROUP BY &lt;/span&gt;&lt;/h3&gt;This eliminates the sorting step for an ORDER BY clause in a select statement  if ALL of the following conditions are met: &lt;br /&gt;&lt;ol start="1" type="1"&gt;&lt;li&gt; All ORDER BY columns are in ascending order or in descending order. &lt;/li&gt;&lt;li&gt; Only columns appear in the ORDER BY clause. That is, no expressions are used  in the ORDER BY clause. &lt;/li&gt;&lt;li&gt; ORDER BY columns are a prefix of some base table index. &lt;/li&gt;&lt;li&gt; The cost of accessing by the index is less than sorting the result set.  &lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;div class="sect2"&gt;&lt;a href="" id="sthref512" name="sthref512"&gt;&lt;/a&gt; &lt;h3&gt;&lt;span style="color: #330099; font-family: arial, helvetica, sans-serif;"&gt;D.3.3 GROUP BY  optimization with no ORDER BY &lt;/span&gt;&lt;/h3&gt;This eliminates the sorting step for the grouping operation if GROUP BY  columns are the prefix of some base table index. &lt;/div&gt;&lt;div class="sect2"&gt;&lt;a href="" id="sthref513" name="sthref513"&gt;&lt;/a&gt; &lt;h3&gt;&lt;span style="color: #330099; font-family: arial, helvetica, sans-serif;"&gt;D.3.4 ORDER BY  optimization with GROUP BY &lt;/span&gt;&lt;/h3&gt;When ORDER BY columns are the prefix of GROUP BY columns, and all columns are  sorted in either ascending or in descending order, the sorting step for the  query result is eliminated. If GROUP BY columns are the prefix of a base table  index, the sorting step in the grouping operation is also eliminated. &lt;/div&gt;&lt;div class="sect2"&gt;&lt;a href="" id="sthref514" name="sthref514"&gt;&lt;/a&gt; &lt;h3&gt;&lt;span style="color: #330099; font-family: arial, helvetica, sans-serif;"&gt;D.3.5 Cache subquery  results &lt;/span&gt;&lt;/h3&gt;If the optimizer determines that the number of rows returned by a subquery is  small and the query is non-correlated, then the query result will be cached in  memory for better performance. Currently the number of rows is set at 2000. For  example: &lt;br /&gt;&lt;pre&gt;select * from t1 where &lt;br /&gt;t1.c1 = (select sum(salary) &lt;br /&gt;from t2 where t2.deptno = 100);&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-3342292108814070722?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/3342292108814070722/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=3342292108814070722' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/3342292108814070722'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/3342292108814070722'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2012/01/oracle-how-to-optimize-queries-for.html' title='[Oracle] How to optimize queries - for Beginners'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-4086352013483889210</id><published>2011-12-12T08:18:00.000-08:00</published><updated>2011-12-12T08:18:16.010-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='nocache'/><category scheme='http://www.blogger.com/atom/ns#' term='sequence'/><category scheme='http://www.blogger.com/atom/ns#' term='cache'/><category scheme='http://www.blogger.com/atom/ns#' term='oracle'/><title type='text'>[Oracle] While creating a sequence, what does cache and nocache options mean?</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;One common question about sequences is:&lt;br /&gt;&lt;strong&gt;Question&lt;/strong&gt;: While creating a sequence, what does  &lt;strong&gt;cache&lt;/strong&gt; and &lt;strong&gt;nocache&lt;/strong&gt; options mean? For example,  you could create a sequence with a cache of 20 as follows:&lt;br /&gt;&lt;blockquote class="jive-quote"&gt; CREATE SEQUENCE supplier_seq&lt;br /&gt;MINVALUE 1&lt;br /&gt;START WITH 1&lt;br /&gt;INCREMENT BY  1&lt;br /&gt;CACHE 20;&lt;/blockquote&gt;&lt;div style="height: 8pt; min-height: 8pt; padding: 0px;"&gt; &lt;/div&gt;Or you could create the same sequence with the nocache option:&lt;br /&gt;&lt;blockquote class="jive-quote"&gt; CREATE SEQUENCE supplier_seq&lt;br /&gt;MINVALUE 1&lt;br /&gt;START WITH 1&lt;br /&gt;INCREMENT BY  1&lt;br /&gt;NOCACHE;&lt;/blockquote&gt;&lt;div style="height: 8pt; min-height: 8pt; padding: 0px;"&gt; &lt;/div&gt;&lt;strong&gt;Answer&lt;/strong&gt;: With respect to a sequence, the &lt;em&gt;cache&lt;/em&gt;  option specifies how many sequence values will be stored in memory for faster  access.&lt;br /&gt;The downside of creating a sequence with a cache is that if a system failure  occurs, all cached sequence values that have &lt;strong&gt;not&lt;/strong&gt; be used, will  be "lost". This results in a "gap" in the assigned sequence values. When the  system comes back up, Oracle will cache new numbers from where it left off in  the sequence, ignoring the so called "lost" sequence values.&lt;br /&gt;&lt;blockquote class="jive-quote"&gt; Note: To recover the lost sequence values, you can always execute an ALTER  SEQUENCE command to reset the counter to the correct value.&lt;/blockquote&gt;&lt;em&gt;Nocache&lt;/em&gt; means that none of the sequence values are stored in memory.  This option may sacrifice some performance, however, you should not encounter a  gap in the assigned sequence values.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-4086352013483889210?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/4086352013483889210/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=4086352013483889210' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/4086352013483889210'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/4086352013483889210'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/12/oracle-while-creating-sequence-what.html' title='[Oracle] While creating a sequence, what does cache and nocache options mean?'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-3216517015942996642</id><published>2011-12-12T05:20:00.000-08:00</published><updated>2011-12-12T05:20:41.285-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='schema'/><category scheme='http://www.blogger.com/atom/ns#' term='disable'/><category scheme='http://www.blogger.com/atom/ns#' term='triggers'/><category scheme='http://www.blogger.com/atom/ns#' term='enable'/><category scheme='http://www.blogger.com/atom/ns#' term='oracle'/><title type='text'>[Oracle] Enable / Disable all triggers in Schema</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div class="jive-rendered-content"&gt; &lt;strong&gt;Disable Triggers&lt;/strong&gt;&lt;br /&gt;&lt;div style="height: 8pt; min-height: 8pt; padding: 0px;"&gt; &lt;/div&gt;BEGIN&lt;br /&gt;FOR i IN (SELECT trigger_name&lt;br /&gt;FROM user_triggers) LOOP&lt;br /&gt;&lt;div style="height: 8pt; min-height: 8pt; padding: 0px;"&gt; &lt;/div&gt;EXECUTE IMMEDIATE 'ALTER TRIGGER ' || i.trigger_name || ' DISABLE';&lt;br /&gt;&lt;div style="height: 8pt; min-height: 8pt; padding: 0px;"&gt; &lt;/div&gt;END LOOP;&lt;br /&gt;END;&lt;br /&gt;/&lt;span id="mce_marker"&gt; &lt;/span&gt;&lt;br /&gt;&lt;div style="height: 8pt; min-height: 8pt; padding: 0px;"&gt; &lt;/div&gt;&lt;div style="height: 8pt; min-height: 8pt; padding: 0px;"&gt; &lt;/div&gt;&lt;strong&gt;Enable Triggers&lt;/strong&gt;&lt;br /&gt;&lt;div style="height: 8pt; min-height: 8pt; padding: 0px;"&gt; &lt;/div&gt;BEGIN&lt;br /&gt;FOR i IN (SELECT trigger_name&lt;br /&gt;FROM user_triggers) LOOP&lt;br /&gt;&lt;div style="height: 8pt; min-height: 8pt; padding: 0px;"&gt; &lt;/div&gt;EXECUTE IMMEDIATE 'ALTER TRIGGER ' || i.trigger_name || ' ENABLE';&lt;br /&gt;&lt;div style="height: 8pt; min-height: 8pt; padding: 0px;"&gt; &lt;/div&gt;END LOOP;&lt;br /&gt;END;&lt;br /&gt;/&lt;/div&gt;&lt;!-- [DocumentBodyEnd:9d92ec53-1201-4237-b495-4e0108009d9e] --&gt;&lt;!-- BEGIN attachments --&gt;&lt;!-- END attachments --&gt;&lt;!-- BEGIN content details --&gt; &lt;br /&gt;&lt;br /&gt;&lt;div id="jive-comment-post-block" sizcache="137" sizset="10" style="display: none;"&gt; &lt;form action="javascript:void(0);" class="sammy-app-1323695961872-88-" jquery1323695961439="390" method="post" name="jive-comment-post-form" sizcache="137" sizset="10"&gt; &lt;div class="jive-error-text" id="jive-comment-error" style="display: none;"&gt;&lt;/div&gt;&lt;div sizcache="137" sizset="10"&gt;&lt;textarea class="jive-comment-textarea" id="wysiwygtext" name="commentBody" rows="10"&gt;&lt;/textarea&gt;  &lt;/div&gt;&lt;div class="jive-blog-comment-preview" id="jive-blog-comment-preview" style="display: none;"&gt;&lt;/div&gt;&lt;div class="jive-form-buttons" sizcache="137" sizset="11"&gt;&lt;input name="post" type="submit" value="Add Comment" /&gt; &lt;input name="cancel" type="button" value="Cancel" /&gt; &lt;/div&gt;&lt;/form&gt;&lt;/div&gt;&lt;br /&gt;&lt;div id="jive-comment-edit-block" sizcache="137" sizset="13" style="display: none;"&gt; &lt;form action="javascript:void(0);" class="sammy-app-1323695961872-88-" jquery1323695961439="392" method="post" name="jive-comment-edit-form" sizcache="137" sizset="13"&gt; &lt;div class="jive-error-text" id="jive-comment-error" style="display: none;"&gt;&lt;/div&gt;&lt;div class="jive-comment-post-anonymous" sizcache="137" sizset="13"&gt; &lt;div sizcache="137" sizset="13"&gt;&lt;input name="name" /&gt; &lt;label for="name"&gt;Name  &lt;span&gt;(required)&lt;/span&gt;&lt;/label&gt; &lt;/div&gt;&lt;div sizcache="137" sizset="14"&gt;&lt;input name="email" /&gt; &lt;label for="email"&gt;Email  Address &lt;span&gt;(required, will not be published)&lt;/span&gt;&lt;/label&gt; &lt;/div&gt;&lt;div sizcache="137" sizset="15"&gt;&lt;input name="url" /&gt; &lt;label for="url"&gt;Website  Address&lt;/label&gt; &lt;/div&gt;&lt;/div&gt;&lt;div sizcache="137" sizset="16"&gt;&lt;textarea class="jive-comment-textarea" id="wysiwygtext" name="commentBody" rows="10"&gt;&amp;lt;%= commentBody %&amp;gt;&lt;/textarea&gt;  &lt;/div&gt;&lt;div class="jive-blog-comment-preview" id="jive-blog-comment-preview" style="display: none;"&gt;&lt;/div&gt;&lt;div class="jive-form-buttons" sizcache="137" sizset="17"&gt;&lt;input name="post" type="button" value="Save" /&gt; &lt;input name="cancel" type="button" value="Cancel" /&gt; &lt;/div&gt;&lt;/form&gt;&lt;/div&gt;&lt;form action="/blogs-delete-post!execute.jspa" class="sammy-app-1323695961872-88-" id="blogPostDelete" jquery1323695961439="394" method="post" sizcache="137" sizset="19"&gt;&lt;input name="blogPost" type="hidden" value="1639" /&gt; &lt;input name="blog" type="hidden" value="1386" /&gt; &lt;input name="jive.token.name" type="hidden" value="blogpost.delete.1639" /&gt; &lt;input name="blogpost.delete.1639" type="hidden" value="1323437290659-LPVR4EA7WFWKRFD5GTDVSBZKY40QVZPU" /&gt; &lt;/form&gt;&lt;script type="text/javascript"&gt;                    function deletePost() {                        var confirmDelete = confirm('Are you sure you want to delete this post?');                        if (confirmDelete) {                            $j('#blogPostDelete').submit()                        }                    }            &lt;/script&gt; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-3216517015942996642?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/3216517015942996642/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=3216517015942996642' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/3216517015942996642'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/3216517015942996642'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/12/oracle-enable-disable-all-triggers-in.html' title='[Oracle] Enable / Disable all triggers in Schema'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-8721862380410855034</id><published>2011-11-29T04:27:00.000-08:00</published><updated>2011-11-29T04:27:03.130-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='query'/><category scheme='http://www.blogger.com/atom/ns#' term='log'/><category scheme='http://www.blogger.com/atom/ns#' term='oracle'/><title type='text'>[Oracle] How to see last sql statements executed</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Recently we get into scenario where we need to see that which sql statements  are being executed by activity upload.&lt;br /&gt;&lt;br /&gt;&lt;div style="height: 8pt; min-height: 8pt; padding: 0px;"&gt; &lt;/div&gt;&lt;br /&gt;So here is an easy way to do this:&lt;br /&gt;&lt;br /&gt;&lt;div style="height: 8pt; min-height: 8pt; padding: 0px;"&gt; &lt;/div&gt;&lt;br /&gt;select sql_text from v$sql where rownum&amp;lt;=100 and  parsing_schema_name='NC_SDA_1_301';&lt;br /&gt;&lt;br /&gt;&lt;div style="height: 8pt; min-height: 8pt; padding: 0px;"&gt; &lt;/div&gt;&lt;br /&gt;Parsing Schema Name ; should be your schema name for which you need to see  the sql statements executed on.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-8721862380410855034?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/8721862380410855034/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=8721862380410855034' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/8721862380410855034'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/8721862380410855034'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/11/oracle-how-to-see-last-sql-statements.html' title='[Oracle] How to see last sql statements executed'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-6401573890041528361</id><published>2011-11-24T09:42:00.000-08:00</published><updated>2011-11-24T09:42:15.365-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='consatraints'/><category scheme='http://www.blogger.com/atom/ns#' term='alter'/><category scheme='http://www.blogger.com/atom/ns#' term='disable'/><category scheme='http://www.blogger.com/atom/ns#' term='ddl'/><category scheme='http://www.blogger.com/atom/ns#' term='enable'/><category scheme='http://www.blogger.com/atom/ns#' term='table'/><category scheme='http://www.blogger.com/atom/ns#' term='database'/><title type='text'>[Oracle] Enable / Disable all constraints in DB</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span style="font-size: 12pt;"&gt;&lt;strong&gt;Disable  Constraints:&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="height: 8pt; min-height: 8pt; padding: 0px;"&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="line-height: normal;"&gt;BEGIN &lt;/div&gt;&lt;br /&gt;&lt;div style="line-height: normal;"&gt;FOR c IN &lt;/div&gt;&lt;br /&gt;&lt;div style="line-height: normal;"&gt;(SELECT c.owner, c.table_name, c.constraint_name  &lt;/div&gt;&lt;br /&gt;&lt;div style="line-height: normal;"&gt;FROM user_constraints c, user_tables t &lt;/div&gt;&lt;br /&gt;&lt;div style="line-height: normal;"&gt;WHERE c.table_name = t.table_name &lt;/div&gt;&lt;br /&gt;&lt;div style="line-height: normal;"&gt;AND c.status = 'ENABLED' &lt;/div&gt;&lt;br /&gt;&lt;div style="line-height: normal;"&gt;ORDER BY c.constraint_type DESC) &lt;/div&gt;&lt;br /&gt;&lt;div style="line-height: normal;"&gt;LOOP &lt;/div&gt;&lt;br /&gt;&lt;div style="line-height: normal;"&gt;dbms_utility.exec_ddl_statement('alter table '  || c.owner || '.' || c.table_name || ' disable constraint ' ||  c.constraint_name); &lt;/div&gt;&lt;br /&gt;&lt;div style="line-height: normal;"&gt;END LOOP; &lt;/div&gt;&lt;br /&gt;&lt;div style="line-height: normal;"&gt;END;&lt;/div&gt;&lt;br /&gt;&lt;div style="height: 8pt; min-height: 8pt; padding: 0px;"&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="line-height: normal;"&gt;&lt;span style="font-size: 12pt;"&gt;&lt;strong&gt;Enable  Constraints:&lt;/strong&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="height: 8pt; min-height: 8pt; padding: 0px;"&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="line-height: normal;"&gt;BEGIN &lt;/div&gt;&lt;br /&gt;&lt;div style="line-height: normal;"&gt;FOR c IN &lt;/div&gt;&lt;br /&gt;&lt;div style="line-height: normal;"&gt;(SELECT c.owner, c.table_name, c.constraint_name  &lt;/div&gt;&lt;br /&gt;&lt;div style="line-height: normal;"&gt;FROM user_constraints c, user_tables t &lt;/div&gt;&lt;br /&gt;&lt;div style="line-height: normal;"&gt;WHERE c.table_name = t.table_name &lt;/div&gt;&lt;br /&gt;&lt;div style="line-height: normal;"&gt;AND c.status = 'DISABLED' &lt;/div&gt;&lt;br /&gt;&lt;div style="line-height: normal;"&gt;ORDER BY c.constraint_type) &lt;/div&gt;&lt;br /&gt;&lt;div style="line-height: normal;"&gt;LOOP &lt;/div&gt;&lt;br /&gt;&lt;div style="line-height: normal;"&gt;dbms_utility.exec_ddl_statement('alter table '  || c.owner || '.' || c.table_name || ' enable constraint ' ||  c.constraint_name); &lt;/div&gt;&lt;br /&gt;&lt;div style="line-height: normal;"&gt;END LOOP; &lt;/div&gt;&lt;br /&gt;&lt;div style="line-height: normal;"&gt;END;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-6401573890041528361?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/6401573890041528361/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=6401573890041528361' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/6401573890041528361'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/6401573890041528361'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/11/oracle-enable-disable-all-constraints.html' title='[Oracle] Enable / Disable all constraints in DB'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-7249788185219566823</id><published>2011-10-25T22:23:00.000-07:00</published><updated>2011-10-25T22:23:50.462-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='server'/><category scheme='http://www.blogger.com/atom/ns#' term='instance'/><title type='text'>[T-SQL] Change SQL Server instance name</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span style="font-family: inherit;"&gt;&lt;span class="content"&gt;&lt;span class="block" style="margin-left: 0px !important;"&gt;&lt;code class="plain"&gt;EXEC sp_dropserver 'Old Server Name' &lt;/code&gt;&lt;/span&gt;&lt;/span&gt; &lt;/span&gt;&lt;br /&gt;&lt;div class="line alt2"&gt;&lt;span class="content"&gt;&lt;span class="block" style="margin-left: 0px !important;"&gt;&lt;code class="plain"&gt;&lt;span style="font-family: inherit;"&gt;EXEC  sp_addserver 'New Server Name','local' &lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="font-family: inherit;"&gt; &lt;span class="content"&gt;&lt;span class="block" style="margin-left: 0px !important;"&gt;&lt;code class="plain"&gt;GO&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="content"&gt;&lt;span class="block" style="margin-left: 0px !important;"&gt;&lt;code class="plain"&gt;&lt;span style="font-family: inherit;"&gt;Then restart the SQL service and confirm the new server name with @@SERVERNAME.&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-7249788185219566823?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/7249788185219566823/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=7249788185219566823' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/7249788185219566823'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/7249788185219566823'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/10/t-sql-change-sql-server-instance-name.html' title='[T-SQL] Change SQL Server instance name'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-7996415678083440126</id><published>2011-09-20T22:50:00.000-07:00</published><updated>2011-09-20T22:51:01.035-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='query'/><category scheme='http://www.blogger.com/atom/ns#' term='update'/><category scheme='http://www.blogger.com/atom/ns#' term='join'/><category scheme='http://www.blogger.com/atom/ns#' term='table'/><category scheme='http://www.blogger.com/atom/ns#' term='oracle'/><title type='text'>[Oracle] Update Data in Table trough Joins</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;create table source_table&lt;br /&gt;&lt;br /&gt;(source_id&amp;nbsp;&amp;nbsp;&amp;nbsp; number primary key&lt;br /&gt;&lt;br /&gt;,s_col1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; number&lt;br /&gt;&lt;br /&gt;,s_col2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; number&lt;br /&gt;&lt;br /&gt;,s_col3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; number&lt;br /&gt;&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;create table target_table&lt;br /&gt;&lt;br /&gt;(target_id&amp;nbsp;&amp;nbsp;&amp;nbsp; number primary key&lt;br /&gt;&lt;br /&gt;,t_col1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; number&lt;br /&gt;&lt;br /&gt;,t_col2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; number&lt;br /&gt;&lt;br /&gt;,t_col3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; number&lt;br /&gt;&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;insert into source_table(source_id,s_col1,s_col2,s_col3) values (101,111,1.01,-1);&lt;br /&gt;&lt;br /&gt;insert into source_table(source_id,s_col1,s_col2,s_col3) values (102,222,2.02,-2);&lt;br /&gt;&lt;br /&gt;insert into source_table(source_id,s_col1,s_col2,s_col3) values (103,333,3.03,-3);&lt;br /&gt;&lt;br /&gt;insert into source_table(source_id,s_col1,s_col2,s_col3) values (104,444,4.04,-4);&lt;br /&gt;&lt;br /&gt;insert into source_table(source_id,s_col1,s_col2,s_col3) values (105,555,5.05,-5);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;insert into target_table(target_id,t_col1,t_col2,t_col3) values (101,null,null,null);&lt;br /&gt;&lt;br /&gt;insert into target_table(target_id,t_col1,t_col2,t_col3) values (102,null,null,null);&lt;br /&gt;&lt;br /&gt;insert into target_table(target_id,t_col1,t_col2,t_col3) values (103,null,null,null);&lt;br /&gt;&lt;br /&gt;insert into target_table(target_id,t_col1,t_col2,t_col3) values (104,null,null,null);&lt;br /&gt;&lt;br /&gt;insert into target_table(target_id,t_col1,t_col2,t_col3) values (105,null,null,null);&lt;br /&gt;&lt;br /&gt;select * from source_table;&lt;br /&gt;select * from target_table;&lt;br /&gt;&lt;br /&gt;update&lt;br /&gt;(&lt;br /&gt;&amp;nbsp;&amp;nbsp; select t_col1,t_col2,t_col3,s_col1,s_col2,s_col3&lt;br /&gt;&amp;nbsp;&amp;nbsp; from&amp;nbsp;&amp;nbsp; target_table t&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,source_table s&lt;br /&gt;&amp;nbsp;&amp;nbsp; where&amp;nbsp; t.target_id = s.source_id&lt;br /&gt;)&lt;br /&gt;set t_col1 = s_col1&lt;br /&gt;&amp;nbsp;&amp;nbsp; ,t_col2 = s_col2&lt;br /&gt;&amp;nbsp;&amp;nbsp; ,t_col3 = s_col3&lt;br /&gt;;&lt;br /&gt;select * from source_table;&lt;br /&gt;select * from target_table;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-7996415678083440126?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/7996415678083440126/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=7996415678083440126' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/7996415678083440126'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/7996415678083440126'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/09/oracle-update-data-in-table-trough.html' title='[Oracle] Update Data in Table trough Joins'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-486380463781927144</id><published>2011-08-29T23:25:00.000-07:00</published><updated>2011-08-29T23:25:00.246-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='better'/><category scheme='http://www.blogger.com/atom/ns#' term='sql server'/><category scheme='http://www.blogger.com/atom/ns#' term='rdbms'/><title type='text'>[SQLServer]  Why SQL Server is better than any other RDBMS Applications? Part 2</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;I like SQL Server because of its SIMPLICITY. I learned SQL commands  over Oracle (ah! it was too long that I used oracle and never touched it  again after being FRIENDLY with SQL :) ).&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;I like following attributes of SQL Server hence I loved this one… and  as I am trying to deep dive into technology I am being passionate  lover… :)&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;1. First thing I liked is as said its SIMPLICITY.&lt;/span&gt;&lt;/div&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;2. Easy Availability– one don’t have to pay huge bucks to make SQL Available.. he can use Express edition available free.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;3. Uncomplicated installation process – follows the same standard as of  other MS Product like MS-Office etc… that no one need special knowledge  of installation process to get ready to use SQL.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;4. Can be install on Average system – like few other RDMS, SQL do not  have special hardware requirement. so one can be benefited without  having his/her system upgraded.&lt;/span&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;5. User friendly UI. again abide to MS standard for all other application so anyone feel friendly on first visit.&lt;/span&gt;&lt;/div&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;6. Easy navigation through common shortcuts and tool box. I don’t have to  remember multiple keys to navigate.. what works in MS-Office / VS etc..  almost works in SQL as well.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;7. BOL – help documentation is easily available and more friendly to browse to get the correct help.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;8. Perfect match for all level of organizations… small firms to big enterprise to data store.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;9. Perfect suite of application – good clubbing and packaging of Database  engine, Agent Service, Notification Service, Reporting Service, Analysis Service, Integration Service.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;10. Support for Multi- Instance and side by side installation of multiple versions.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;11. Enhanced Security&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;12. Enhanced Optimizer&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;13. availability for various technologies to support high availability  like Log Shipping, Replication, Clustering, Mirroring etc..&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;14. Easy to tune up, one can easily tune up the performance with help of  wizards and additional tool like Profiler etc litle knowledge.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;15. Advancement in the technology.. like SQL Azure, CLR integration,  DAC, Intellisense (though I didnt like current intellisense but it helps  often).&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;16. Broader community –  I like the SQL community, in Fact I have  sharpened my skill through this community.. where you can easily catch  up with SQL MVP or MS SQL Team. I love dedication you guys shown up in  communities. I believe that if someone is in crisis, this community will  never let him get down with SQL.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;17. non ANSI functions in SQL are similar to other programming languages  hence feels comfortable and don’t have to dig more to find the right  function that is equivalent in something like in .net.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-family: Verdana;"&gt;SOURCE:  COPIED FROM A CONTEST - 1 RUNNER UP POST&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-486380463781927144?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/486380463781927144/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=486380463781927144' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/486380463781927144'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/486380463781927144'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/08/sqlserver-why-sql-server-is-better-than_29.html' title='[SQLServer]  Why SQL Server is better than any other RDBMS Applications? Part 2'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-3481907644156463355</id><published>2011-08-29T23:22:00.000-07:00</published><updated>2011-08-29T23:22:52.140-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='better'/><category scheme='http://www.blogger.com/atom/ns#' term='sql server'/><category scheme='http://www.blogger.com/atom/ns#' term='rdbms'/><title type='text'>[SQLServer]  Why SQL Server is better than any other RDBMS Applications? Part 1</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;SQL Server is like most RDMS systems, a database engine but what make  it better than other RDMS systems (especially SQL 2008 onwards) are new  features and other bells and whistles it comes with.&lt;br /&gt;Here are the few:&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;1. Easy integration with Microsoft Operating systems.&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;2. East integration with world’s most common database: Spreadsheet, Microsoft excel in particular and power pivot has significantly enhanced  its value.&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;3. User friendly interface&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;4. Easy to create maintenance plans.&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;5. Integrated Security (windows authentication): This definitely help  streamline server access based on Active directory policies and groups.&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;6. Mixed Authentication: Not only it gives the option to use windows  authentication, it allows other applications to authenticate based on  username and password&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;7. Disaster recovery: SQL Server is very easy to restore after a  disaster (proper backup and recovery strategy needs to be implemented)  as compared to other RDMS. All you need is File system restore followed  by system state and then restore databases from backup. I have been  involved in DR for a lot systems and doing DR on a SQL Server is much  easier than any other RDMS system. Other benefits include Failover  Clustering and Transaction Replication&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;8. Licensing: The licensing structure of SQL Server is much better as  compared to other RDMS systems. Other RDMS systems have a very complex  licensing structure which comes out to be much costly than SQL Server.&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;9. SQL Server Management Studio (SSMS): As compare to other RDMS systems tools, SSMS is the best tool for a developer or a DBA.&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;10. SQL Server Business Intelligence: Business Intelligence in SQL  Server has come a long way and has evolved so much. It is one of the  best if not the best in the market at the moment.&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;Since SQL Server Integration Services, SQL Server Analysis Services  and SQL Server Reporting Services comes with the SQL Server license,  customer doesn’t need to spend extra money on these additional tools,  instead that money can be spend on something else e.g. upgrade SAN, user  training.&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;11. Visualization&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;12. Administering and Monitoring: SQL Server 2008 R2 has really  scored high in its new administration and monitoring tools. It has made  the life of a DBA (even accidental DBA) a lot easier.&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;13. Backup Compression: Even though it is a new feature in SQL Server  2008, it has really helped companies to upgrade to the new version and  speeding a lot (if not all) of the backup operations.&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;14. Data Encryption: SQL Server 2008 provides a lot of encryption  options to encrypt data and code. Transparent Data Encryption has really  safe guarded some of the crucial data movement operations our company.&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-family: Verdana;"&gt;SOURCE: COPIED FROM A CONTEST - WINNER POST&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-3481907644156463355?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/3481907644156463355/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=3481907644156463355' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/3481907644156463355'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/3481907644156463355'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/08/sqlserver-why-sql-server-is-better-than.html' title='[SQLServer]  Why SQL Server is better than any other RDBMS Applications? Part 1'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-3491283586536578011</id><published>2011-08-26T11:14:00.000-07:00</published><updated>2011-08-26T11:14:41.144-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='value'/><category scheme='http://www.blogger.com/atom/ns#' term='calculator'/><title type='text'>[SQLServer]  SQL Server Value Calculator</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;h3&gt;Yes, you have data management options. &lt;/h3&gt;Considering a better data management solution? Consider SQL Server 2008 Enterprise to efficiently manage your business-critical applications. And with Oracle raising their prices, you can still get a solution based on SQL Server for around a third of their cost.* Do the math on SQL Server value and you’ll see the efficiencies add up. &lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;a href="http://www.microsoft.com/sqlserver/en/us/tools/value-calculator.aspx"&gt;SQL Server 2008 Value Calculator&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-3491283586536578011?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/3491283586536578011/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=3491283586536578011' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/3491283586536578011'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/3491283586536578011'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/08/sqlserver-sql-server-value-calculator.html' title='[SQLServer]  SQL Server Value Calculator'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-7413718336304229391</id><published>2011-08-17T02:43:00.000-07:00</published><updated>2011-08-17T02:43:34.377-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='create'/><category scheme='http://www.blogger.com/atom/ns#' term='contained'/><category scheme='http://www.blogger.com/atom/ns#' term='user databases'/><category scheme='http://www.blogger.com/atom/ns#' term='database'/><title type='text'>[T-SQL] Contained Database</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div style="text-align: justify;"&gt;A Contained Database is a database which contains all the necessary settings and metadata, making database easily portable to another server. This database will contain all the necessary details and will not have to depend on any server where it is installed for anything. You can take this database and move it to another server without having any worries.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;The real question is, “What about users who are connecting to this database?” Once the contained database is moved, the users are moved as well, and users who belong to the contained database will have no access outside the contained database.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;In &lt;em&gt;summary, &lt;strong&gt;“Database is now self-contained. Database which is ’contained’ will not depend on anything on the server where it is installed.”&lt;/strong&gt;&lt;/em&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Let us try out this feature on SQL Server Denali. We will do the following steps:&lt;/div&gt;&lt;ol style="text-align: justify;"&gt;&lt;li&gt;Enable Contained Database&lt;/li&gt;&lt;li&gt;Create Contained Database&lt;/li&gt;&lt;li&gt;Create User in Contained Database&lt;/li&gt;&lt;li&gt;Try if the user can access outside      Contained Database&lt;/li&gt;&lt;/ol&gt;&lt;div style="text-align: justify;"&gt;We can do various tests on this subject; however, in this blog post we will limit out exercise to the above four points.&lt;/div&gt;&lt;h2 style="text-align: justify;"&gt;Enable Contained Database&lt;/h2&gt;&lt;div style="text-align: justify;"&gt;Run the following code on SQL Server Denali. This code will enable the settings for the contained database.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;code style="font-size: 12px;"&gt;&lt;span style="color: darkred;"&gt;sp_configure &lt;/span&gt;&lt;span style="color: red;"&gt;'show advanced options'&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;/span&gt;&lt;span style="color: black;"&gt;1&lt;br /&gt;GO&lt;/span&gt;&lt;span style="color: blue;"&gt;RECONFIGURE WITH &lt;/span&gt;&lt;span style="color: black;"&gt;OVERRIDE&lt;br /&gt;GO&lt;/span&gt;&lt;span style="color: darkred;"&gt;sp_configure &lt;/span&gt;&lt;span style="color: red;"&gt;'contained database authentication'&lt;/span&gt;&lt;span style="color: grey;"&gt;, &lt;/span&gt;&lt;span style="color: black;"&gt;1&lt;br /&gt;GO&lt;/span&gt;&lt;span style="color: blue;"&gt;RECONFIGURE WITH &lt;/span&gt;&lt;span style="color: black;"&gt;OVERRIDE&lt;br /&gt;GO&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;h2 style="text-align: justify;"&gt;Create Contained Database&lt;/h2&gt;&lt;div style="text-align: justify;"&gt;&lt;code style="font-size: 12px;"&gt;&lt;span style="color: blue;"&gt;CREATE DATABASE &lt;/span&gt;&lt;span style="color: black;"&gt;[ContainedDatabase]&lt;br /&gt;CONTAINMENT &lt;/span&gt;&lt;span style="color: blue;"&gt;= &lt;/span&gt;&lt;span style="color: black;"&gt;PARTIAL&lt;/span&gt;&lt;span style="color: blue;"&gt;ON PRIMARY&lt;/span&gt;&lt;span style="color: grey;"&gt;( &lt;/span&gt;&lt;span style="color: black;"&gt;NAME &lt;/span&gt;&lt;span style="color: blue;"&gt;= &lt;/span&gt;&lt;span style="color: red;"&gt;N'ContainedDatabase'&lt;/span&gt;&lt;span style="color: grey;"&gt;, &lt;/span&gt;&lt;span style="color: black;"&gt;FILENAME &lt;/span&gt;&lt;span style="color: blue;"&gt;= &lt;/span&gt;&lt;span style="color: red;"&gt;N'C:\ContainedDatabase.mdf'&lt;/span&gt;&lt;span style="color: grey;"&gt;)&lt;/span&gt;&lt;span style="color: magenta;"&gt;LOG &lt;/span&gt;&lt;span style="color: blue;"&gt;ON&lt;/span&gt;&lt;span style="color: grey;"&gt;( &lt;/span&gt;&lt;span style="color: black;"&gt;NAME &lt;/span&gt;&lt;span style="color: blue;"&gt;= &lt;/span&gt;&lt;span style="color: red;"&gt;N'ContainedDatabase_log'&lt;/span&gt;&lt;span style="color: grey;"&gt;, &lt;/span&gt;&lt;span style="color: black;"&gt;FILENAME &lt;/span&gt;&lt;span style="color: blue;"&gt;= &lt;/span&gt;&lt;span style="color: red;"&gt;N'C:\ContainedDatabase_log.ldf'&lt;/span&gt;&lt;span style="color: grey;"&gt;)&lt;/span&gt;&lt;span style="color: black;"&gt;GO&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;h2 style="text-align: justify;"&gt;Create User in Contained Database&lt;/h2&gt;&lt;div style="text-align: justify;"&gt;&lt;code style="font-size: 12px;"&gt;&lt;span style="color: blue;"&gt;USE &lt;/span&gt;&lt;span style="color: black;"&gt;[ContainedDatabase]&lt;br /&gt;GO&lt;/span&gt;&lt;span style="color: blue;"&gt;CREATE &lt;/span&gt;&lt;span style="color: magenta;"&gt;USER &lt;/span&gt;&lt;span style="color: black;"&gt;ContainedUser&lt;/span&gt;&lt;span style="color: blue;"&gt;WITH &lt;/span&gt;&lt;span style="color: black;"&gt;PASSWORD &lt;/span&gt;&lt;span style="color: blue;"&gt;= &lt;/span&gt;&lt;span style="color: red;"&gt;'pass@word'&lt;/span&gt;&lt;span style="color: grey;"&gt;;&lt;/span&gt;&lt;span style="color: black;"&gt;GO&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;h2 style="text-align: justify;"&gt;Try if this user can access out side Contained Database&lt;/h2&gt;&lt;div style="text-align: justify;"&gt;To test this, we will attempt to login in the database with default settings (where login database is the master).&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;img alt="" class="alignnone" height="321" src="http://www.pinaldave.com/bimg/contained1.jpg" width="426" /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;img alt="" class="alignnone" height="500" src="http://www.pinaldave.com/bimg/contained2.jpg" width="426" /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;When we attempt this, we will be not able to login in the server simply because the user does not exist at the server level.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;img alt="" class="alignnone" height="128" src="http://www.pinaldave.com/bimg/contained3.jpg" width="490" /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Now, let us try to login in the system using the username which was created in the Contained Database.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;img alt="" class="alignnone" height="500" src="http://www.pinaldave.com/bimg/contained4.jpg" width="426" /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;You will notice that the login would be successful in the server. When expanded it, the user will have access to the contained database only, and not to any other database.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;img alt="" class="alignnone" height="337" src="http://www.pinaldave.com/bimg/contained5.jpg" width="433" /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;We will tackle more about this interesting subject in the future.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Reference:&lt;strong&gt; Pinal Dave (&lt;a href="http://blog.sqlauthority.com/" target="_blank"&gt;&lt;span style="color: #384f83;"&gt;http://blog.SQLAuthority.com&lt;/span&gt;&lt;/a&gt;)&lt;/strong&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-7413718336304229391?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/7413718336304229391/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=7413718336304229391' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/7413718336304229391'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/7413718336304229391'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/08/t-sql-contained-database.html' title='[T-SQL] Contained Database'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-2300824119294278180</id><published>2011-08-02T07:20:00.000-07:00</published><updated>2011-08-02T07:20:30.810-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='wildcard'/><category scheme='http://www.blogger.com/atom/ns#' term='query'/><title type='text'>[T-SQL] Wildcard</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;h2 style="text-align: justify;"&gt;Wildcard Basics Recap&lt;/h2&gt;&lt;div style="text-align: justify;"&gt;Lets start off with something most of us know already. Most SQL folks understand the usefulness and power of the basic uses of wildcards. Using wildcards allows you to do pattern matches in a column. In this case our criteria does not want to use the = sign to find a pattern match. The operator that allows you to do approximate predicates is &lt;em&gt;LIKE&lt;/em&gt;. The LIKE operator allows you to do special relative searches to filter your result set.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;code style="font-size: 12px;"&gt;&lt;span style="color: green;"&gt;--Find all LastNames that start with the letter A&lt;/span&gt;&lt;span style="color: blue;"&gt;SELECT &lt;/span&gt;&lt;span style="color: grey;"&gt;*&lt;/span&gt;&lt;span style="color: blue;"&gt;FROM &lt;/span&gt;&lt;span style="color: black;"&gt;Employee&lt;/span&gt;&lt;span style="color: blue;"&gt;WHERE &lt;/span&gt;&lt;span style="color: black;"&gt;LastName &lt;/span&gt;&lt;span style="color: grey;"&gt;LIKE &lt;/span&gt;&lt;span style="color: red;"&gt;'A%'&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;To find everyone whose last name starts with the letter B, you need “B” to be the first letter. After the letter B you can have any number of characters. Using B% in single quotes after the LIKE operator gets all last names starting with the letter B.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;code style="font-size: 12px;"&gt;&lt;span style="color: green;"&gt;--Find all LastNames that start with the letter B&lt;/span&gt;&lt;span style="color: blue;"&gt;SELECT &lt;/span&gt;&lt;span style="color: grey;"&gt;*&lt;/span&gt;&lt;span style="color: blue;"&gt;FROM &lt;/span&gt;&lt;span style="color: black;"&gt;Employee&lt;/span&gt;&lt;span style="color: blue;"&gt;WHERE &lt;/span&gt;&lt;span style="color: black;"&gt;LastName &lt;/span&gt;&lt;span style="color: grey;"&gt;LIKE &lt;/span&gt;&lt;span style="color: red;"&gt;'B%'&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;h2 style="text-align: justify;"&gt;Wildcard ranges or set specifiers&lt;/h2&gt;&lt;div style="text-align: justify;"&gt;If you want to find all LastName values starting with the letters A or B you can use two predicates in your WHERE clause. You need to separate them with the &lt;em&gt;OR&lt;/em&gt; operator.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;code style="font-size: 12px;"&gt;&lt;span style="color: green;"&gt;--Find all LastNames that start with the letter B&lt;/span&gt;&lt;span style="color: blue;"&gt;SELECT &lt;/span&gt;&lt;span style="color: grey;"&gt;*&lt;/span&gt;&lt;span style="color: blue;"&gt;FROM &lt;/span&gt;&lt;span style="color: black;"&gt;Employee&lt;/span&gt;&lt;span style="color: blue;"&gt;WHERE &lt;/span&gt;&lt;span style="color: black;"&gt;LastName &lt;/span&gt;&lt;span style="color: grey;"&gt;LIKE &lt;/span&gt;&lt;span style="color: red;"&gt;'A%'&lt;/span&gt;&lt;span style="color: grey;"&gt;OR &lt;/span&gt;&lt;span style="color: black;"&gt;LastName &lt;/span&gt;&lt;span style="color: grey;"&gt;LIKE &lt;/span&gt;&lt;span style="color: red;"&gt;'B%'&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Finding names beginning with A or B is easy. How about the registration desk example where want the names ranging from A-K? This works well until you want a range of A-K as in the example below:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;code style="font-size: 12px;"&gt;&lt;span style="color: green;"&gt;--Find all LastNames ranging from A-K&lt;/span&gt;&lt;span style="color: blue;"&gt;SELECT &lt;/span&gt;&lt;span style="color: grey;"&gt;*&lt;/span&gt;&lt;span style="color: blue;"&gt;FROM &lt;/span&gt;&lt;span style="color: black;"&gt;Employee&lt;/span&gt;&lt;span style="color: blue;"&gt;WHERE &lt;/span&gt;&lt;span style="color: black;"&gt;LastName &lt;/span&gt;&lt;span style="color: grey;"&gt;LIKE &lt;/span&gt;&lt;span style="color: red;"&gt;'A%'&lt;/span&gt;&lt;span style="color: grey;"&gt;OR &lt;/span&gt;&lt;span style="color: black;"&gt;LastName &lt;/span&gt;&lt;span style="color: grey;"&gt;LIKE &lt;/span&gt;&lt;span style="color: red;"&gt;'B%'&lt;/span&gt;&lt;span style="color: grey;"&gt;OR &lt;/span&gt;&lt;span style="color: black;"&gt;LastName &lt;/span&gt;&lt;span style="color: grey;"&gt;LIKE &lt;/span&gt;&lt;span style="color: red;"&gt;'C%'&lt;/span&gt;&lt;span style="color: grey;"&gt;OR &lt;/span&gt;&lt;span style="color: black;"&gt;LastName &lt;/span&gt;&lt;span style="color: grey;"&gt;LIKE &lt;/span&gt;&lt;span style="color: red;"&gt;'D%'&lt;/span&gt;&lt;span style="color: grey;"&gt;OR &lt;/span&gt;&lt;span style="color: black;"&gt;LastName &lt;/span&gt;&lt;span style="color: grey;"&gt;LIKE &lt;/span&gt;&lt;span style="color: red;"&gt;'E%'&lt;/span&gt;&lt;span style="color: grey;"&gt;OR &lt;/span&gt;&lt;span style="color: black;"&gt;LastName &lt;/span&gt;&lt;span style="color: grey;"&gt;LIKE &lt;/span&gt;&lt;span style="color: red;"&gt;'F%'&lt;/span&gt;&lt;span style="color: grey;"&gt;OR &lt;/span&gt;&lt;span style="color: black;"&gt;LastName &lt;/span&gt;&lt;span style="color: grey;"&gt;LIKE &lt;/span&gt;&lt;span style="color: red;"&gt;'G%'&lt;/span&gt;&lt;span style="color: grey;"&gt;OR &lt;/span&gt;&lt;span style="color: black;"&gt;LastName &lt;/span&gt;&lt;span style="color: grey;"&gt;LIKE &lt;/span&gt;&lt;span style="color: red;"&gt;'H%'&lt;/span&gt;&lt;span style="color: grey;"&gt;OR &lt;/span&gt;&lt;span style="color: black;"&gt;LastName &lt;/span&gt;&lt;span style="color: grey;"&gt;LIKE &lt;/span&gt;&lt;span style="color: red;"&gt;'I%'&lt;/span&gt;&lt;span style="color: grey;"&gt;OR &lt;/span&gt;&lt;span style="color: black;"&gt;LastName &lt;/span&gt;&lt;span style="color: grey;"&gt;LIKE &lt;/span&gt;&lt;span style="color: red;"&gt;'J%'&lt;/span&gt;&lt;span style="color: grey;"&gt;OR &lt;/span&gt;&lt;span style="color: black;"&gt;LastName &lt;/span&gt;&lt;span style="color: grey;"&gt;LIKE &lt;/span&gt;&lt;span style="color: red;"&gt;'K%'&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;The previous query does find LastName values starting from A-K. However, if you need a range of letters, the LIKE operator has many better options. We only really care about the first letter of the last name and there a several first letters that fit with what were looking for. The first letter of the last name can be A,B,C,D,E,F,G,H,I,J or K. Simply list all the choices you want for the first letter inside a set of square brackets.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;code style="font-size: 12px;"&gt;&lt;span style="color: green;"&gt;--LastNames ranging from A to K using a set of 11 letters&lt;/span&gt;&lt;span style="color: blue;"&gt;SELECT &lt;/span&gt;&lt;span style="color: grey;"&gt;*&lt;/span&gt;&lt;span style="color: blue;"&gt;FROM &lt;/span&gt;&lt;span style="color: black;"&gt;Employee&lt;/span&gt;&lt;span style="color: blue;"&gt;WHERE &lt;/span&gt;&lt;span style="color: black;"&gt;LastName &lt;/span&gt;&lt;span style="color: grey;"&gt;LIKE &lt;/span&gt;&lt;span style="color: red;"&gt;'[ABCDEFGHIJK]%'&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Square brackets with wildcards enclose ranges or sets for 1 position. In this case the first position is a set of 11 different possible letters. This is not a series of letter but a multiple choice of letters. For example this works regardless of the order you put your letters in. This code sample below does the exact same thing.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;code style="font-size: 12px;"&gt;&lt;span style="color: green;"&gt;--LastNames ranging from A to K using a set of 11 letters&lt;/span&gt;&lt;span style="color: blue;"&gt;SELECT &lt;/span&gt;&lt;span style="color: grey;"&gt;*&lt;/span&gt;&lt;span style="color: blue;"&gt;FROM &lt;/span&gt;&lt;span style="color: black;"&gt;Employee&lt;/span&gt;&lt;span style="color: blue;"&gt;WHERE &lt;/span&gt;&lt;span style="color: black;"&gt;LastName &lt;/span&gt;&lt;span style="color: grey;"&gt;LIKE &lt;/span&gt;&lt;span style="color: red;"&gt;'[KBCDEFGHIJA]%'&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Again the set is how many letters you put in the square brackets. The code below is a logical mistake where you won’t get A to K but you just get A or K for the first letter.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;code style="font-size: 12px;"&gt;&lt;span style="color: green;"&gt;--Find all LastNames starting with A or K (Mistake&lt;/span&gt;&lt;span style="color: blue;"&gt;SELECT &lt;/span&gt;&lt;span style="color: grey;"&gt;*&lt;/span&gt;&lt;span style="color: blue;"&gt;FROM &lt;/span&gt;&lt;span style="color: black;"&gt;Employee&lt;/span&gt;&lt;span style="color: blue;"&gt;WHERE &lt;/span&gt;&lt;span style="color: black;"&gt;LastName &lt;/span&gt;&lt;span style="color: grey;"&gt;LIKE &lt;/span&gt;&lt;span style="color: red;"&gt;'[AK]%'&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Since we’re looking for the first letter to be within a range  from A to K, we specify that range in square brackets. This is even easier than using a set. The wildcard after the brackets allows any number of characters after the range.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;code style="font-size: 12px;"&gt;&lt;span style="color: green;"&gt;--LastNames ranging from A to K using a range&lt;/span&gt;&lt;span style="color: blue;"&gt;SELECT &lt;/span&gt;&lt;span style="color: grey;"&gt;*&lt;/span&gt;&lt;span style="color: blue;"&gt;FROM &lt;/span&gt;&lt;span style="color: black;"&gt;Employee&lt;/span&gt;&lt;span style="color: blue;"&gt;WHERE &lt;/span&gt;&lt;span style="color: black;"&gt;LastName &lt;/span&gt;&lt;span style="color: grey;"&gt;LIKE &lt;/span&gt;&lt;span style="color: red;"&gt;'[A-K]%'&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;em&gt;Note:&lt;/em&gt; this range will not work if your LIKE was changed to an equal (=) sign. The following code will not return any records to your result set:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;code style="font-size: 12px;"&gt;&lt;span style="color: green;"&gt;--Bad query (it won’t error but returns no records)&lt;/span&gt;&lt;span style="color: blue;"&gt;SELECT &lt;/span&gt;&lt;span style="color: grey;"&gt;*&lt;/span&gt;&lt;span style="color: blue;"&gt;FROM &lt;/span&gt;&lt;span style="color: black;"&gt;Employee&lt;/span&gt;&lt;span style="color: blue;"&gt;WHERE &lt;/span&gt;&lt;span style="color: black;"&gt;LastName &lt;/span&gt;&lt;span style="color: blue;"&gt;= &lt;/span&gt;&lt;span style="color: red;"&gt;'[A-K]%'&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-2300824119294278180?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/2300824119294278180/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=2300824119294278180' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/2300824119294278180'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/2300824119294278180'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/08/t-sql-wildcard.html' title='[T-SQL] Wildcard'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-4185217355103042987</id><published>2011-07-11T23:47:00.000-07:00</published><updated>2011-07-11T23:59:55.185-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='text files'/><category scheme='http://www.blogger.com/atom/ns#' term='csv'/><category scheme='http://www.blogger.com/atom/ns#' term='learners'/><category scheme='http://www.blogger.com/atom/ns#' term='informatica'/><category scheme='http://www.blogger.com/atom/ns#' term='tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='mapping'/><category scheme='http://www.blogger.com/atom/ns#' term='source'/><category scheme='http://www.blogger.com/atom/ns#' term='workflow'/><category scheme='http://www.blogger.com/atom/ns#' term='target'/><title type='text'>[Informatica] Tutorial - Working with text files</title><content type='html'>Here is the link of video in which i have created a mapping , workflow for how to take data from one csv and transform and create another csv.&lt;br /&gt;&lt;br /&gt;http://www.youtube.com/watch?v=kbwbafnlvoc&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.screencast.com/t/UU1sDxBkcP"&gt;informatica_tutorial_textfiles&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-4185217355103042987?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/4185217355103042987/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=4185217355103042987' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/4185217355103042987'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/4185217355103042987'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/07/informatica-tutorial-working-with-text.html' title='[Informatica] Tutorial - Working with text files'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-9054340090969764145</id><published>2011-06-27T05:12:00.000-07:00</published><updated>2011-06-27T05:12:29.362-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql server'/><category scheme='http://www.blogger.com/atom/ns#' term='features'/><category scheme='http://www.blogger.com/atom/ns#' term='2008'/><title type='text'>[SQL Server] 10 reasons why SQL Server 2008 is going to rock</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="color: #6a604f; font-family: Helvetica, Arial, Geneva, sans-serif; font-size: 17px;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="font-size: 17px; margin-bottom: 1.5em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;10.&amp;nbsp;&amp;nbsp;&lt;strong style="color: #d26941; font-size: 17px; font-weight: bold; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;Plug-in model for SSMS&lt;/strong&gt;.&amp;nbsp;&amp;nbsp; SSMS 2005 also had a plug-in model, but it was not published, so the few developers that braved that environment were flying blind.&amp;nbsp; Apparently for 2008, the plug-in model will be published and a thousand add-ins will bloom.&amp;nbsp;&lt;/div&gt;&lt;div style="font-size: 17px; margin-bottom: 1.5em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;9.&amp;nbsp;&amp;nbsp;&lt;strong style="color: #d26941; font-size: 17px; font-weight: bold; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;Inline variable assignment.&lt;/strong&gt;&amp;nbsp; I often wondered why, as a language, SQL languishes behind the times.&amp;nbsp; I mean, it has barely any modern syntactic sugar.&amp;nbsp; Well, in this version, they are at least scratching the the tip of the iceberg.&amp;nbsp;&lt;/div&gt;&lt;div style="font-size: 17px; margin-bottom: 1.5em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;Instead of:&lt;/div&gt;&lt;div style="font-size: 17px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;pre class="csharpcode" style="background-color: white; color: black; font-family: Consolas, 'Courier New', Courier, monospace; font-size: small; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;span class="kwrd" style="color: blue; font-size: 13px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;DECLARE&lt;/span&gt; @myVar &lt;span class="kwrd" style="color: blue; font-size: 13px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;int&lt;/span&gt; &lt;br /&gt;&lt;span class="kwrd" style="color: blue; font-size: 13px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;SET&lt;/span&gt; @myVar = 5&lt;/pre&gt;&lt;/div&gt;&lt;div style="font-size: 17px; margin-bottom: 1.5em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;br style="font-size: 17px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /&gt;you can do it in one line:&lt;/div&gt;&lt;div style="font-size: 17px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;pre class="csharpcode" style="background-color: white; color: black; font-family: Consolas, 'Courier New', Courier, monospace; font-size: small; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;span class="kwrd" style="color: blue; font-size: 13px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;DECLARE&lt;/span&gt; @myVar &lt;span class="kwrd" style="color: blue; font-size: 13px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;int&lt;/span&gt; = 5&lt;/pre&gt;&lt;/div&gt;&lt;div style="font-size: 17px; margin-bottom: 1.5em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;br style="font-size: 17px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /&gt;Sweet.&amp;nbsp;&lt;/div&gt;&lt;div style="font-size: 17px; margin-bottom: 1.5em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;8.&amp;nbsp;&amp;nbsp;&lt;strong style="color: #d26941; font-size: 17px; font-weight: bold; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;C like math syntax&lt;/strong&gt;.&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; font-size: 17px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;SET&lt;/span&gt;&amp;nbsp;@i += 5.&amp;nbsp; Enough said.&amp;nbsp; They finally let a C# developer on the SQL team.&amp;nbsp;&lt;/div&gt;&lt;div style="font-size: 17px; margin-bottom: 1.5em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;7.&amp;nbsp;&amp;nbsp;&lt;strong style="color: #d26941; font-size: 17px; font-weight: bold; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;Auditing.&lt;/strong&gt;&amp;nbsp; It's a 10 dollar word for storing changes to your data for later review, debugging or in response to regulatory laws.&amp;nbsp; It's a thankless and a mundane task and no one is ever excited by the prospect of writing triggers to handle it.&amp;nbsp; SQL Server 2008 introduces automatic auditing, so we can now check one thing off our to do list.&lt;/div&gt;&lt;div style="font-size: 17px; margin-bottom: 1.5em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;6.&amp;nbsp;&amp;nbsp;&lt;strong style="color: #d26941; font-size: 17px; font-weight: bold; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;Compression&lt;/strong&gt;.&amp;nbsp; You may think that this feature is a waste of time, but it's not what it sounds like.&amp;nbsp; The release will offer row-level and page-level compression.&amp;nbsp; The compression mostly takes place on the metadata.&amp;nbsp; For instance, page compression will store common data for affected rows in a single place.&amp;nbsp;&lt;/div&gt;&lt;div style="font-size: 17px; margin-bottom: 1.5em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;The metadata storage for variable length fields is going to be completely crazy: they are pushing things into bits (instead of bytes).&amp;nbsp; For instance, length of the varchar will be stored in 3 bits.&amp;nbsp;&lt;/div&gt;&lt;div style="font-size: 17px; margin-bottom: 1.5em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;Anyway, I don't really care about space savings - storage is cheap.&amp;nbsp; What I do care about is that the feature promised (key word here "promises") to reduce I/O and RAM utilization, while increasing CPU utilization.&amp;nbsp; Every single performance problem I ever dealt with had to do with I/O overloading.&amp;nbsp; Will see how this plays out.&amp;nbsp; I am skeptical until I see some real world production benchmarks.&lt;/div&gt;&lt;div style="font-size: 17px; margin-bottom: 1.5em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;5.&amp;nbsp;&amp;nbsp;&lt;strong style="color: #d26941; font-size: 17px; font-weight: bold; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;Filtered Indexes.&lt;/strong&gt;&amp;nbsp; This is another feature that sounds great - will have to see how it plays out.&amp;nbsp; Anyway, it allows you to create an index while specifying what rows are not to be in the index.&amp;nbsp; For example, index all rows where Status != null.&amp;nbsp; Theoretically, it'll get rid of all the dead weight in the index, allowing for faster queries.&amp;nbsp;&lt;/div&gt;&lt;div style="font-size: 17px; margin-bottom: 1.5em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;4.&amp;nbsp;&amp;nbsp;&lt;strong style="color: #d26941; font-size: 17px; font-weight: bold; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;Resource governor.&lt;/strong&gt;&amp;nbsp; All I can say is FINALLY.&amp;nbsp; Sybase has had it since version 12 (that's last millennium, people).&amp;nbsp; Basically it allows the DBA to specify how much resources (e.g. CPU/RAM) each user is entitled to.&amp;nbsp; At the very least, it'll prevent people, with sparse SQL knowledge from shooting off a query with a Cartesian product and bringing down the box.&lt;/div&gt;&lt;div style="font-size: 17px; margin-bottom: 1.5em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;Actually Sybase is still ahead of MS on this feature.&amp;nbsp; Its ASE server allows you to prioritize one user over another - a feature that I found immensely useful.&lt;/div&gt;&lt;div style="font-size: 17px; margin-bottom: 1.5em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;3.&amp;nbsp;&amp;nbsp;&lt;strong style="color: #d26941; font-size: 17px; font-weight: bold; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;Plan freezing&lt;/strong&gt;.&amp;nbsp; This is a solution to my personal pet peeve. Sometimes SQL Server decides to change its plan on you (in response to data changes, etc...).&amp;nbsp; If you've achieved your optimal query plan, now you can stick with it.&amp;nbsp; Yeah, I know, hints are evil, but there are situations when you want to take a hammer to SQL Server - well, this is the chill pill.&lt;/div&gt;&lt;div style="font-size: 17px; margin-bottom: 1.5em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;2.&amp;nbsp;&amp;nbsp;&lt;strong style="color: #d26941; font-size: 17px; font-weight: bold; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;Processing of delimited strings.&lt;/strong&gt;&amp;nbsp;&amp;nbsp; This is awesome and I could have used this feature...well, always.&amp;nbsp; Currently, we pass in delimited strings in the following manner:&lt;/div&gt;&lt;div style="font-size: 17px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;pre class="csharpcode" style="background-color: white; color: black; font-family: Consolas, 'Courier New', Courier, monospace; font-size: small; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;span class="kwrd" style="color: blue; font-size: 13px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;exec&lt;/span&gt; sp_MySproc &lt;span class="str" style="color: #006080; font-size: 13px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;'murphy,35;galen,31;samuels,27;colton,42'&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div style="font-size: 17px; margin-bottom: 1.5em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;br style="font-size: 17px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /&gt;Then the stored proc needs to parse the string into a usable form - a mindless task.&lt;/div&gt;&lt;div style="font-size: 17px; margin-bottom: 1.5em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;In 2008, Microsoft introduced Table Value Parameters (TVP).&amp;nbsp;&lt;/div&gt;&lt;div style="font-size: 17px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;pre class="csharpcode" style="background-color: white; color: black; font-family: Consolas, 'Courier New', Courier, monospace; font-size: small; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;span class="kwrd" style="color: blue; font-size: 13px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;CREATE&lt;/span&gt; TYPE PeepsType &lt;span class="kwrd" style="color: blue; font-size: 13px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;AS&lt;/span&gt; &lt;span class="kwrd" style="color: blue; font-size: 13px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;TABLE&lt;/span&gt; (Name &lt;span class="kwrd" style="color: blue; font-size: 13px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;varchar&lt;/span&gt;(20), Age &lt;span class="kwrd" style="color: blue; font-size: 13px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;int&lt;/span&gt;) &lt;br /&gt;&lt;span class="kwrd" style="color: blue; font-size: 13px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;DECLARE&lt;/span&gt; @myPeeps PeepsType &lt;br /&gt;INSERT @myPeeps &lt;span class="kwrd" style="color: blue; font-size: 13px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;SELECT&lt;/span&gt; &lt;span class="str" style="color: #006080; font-size: 13px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;'murphy'&lt;/span&gt;, 35 &lt;br /&gt;INSERT @myPeeps &lt;span class="kwrd" style="color: blue; font-size: 13px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;SELECT&lt;/span&gt; &lt;span class="str" style="color: #006080; font-size: 13px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;'galen'&lt;/span&gt;, 31 &lt;br /&gt;INSERT @myPeeps &lt;span class="kwrd" style="color: blue; font-size: 13px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;SELECT&lt;/span&gt; &lt;span class="str" style="color: #006080; font-size: 13px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;'samuels'&lt;/span&gt;, 27 &lt;br /&gt;INSERT @myPeeps &lt;span class="kwrd" style="color: blue; font-size: 13px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;SELECT&lt;/span&gt; &lt;span class="str" style="color: #006080; font-size: 13px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;'colton'&lt;/span&gt;, 42&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd" style="color: blue; font-size: 13px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;exec&lt;/span&gt; sp_MySproc2 @myPeeps &lt;/pre&gt;&lt;/div&gt;&lt;div style="font-size: 17px; margin-bottom: 1.5em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;/div&gt;&lt;div style="font-size: 17px; margin-bottom: 1.5em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;br style="font-size: 17px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /&gt;And the sproc would look like this:&lt;/div&gt;&lt;div style="font-size: 17px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;pre class="csharpcode" style="background-color: white; color: black; font-family: Consolas, 'Courier New', Courier, monospace; font-size: small; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;span class="kwrd" style="color: blue; font-size: 13px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd" style="color: blue; font-size: 13px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;PROCEDURE&lt;/span&gt; sp_MySproc2(@myPeeps PeepsType READONLY) ...&lt;/pre&gt;&lt;/div&gt;&lt;div style="font-size: 17px; margin-bottom: 1.5em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;br style="font-size: 17px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /&gt;The advantage here is that you can treat the Table Type as a regular table, use it in joins, etc.&amp;nbsp; Say goodbye to all those string parsing routines.&lt;/div&gt;&lt;div style="font-size: 17px; margin-bottom: 1.5em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;1.&amp;nbsp;&lt;strong style="color: #d26941; font-size: 17px; font-weight: bold; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;Intellisense&lt;/strong&gt;&amp;nbsp;in the SQL Server Management Studio (SSMS).&amp;nbsp; This has been previously possible in SQL Server 2000 and 2005 with&amp;nbsp;&lt;img align="right" alt="Intellisense" border="0" height="129" src="http://angryhacker.com/blog/images/angryhacker_com/blog/WindowsLiveWriter/10reasonswhySQLServer2008isgoingtorock_13E6B/Intellisense_3.png" style="border-bottom-color: rgb(202, 202, 202); border-bottom-style: solid; border-bottom-width: 0px; border-left-color: rgb(202, 202, 202); border-left-style: solid; border-left-width: 0px; border-right-color: rgb(202, 202, 202); border-right-style: solid; border-right-width: 0px; border-top-color: rgb(202, 202, 202); border-top-style: solid; border-top-width: 0px; font-size: 17px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px;" width="295" /&gt;use of 3rd party add-ins like SQL Prompt ($195).&amp;nbsp; But these tools are a horrible hack at best (e.g. they hook into the editor window and try to interpret what the application is doing).&amp;nbsp;&amp;nbsp;&lt;br style="font-size: 17px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /&gt;&lt;/div&gt;&lt;div style="font-size: 17px; margin-bottom: 1.5em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;Built-in intellisense is huge - it means new people can easily learn the database schema as they go.&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-9054340090969764145?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/9054340090969764145/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=9054340090969764145' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/9054340090969764145'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/9054340090969764145'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/06/sql-server-10-reasons-why-sql-server.html' title='[SQL Server] 10 reasons why SQL Server 2008 is going to rock'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-374898264980682606</id><published>2011-05-27T05:18:00.000-07:00</published><updated>2011-05-27T05:18:12.494-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='visit'/><category scheme='http://www.blogger.com/atom/ns#' term='personal'/><category scheme='http://www.blogger.com/atom/ns#' term='iran'/><title type='text'>[Personal] Visit to Iran</title><content type='html'>This month i was on vacations and during vacations i visit Iran for ziarat and recreational purpose. Had an excellent time with my whole family(MashAllah).&lt;br /&gt;&lt;br /&gt;I visited following cities:&lt;br /&gt;1. Tehran&lt;br /&gt;2. Meshad&lt;br /&gt;3. Qum&lt;br /&gt;4. Miami&lt;br /&gt;&lt;br /&gt;This was my 7th visit to Iran and like always i enjoyed this trip as well, the speciality of this trip was that this time my parents were also with me.&lt;br /&gt;&lt;br /&gt;Iran is a very peaceful and beautiful country. I visited many holy shrines there some of which include Imam Reza(a.s) , Bibi Masooma Qum (s.a) , Shah Abol Azim , Hazrat Zaid shaheed and many more.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-374898264980682606?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/374898264980682606/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=374898264980682606' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/374898264980682606'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/374898264980682606'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/05/personal-visit-to-iran.html' title='[Personal] Visit to Iran'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-8425501247359233439</id><published>2011-04-20T03:18:00.001-07:00</published><updated>2011-04-20T03:18:46.123-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='video'/><category scheme='http://www.blogger.com/atom/ns#' term='informatica'/><category scheme='http://www.blogger.com/atom/ns#' term='tutorial'/><title type='text'>[Informatica] Tutorial Part 5</title><content type='html'>Here is the last session of informatica tutorial:&lt;br /&gt;&lt;br /&gt;http://www.youtube.com/watch?v=8zdPvAkMv90&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-8425501247359233439?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/8425501247359233439/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=8425501247359233439' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/8425501247359233439'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/8425501247359233439'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/04/informatica-tutorial-part-5.html' title='[Informatica] Tutorial Part 5'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-2405498909029586047</id><published>2011-04-14T23:58:00.000-07:00</published><updated>2011-04-14T23:58:55.536-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='location'/><category scheme='http://www.blogger.com/atom/ns#' term='sys'/><category scheme='http://www.blogger.com/atom/ns#' term='log files'/><category scheme='http://www.blogger.com/atom/ns#' term='data files'/><title type='text'>[T-SQL] Find current location of data and log file of all database</title><content type='html'>In general we see that some times we go trough very small queries but it has really a big impact during ongoing scenario.&lt;br /&gt;&lt;br /&gt;Here is one of the query by which you can see the location of data and log file of all the databases.&lt;br /&gt;&lt;br /&gt;SELECT name, physical_name AS current_file_location&lt;br /&gt;FROM sys.master_files&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-2405498909029586047?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/2405498909029586047/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=2405498909029586047' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/2405498909029586047'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/2405498909029586047'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/04/t-sql-find-current-location-of-data-and.html' title='[T-SQL] Find current location of data and log file of all database'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-2456896703150756161</id><published>2011-04-12T00:24:00.000-07:00</published><updated>2011-04-12T00:24:50.163-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='default'/><category scheme='http://www.blogger.com/atom/ns#' term='alter'/><category scheme='http://www.blogger.com/atom/ns#' term='not null'/><category scheme='http://www.blogger.com/atom/ns#' term='add'/><title type='text'>[T-SQL] Add new column [Not Null] column in a table already having data - Part 2</title><content type='html'>Previously i wrote an article with a method that how can we include not null column in a table already having data.&lt;br /&gt;&lt;br /&gt;But that method has number of scripts to execute. SQL Server handle it in a very good way.&lt;br /&gt;&lt;br /&gt;If you execute the script &lt;br /&gt;&lt;br /&gt;ALTER TABLE TestTable&lt;br /&gt;ADD ThirdCol INT NOT NULL DEFAULT(0)&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;Then SQL Server will itself insert the default value 0 for the rows which are already present in database.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-2456896703150756161?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/2456896703150756161/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=2456896703150756161' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/2456896703150756161'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/2456896703150756161'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/04/t-sql-add-new-column-not-null-column-in.html' title='[T-SQL] Add new column [Not Null] column in a table already having data - Part 2'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-2160299296936942465</id><published>2011-04-12T00:15:00.000-07:00</published><updated>2011-04-12T00:15:44.516-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='recommendations'/><category scheme='http://www.blogger.com/atom/ns#' term='tempdb'/><category scheme='http://www.blogger.com/atom/ns#' term='optimization'/><title type='text'>[SQLServer] TempDB Recommendations</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I was going trough a nice article , so sharing apart from it regarding the recommendations for TempDB.&lt;br /&gt;&lt;br /&gt;Source: &lt;a href="http://blogs.msdn.com/b/cindygross/archive/2009/11/20/compilation-of-sql-server-tempdb-io-best-practices.aspx"&gt;http://blogs.msdn.com/b/cindygross/archive/2009/11/20/compilation-of-sql-server-tempdb-io-best-practices.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Pre-size TempDB appropriately. Leave autogrow on with instant file initialization enabled, but try to configure the database so that it never hits an autogrow event. Make sure the autogrow growth increment is appropriate.&lt;br /&gt;&lt;br /&gt;· Follow general IO recommendations for fast IO.&lt;br /&gt;&lt;br /&gt;· If your TempDB experiences metadata contention (waitresource = 2:1:1 or 2:1:3), you should split out your data onto multiple files. Generally you will want somewhere between 1/4 and 1 file per physical core. If you don't want to wait to see if any metadata contention occurs you may want to start out with around 1/4 to 1/2 the number of data files as CPUs up to about 8 files. If you think you might need more than 8 files we should do some testing first to see what the impact is. For example, if you have 8 physical CPUs you may want to start with 2-4 data files and monitor for metadata contention. &lt;br /&gt;&lt;br /&gt;· All TempDB data files should be of equal size.&lt;br /&gt;&lt;br /&gt;· As with any database, your TempDB performance may improve if you spread it out over multiple drives. This only helps if each drive or mount point is truly a separate IO path. Whether each TempDB will have a measurable improvement from using multiple drives depends on the specific system.&lt;br /&gt;&lt;br /&gt;· In general you only need one log file. If you need to have multiple log files because you don't have enough disk space on one drive that is fine, but there is no direct benefit from having the log on multiple files or drives.&lt;br /&gt;&lt;br /&gt;· On SQL Server 2000 and more rarely on SQL Server 2005 or later you may want to enable trace flag -T1118.&lt;br /&gt;&lt;br /&gt;· Avoid shrinking TempDB (or any database) files unless you are very certain you will never need the space again.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-2160299296936942465?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/2160299296936942465/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=2160299296936942465' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/2160299296936942465'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/2160299296936942465'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/04/sqlserver-tempdb-recommendations.html' title='[SQLServer] TempDB Recommendations'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-5919898669908185520</id><published>2011-03-28T03:48:00.000-07:00</published><updated>2011-03-28T03:48:19.691-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='profile'/><category scheme='http://www.blogger.com/atom/ns#' term='expiry'/><category scheme='http://www.blogger.com/atom/ns#' term='account'/><title type='text'>[Oracle] Account Expiry</title><content type='html'>Question: How can we auto lock a schema or user in oracle.&lt;br /&gt;Ans: You can not directly lock a schema but you can lock user trough profile. First create a profile with the method defined below and then while creating user give that profile name instead of default.&lt;br /&gt;&lt;br /&gt;CREATE PROFILE prof LIMIT&lt;br /&gt;  FAILED_LOGIN_ATTEMPTS 4&lt;br /&gt;  PASSWORD_LOCK_TIME 30&lt;br /&gt;  PASSWORD_LIFE_TIME 90;&lt;br /&gt;&lt;br /&gt;ALTER USER mabbas PROFILE prof;&lt;br /&gt;&lt;br /&gt;User mabbas can use his password for 90 days before the user (or DBA) is forced to change the password.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-5919898669908185520?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/5919898669908185520/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=5919898669908185520' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/5919898669908185520'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/5919898669908185520'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/03/oracle-account-expiry.html' title='[Oracle] Account Expiry'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-4260338003000943721</id><published>2011-03-25T05:37:00.001-07:00</published><updated>2011-03-25T05:37:29.184-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='password'/><category scheme='http://www.blogger.com/atom/ns#' term='change'/><title type='text'>[T-SQL] Change SQL Server 2005 SA Password</title><content type='html'>Changing the password in SQL Server was much easier. You just type the following thing and password for the account is changed:&lt;br /&gt;&lt;br /&gt;     sp_password 'Old','New', Account&lt;br /&gt;&lt;br /&gt;But this dont work for Sql Server 2005. Initially I thought whats worng with the SQL Server, but later I realized that it may be different for the two versions. At last I found it and here it is:&lt;br /&gt;&lt;br /&gt;ALTER LOGIN Account_Name WITH&lt;br /&gt;PASSWORD = 'New_Password'&lt;br /&gt;OLD_PASSWORD = 'Old_Password';&lt;br /&gt;GO&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-4260338003000943721?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/4260338003000943721/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=4260338003000943721' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/4260338003000943721'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/4260338003000943721'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/03/t-sql-change-sql-server-2005-sa.html' title='[T-SQL] Change SQL Server 2005 SA Password'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-6618397010361996653</id><published>2011-03-17T06:25:00.000-07:00</published><updated>2011-03-17T06:25:06.763-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='video'/><category scheme='http://www.blogger.com/atom/ns#' term='learners'/><category scheme='http://www.blogger.com/atom/ns#' term='informatica'/><category scheme='http://www.blogger.com/atom/ns#' term='tutorial'/><title type='text'>[Informatica] Tutorial Part 4</title><content type='html'>Here is the third part of Informatica Tutorial Part 4.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;http://www.youtube.com/watch?v=AuCVmPpRvy4&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-6618397010361996653?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/6618397010361996653/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=6618397010361996653' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/6618397010361996653'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/6618397010361996653'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/03/informatica-tutorial-part-4.html' title='[Informatica] Tutorial Part 4'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-7779557350318820184</id><published>2011-03-08T10:14:00.000-08:00</published><updated>2011-03-08T10:14:23.073-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='isolation'/><category scheme='http://www.blogger.com/atom/ns#' term='concurrency'/><title type='text'>[T-SQL] Concurrency Issues and Isolation Level</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;There are four types of concurrency problems visible in the normal programming.&lt;br /&gt;&lt;br /&gt;1) Lost Update – This problem occurs when there are two transactions involved and both are unaware of each other. The transaction which occurs later overwrites the transactions created by the earlier update.&lt;br /&gt;&lt;br /&gt;2) Dirty Reads – This problem occurs when a transactions selects data that isn’t committed by another transaction leading to read the data which may not exists when transactions are over.&lt;br /&gt;&lt;br /&gt;Example: Transaction 1 changes the row. Transaction 2 changes the row. Transaction 1 rolls back the changes. Transaction 2 has selected the row which does not exist.&lt;br /&gt;&lt;br /&gt;3) Nonrepeatable Reads – This problem occurs when two SELECT statements of the same data results in different values because another transactions has updated the data between the two SELECT statements.&lt;br /&gt;&lt;br /&gt;Example: Transaction 1 selects a row, which is later on updated by Transaction 2. When Transaction A later on selects the row it gets different value.&lt;br /&gt;&lt;br /&gt;4) Phantom Reads – This problem occurs when UPDATE/DELETE is happening on one set of data and INSERT/UPDATE is happening on the same set of data leading inconsistent data in earlier transaction when both the transactions are over.&lt;br /&gt;&lt;br /&gt;Example: Transaction 1 is deleting 10 rows which are marked as deleting rows, during the same time Transaction 2 inserts row marked as deleted. When Transaction 1 is done deleting rows, there will be still rows marked to be deleted.&lt;br /&gt;&lt;br /&gt;When two or more transactions are updating the data, concurrency is the biggest issue. I commonly see people toying around with isolation level or locking hints (e.g. NOLOCK) etc, which can very well compromise your data integrity leading to much larger issue in future.&lt;br /&gt;&lt;br /&gt;Here is the quick mapping of the isolation level with concurrency problems:&lt;br /&gt;&lt;br /&gt;Isolation Dirty Reads Lost Update Nonrepeatable Reads Phantom Reads &lt;br /&gt;Read Uncommitted Yes Yes Yes Yes &lt;br /&gt;Read Committed No Yes Yes Yes &lt;br /&gt;Repeatable Read No No No Yes &lt;br /&gt;Snapshot No No No No &lt;br /&gt;Serializable No No No No &lt;br /&gt;&lt;br /&gt;Source: sqlauthority.com&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-7779557350318820184?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/7779557350318820184/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=7779557350318820184' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/7779557350318820184'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/7779557350318820184'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/03/t-sql-concurrency-issues-and-isolation.html' title='[T-SQL] Concurrency Issues and Isolation Level'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-327041468032606525</id><published>2011-03-05T10:17:00.000-08:00</published><updated>2011-03-05T10:17:55.818-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='video'/><category scheme='http://www.blogger.com/atom/ns#' term='learners'/><category scheme='http://www.blogger.com/atom/ns#' term='informatica'/><category scheme='http://www.blogger.com/atom/ns#' term='tutorial'/><title type='text'>[Informatica] Tutorial Part 3</title><content type='html'>Here is the third part of Informatica Tutorial Part 3.&lt;br /&gt;&lt;br /&gt;http://www.youtube.com/watch?v=upwtGPn4pDI&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-327041468032606525?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/327041468032606525/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=327041468032606525' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/327041468032606525'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/327041468032606525'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/03/informatica-tutorial-part-3.html' title='[Informatica] Tutorial Part 3'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-3875389137346158129</id><published>2011-03-02T04:41:00.001-08:00</published><updated>2011-03-02T04:41:50.398-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='video'/><category scheme='http://www.blogger.com/atom/ns#' term='informatica'/><category scheme='http://www.blogger.com/atom/ns#' term='tutorial'/><title type='text'>[Informatica] Tutorial Part 2</title><content type='html'>Informatica Tutorial Part 2 for two beginners:&lt;br /&gt;&lt;br /&gt;http://www.youtube.com/watch?v=oM2d-IHfRUw&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-3875389137346158129?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/3875389137346158129/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=3875389137346158129' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/3875389137346158129'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/3875389137346158129'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/03/informatica-tutorial-part-2.html' title='[Informatica] Tutorial Part 2'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-2493048525480815595</id><published>2011-02-28T21:20:00.001-08:00</published><updated>2011-02-28T21:20:55.704-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='video'/><category scheme='http://www.blogger.com/atom/ns#' term='informatica'/><category scheme='http://www.blogger.com/atom/ns#' term='tutorial'/><title type='text'>[Informatica] Tutorial Part 1</title><content type='html'>Here is the link if Informatica Tutorial Part 1 for beginners:&lt;br /&gt;&lt;br /&gt;http://www.youtube.com/watch?v=ufH_n5exxQw&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-2493048525480815595?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/2493048525480815595/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=2493048525480815595' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/2493048525480815595'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/2493048525480815595'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/02/informatica-tutorial-part-1.html' title='[Informatica] Tutorial Part 1'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-9212668312867663208</id><published>2011-02-18T04:54:00.000-08:00</published><updated>2011-02-18T04:54:10.568-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='informatica'/><category scheme='http://www.blogger.com/atom/ns#' term='integration service'/><title type='text'>[Informatica] Configure Power Center Integration Service</title><content type='html'>Finally we need to configure Integration Service through which we can execute our workflows.&lt;br /&gt;1. In the Administrator tool, click the Domain tab.&lt;br /&gt;2. On the Navigator Actions menu, click New &gt; PowerCenter Integration Service.&lt;br /&gt;The New Integration Service dialog box appears.&lt;br /&gt;3. Enter the Service Name, License, And Primary Node.&lt;br /&gt;4. Now provide the repository information which you just created, its included repository name, username and password.&lt;br /&gt;5. Click Finish.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-9212668312867663208?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/9212668312867663208/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=9212668312867663208' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/9212668312867663208'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/9212668312867663208'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/02/informatica-configure-power-center_18.html' title='[Informatica] Configure Power Center Integration Service'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-5842822502423736317</id><published>2011-02-18T04:52:00.000-08:00</published><updated>2011-02-18T04:52:12.703-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='configure'/><category scheme='http://www.blogger.com/atom/ns#' term='informatica'/><category scheme='http://www.blogger.com/atom/ns#' term='repository'/><title type='text'>[Informatica] Configure Power Center Repository Service</title><content type='html'>After the successful installation of Informatica we need to configure repository service. These steps need to be done from windows operating system. Any browser should be installed for performing these steps.&lt;br /&gt;1. Open up the browser and type in below format http://DomainName:PortNo/administrator/index.html&lt;br /&gt;Sample: http://informatica-test:6007/administrator/index.html&lt;br /&gt;2. Enter the username and password provided during the installation.&lt;br /&gt;3. In the Administrator tool, click the Domain tab.&lt;br /&gt;4. In the Navigator, select the folder where you want to create the PowerCenter Repository Service. Note: If you do not select a folder, you can move the PowerCenter Repository Service into a folder after you create it.&lt;br /&gt;5. In the Domain Actions menu, click New &gt; PowerCenter Repository Service. The Create New Repository Service dialog box appears.&lt;br /&gt;6. Provide the Repository Service Name and all other database parameters.&lt;br /&gt;7. Click the option to create repository contents.  &lt;br /&gt;8. Select the license, node and all other information that need to be provided.&lt;br /&gt;9. Select “UTF-8 encoding of Unicode” in Code page combo box.&lt;br /&gt;10. Click Ok.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-5842822502423736317?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/5842822502423736317/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=5842822502423736317' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/5842822502423736317'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/5842822502423736317'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/02/informatica-configure-power-center.html' title='[Informatica] Configure Power Center Repository Service'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-3993141717530468884</id><published>2011-02-18T04:49:00.000-08:00</published><updated>2011-02-18T04:49:39.997-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='server'/><category scheme='http://www.blogger.com/atom/ns#' term='informatica'/><title type='text'>[Informatica] Server Installation 9.0.1</title><content type='html'>Here are steps to install informatica server 9.0.1:&lt;br /&gt;&lt;br /&gt;1. Verify that your environment meets the minimum system requirements, and complete the pre-installation tasks as completed in steps 3 and 4 of this guide.&lt;br /&gt;2. Log in to the machine with a system user account.&lt;br /&gt;3. Close all other applications.&lt;br /&gt;4. On a shell command line, run the install.sh file located in the root directory. The installer displays the message to verify that the locale environment variables are set.&lt;br /&gt;5. If the environment variables are not set, enter N to exit the installer and set them as required. If the environment variables are set, enter Y to continue.&lt;br /&gt;6. Enter C for console mode installation.&lt;br /&gt;7. Press Enter.&lt;br /&gt;8. Enter 1 to install Informatica 9.0.1. Review the system requirements and pre-installation tasks. Verify that all installation requirements are met before you continue the installation.&lt;br /&gt;9. Press Enter.&lt;br /&gt;10. Enter the path and file name of the Informatica license key.&lt;br /&gt;11. Enter the path for the installation directory or press Enter to use the default directory. The directory names in the path must not contain spaces or the following especial characters: @|* $ # ! % ( ) { } [ ] , ; '&lt;br /&gt;12. Review the installation information, and press Enter to continue. The installer copies the Informatica files to the installation directory.&lt;br /&gt;13. Enter 1 to create a domain. If you create a domain, the node on the current machine becomes a gateway node on the domain. The gateway node contains a Service Manager that manages all domain operations.&lt;br /&gt;14. Select whether to set up a secure connection between the Service Manager and the Administrator tool. Press 1 to Enable HTTPS for Informatica Administrator.&lt;br /&gt;15. Select the database to use for the domain configuration repository. Press 1 to select Oracle.&lt;br /&gt;16. Enter the Database User ID and Password.&lt;br /&gt;17. Select how you want to specify the database connection URL. Press 1 for JDBC URL.&lt;br /&gt;18. Now enter the properties at the prompt.&lt;br /&gt;a. Database Address: Enter HostName:PortNo&lt;br /&gt;b. Database service name: Enter SID&lt;br /&gt;c. Configure JDBC parameters: Select yes, enter the parameters or press enter to accept the default.&lt;br /&gt;19. If the database contains a domain configuration repository for a previous domain, select 2 to overwrite the data or set up another database. Press Continue to overwrite.&lt;br /&gt;20. Enter the following information at the prompt:&lt;br /&gt;a. Domain name: Enter Domain Name&lt;br /&gt;b. Domain host name: Enter Host Name&lt;br /&gt;c. Node name: Press Enter for default Node Name&lt;br /&gt;d. Domain port number: Press Enter for default port name&lt;br /&gt;e. Domain user name: Enter username, this would be used for initial setup of Informatica&lt;br /&gt;f. Domain user password: Enter Password&lt;br /&gt;g. Confirm password: Enter Password again&lt;br /&gt;21.  Now it would ask whether to display the default ports for the domain and node components assigned by the installer. Press 1 for No.&lt;br /&gt;22.  Installation is now complete.&lt;br /&gt;23.  Go to the Informatica installation directory and write the below command to bring up the Informatica service.&lt;br /&gt;infaservice.sh startup&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-3993141717530468884?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/3993141717530468884/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=3993141717530468884' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/3993141717530468884'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/3993141717530468884'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/02/informatica-server-installation-901.html' title='[Informatica] Server Installation 9.0.1'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-342028597261074516.post-8526925634098712436</id><published>2011-02-18T04:43:00.000-08:00</published><updated>2011-02-18T04:43:50.860-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='import'/><category scheme='http://www.blogger.com/atom/ns#' term='workflow'/><title type='text'>[Informatica] How to import workflow in Informatica PC</title><content type='html'>Here are the steps to import workflow in Informatica Power Centre:&lt;br /&gt;&lt;br /&gt;1. Verify that xml file is present in source folder.&lt;br /&gt;2. Open Informatica PC Repository Manager.&lt;br /&gt;3. Connect to the repository by providing relevant username and password.&lt;br /&gt;4. Create a new folder in repository.&lt;br /&gt;5. Go to that folder and then under Repository menu at the top click import objects.&lt;br /&gt;6. Select the file that is present in informaticarepository folder and click next.&lt;br /&gt;7. In this screen click button add all as you would need all the objects to execute workflow which are currently present in xml file and click next.&lt;br /&gt;8. Select the folder which was created recently and click next.&lt;br /&gt;9. Now click next one more time and click import. It would show you all the objects import status.&lt;br /&gt;10. Now you can verify in the folder that workflow exists.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-8526925634098712436?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/8526925634098712436/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=8526925634098712436' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/8526925634098712436'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/8526925634098712436'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/02/informatica-how-to-import-workflow-in.html' title='[Informatica] How to import workflow in Informatica PC'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-2593838000856703380</id><published>2011-02-15T23:44:00.001-08:00</published><updated>2011-02-15T23:44:42.645-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='backup'/><category scheme='http://www.blogger.com/atom/ns#' term='stored procedure'/><category scheme='http://www.blogger.com/atom/ns#' term='database'/><category scheme='http://www.blogger.com/atom/ns#' term='script'/><title type='text'>[T-SQL] Database backup procedure - advanced</title><content type='html'>I have got this script from one of the blogs:&lt;br /&gt;&lt;br /&gt;if exists (select * from sysobjects where id = object_id(N'[dbo].[spBackupAllDatabases]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)&lt;br /&gt;drop procedure [dbo].[spBackupAllDatabases]&lt;br /&gt;go&lt;br /&gt;&lt;br /&gt;Create Procedure spBackupAllDatabases&lt;br /&gt;@Path varchar(128) ,&lt;br /&gt;@Type varchar(4) -- Full / Log&lt;br /&gt;as&lt;br /&gt;/*&lt;br /&gt;Backup file format&lt;br /&gt;&lt;dbname&gt;_Full_yyyymmdd_hhmmss.bak&lt;br /&gt;&lt;dbname&gt;_Log_yyyymmdd_hhmmss.bak&lt;br /&gt;&lt;br /&gt;exec spBackupAllDatabases 'c:\SQLBackups\', 'Full'&lt;br /&gt;*/&lt;br /&gt;/*&lt;br /&gt;drop table DatabaseBackup&lt;br /&gt;&lt;br /&gt;Create table DatabaseBackup&lt;br /&gt; (&lt;br /&gt; Name   varchar(128) primary key nonclustered ,&lt;br /&gt; BackupFlagFull  varchar(1) not null check (BackupFlagFull in ('Y','N')) ,&lt;br /&gt; BackupFlagLog  varchar(1) not null check (BackupFlagLog in ('Y','N')) ,&lt;br /&gt; RetentionPeriodFull datetime not null ,&lt;br /&gt; RetentionPeriodLog datetime not null&lt;br /&gt; )&lt;br /&gt;*/&lt;br /&gt;set nocount on&lt;br /&gt;declare @sql varchar(1000)&lt;br /&gt; &lt;br /&gt; -- Get all database names&lt;br /&gt; create table #DBName&lt;br /&gt;  (&lt;br /&gt;  ID  int identity (1,1) ,&lt;br /&gt;  Name  varchar(128) not null ,&lt;br /&gt;  RetentionPeriod datetime null&lt;br /&gt;  )&lt;br /&gt; &lt;br /&gt; insert #DBName&lt;br /&gt;  (Name)&lt;br /&gt; select name&lt;br /&gt; from master..sysdatabases&lt;br /&gt; &lt;br /&gt; -- Include any new databases in the backup&lt;br /&gt; insert DatabaseBackup&lt;br /&gt;  (&lt;br /&gt;  Name ,&lt;br /&gt;  BackupFlagFull ,&lt;br /&gt;  BackupFlagLog ,&lt;br /&gt;  RetentionPeriodFull ,&lt;br /&gt;  RetentionPeriodLog&lt;br /&gt;  )&lt;br /&gt; select #DBName.Name ,&lt;br /&gt;  'Y' ,&lt;br /&gt;  'N' ,&lt;br /&gt;  '7 jan 1900' ,  -- default one week&lt;br /&gt;  '1 jan 1900'&lt;br /&gt; from #DBName&lt;br /&gt;  left outer join DatabaseBackup&lt;br /&gt;   on DatabaseBackup.Name = #DBName.Name&lt;br /&gt; where DatabaseBackup.Name is null&lt;br /&gt; and lower(#DBName.Name) &lt;&gt; 'tempdb'&lt;br /&gt; &lt;br /&gt; -- Remove any non-existant databases&lt;br /&gt; delete DatabaseBackup&lt;br /&gt; where not exists&lt;br /&gt;  (&lt;br /&gt;  select *&lt;br /&gt;  from #DBName&lt;br /&gt;  where #DBName.Name = DatabaseBackup.Name&lt;br /&gt;  )&lt;br /&gt; &lt;br /&gt; delete #DBName&lt;br /&gt; &lt;br /&gt; create table #ExistingBackups&lt;br /&gt;  (&lt;br /&gt;  Name varchar(128) ,&lt;br /&gt;  ID int identity (1,1)&lt;br /&gt;  )&lt;br /&gt; &lt;br /&gt; -- loop through databases&lt;br /&gt;declare @Name    varchar(128) ,&lt;br /&gt; @RetentionPeriod datetime ,&lt;br /&gt; @LastBackupToKeep varchar(8) ,&lt;br /&gt; @ID   int ,&lt;br /&gt; @MaxID   int &lt;br /&gt; &lt;br /&gt; insert #DBName&lt;br /&gt;  (Name, RetentionPeriod)&lt;br /&gt; select Name, case when @Type = 'Full' then RetentionPeriodFull else RetentionPeriodLog end&lt;br /&gt; from DatabaseBackup&lt;br /&gt; where (@Type = 'Full' and BackupFlagFull = 'Y')&lt;br /&gt; or (@Type = 'Log' and BackupFlagLog = 'Y')&lt;br /&gt; &lt;br /&gt; select @MaxID  = max(ID) ,&lt;br /&gt;  @ID = 0&lt;br /&gt; from #DBName&lt;br /&gt; &lt;br /&gt; while @ID &lt; @MaxID begin  -- get next database to backup  select @ID = min(ID) from #DBName where ID &gt; @ID&lt;br /&gt;  &lt;br /&gt;  select  @Name = Name ,&lt;br /&gt;   @RetentionPeriod = RetentionPeriod&lt;br /&gt;  from  #DBName&lt;br /&gt;  where ID = @ID&lt;br /&gt;  &lt;br /&gt;  -- Delete old backups&lt;br /&gt;  delete #ExistingBackups&lt;br /&gt;  select  @sql = 'dir /B ' + @Path&lt;br /&gt;  select @sql = @sql + @Name + '_' + @Type + '*.*'&lt;br /&gt;  &lt;br /&gt;  insert #ExistingBackups exec master..xp_cmdshell @sql&lt;br /&gt;  &lt;br /&gt;  if exists (select * from #ExistingBackups where Name like '%File Not Found%')&lt;br /&gt;   delete #ExistingBackups&lt;br /&gt;  &lt;br /&gt;  select  @LastBackupToKeep = convert(varchar(8),getdate() - @RetentionPeriod,112)&lt;br /&gt;  delete #ExistingBackups where Name &gt; @Name + '_' + @Type + '_' + @LastBackupToKeep&lt;br /&gt;&lt;br /&gt;declare @eID int ,&lt;br /&gt; @eMaxID int ,&lt;br /&gt; @eName varchar(128)&lt;br /&gt;  &lt;br /&gt;  -- loop round all the out of date backups&lt;br /&gt;  select @eID = 0 ,&lt;br /&gt;   @eMaxID = coalesce(max(ID), 0)&lt;br /&gt;  from #ExistingBackups&lt;br /&gt;  &lt;br /&gt;  while @eID &lt; @eMaxID  begin   select  @eID = min(ID) from #ExistingBackups where ID &gt; @eID&lt;br /&gt;   select @eName = Name from #ExistingBackups where ID = @eID&lt;br /&gt;   &lt;br /&gt;   select @sql = 'del ' + @Path + @eName&lt;br /&gt;   exec master..xp_cmdshell @sql&lt;br /&gt;  end&lt;br /&gt;  delete #ExistingBackups&lt;br /&gt; &lt;br /&gt;  -- now do the backup&lt;br /&gt;  select @sql = @Path + @Name + '_' + @Type + '_' &lt;br /&gt;     + convert(varchar(8),getdate(),112) + '_' &lt;br /&gt;     + replace(convert(varchar(8),getdate(),108),':','') + '.bak'&lt;br /&gt;  if @Type = 'Full'&lt;br /&gt;   backup database @Name&lt;br /&gt;   to disk = @sql&lt;br /&gt;  else&lt;br /&gt;   backup log @Name&lt;br /&gt;   to disk = @sql&lt;br /&gt; end&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/342028597261074516-2593838000856703380?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/2593838000856703380/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=2593838000856703380' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/2593838000856703380'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/2593838000856703380'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/02/t-sql-database-backup-procedure.html' title='[T-SQL] Database backup procedure - advanced'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-797753973712257403</id><published>2011-02-15T23:37:00.001-08:00</published><updated>2011-02-15T23:37:36.410-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='backup'/><category scheme='http://www.blogger.com/atom/ns#' term='database'/><category scheme='http://www.blogger.com/atom/ns#' term='script'/><title type='text'>[T-SQL] Database backup script</title><content type='html'>Today i got a request to provide a database backup script in such a way that every time it generated new name for database. So here is the script:&lt;br /&gt;&lt;br /&gt;DECLARE @name VARCHAR(50) -- database name  &lt;br /&gt;DECLARE @path VARCHAR(256) -- path for backup files  &lt;br /&gt;DECLARE @fileName VARCHAR(256) -- filename for backup  &lt;br /&gt;DECLARE @fileDate VARCHAR(20) -- used for file name &lt;br /&gt;&lt;br /&gt;SET @path = 'C:\Backup\'  &lt;br /&gt;&lt;br /&gt;SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),114) &lt;br /&gt;&lt;br /&gt;DECLARE db_cursor CURSOR FOR  &lt;br /&gt;SELECT name &lt;br /&gt;FROM master.dbo.sysdatabases &lt;br /&gt;WHERE name NOT IN ('master','model','msdb','tempdb')  &lt;br /&gt;&lt;br /&gt;OPEN db_cursor   &lt;br /&gt;FETCH NEXT FROM db_cursor INTO @name   &lt;br /&gt;&lt;br /&gt;WHILE @@FETCH_STATUS = 0   &lt;br /&gt;BEGIN   &lt;br /&gt;       SET @fileName = @path + @name + '_' + @fileDate + '.BAK'  &lt;br /&gt;       BACKUP DATABASE @name TO DISK = @fileName  &lt;br /&gt;    Print @filename&lt;br /&gt;       FETCH NEXT FROM db_cursor INTO @name   &lt;br /&gt;END   &lt;br /&gt;&lt;br /&gt;CLOSE db_cursor   &lt;br /&gt;DEALLOCATE db_cursor&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-797753973712257403?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/797753973712257403/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=797753973712257403' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/797753973712257403'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/797753973712257403'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/02/t-sql-database-backup-script.html' title='[T-SQL] Database backup script'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-1321198826889566045</id><published>2011-01-28T03:39:00.000-08:00</published><updated>2011-01-28T03:39:02.131-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='informatica'/><category scheme='http://www.blogger.com/atom/ns#' term='architecture'/><title type='text'>[Informatica] Software Architecture illustrated</title><content type='html'>Informatica &gt;&gt; Beginners &gt;&gt; Informatica System Architecture&lt;br /&gt;&lt;br /&gt;Informatica Software Architecture illustrated&lt;br /&gt;Informatica ETL product, known as Informatica Power Center consists of 3 main components.&lt;br /&gt;&lt;br /&gt;1. Informatica PowerCenter Client Tools: &lt;br /&gt;These are the development tools installed at developer end. These tools enable a developer to &lt;br /&gt;&lt;br /&gt;•Define transformation process, known as mapping. (Designer)&lt;br /&gt;•Define run-time properties for a mapping, known as sessions (Workflow Manager)&lt;br /&gt;•Monitor execution of sessions (Workflow Monitor)&lt;br /&gt;•Manage repository, useful for administrators (Repository Manager)&lt;br /&gt;•Report Metadata (Metadata Reporter)&lt;br /&gt;&lt;br /&gt;2. Informatica PowerCenter Repository:&lt;br /&gt;Repository is the heart of Informatica tools. Repository is a kind of data inventory where all the data related to mappings, sources, targets etc is kept. This is the place where all the metadata for your application is stored. All the client tools and Informatica Server fetch data from Repository. Informatica client and server without repository is same as a PC without memory/harddisk, which has got the ability to process data but has no data to process. This can be treated as backend of Informatica. &lt;br /&gt;&lt;br /&gt;3. Informatica PowerCenter Server: &lt;br /&gt;Server is the place, where all the executions take place. Server makes physical connections to sources/targets, fetches data, applies the transformations mentioned in the mapping and loads the data in the target system.&lt;br /&gt; &lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_aStpYnZNGVg/TUKquxE-sFI/AAAAAAAAACU/jKBfFH4n09w/s1600/informatica_architecture.jpg" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="320" width="216" src="http://2.bp.blogspot.com/_aStpYnZNGVg/TUKquxE-sFI/AAAAAAAAACU/jKBfFH4n09w/s320/informatica_architecture.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-1321198826889566045?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/1321198826889566045/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=1321198826889566045' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/1321198826889566045'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/1321198826889566045'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/01/informatica-software-architecture.html' title='[Informatica] Software Architecture illustrated'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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://2.bp.blogspot.com/_aStpYnZNGVg/TUKquxE-sFI/AAAAAAAAACU/jKBfFH4n09w/s72-c/informatica_architecture.jpg' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-342028597261074516.post-2704805013441912547</id><published>2011-01-28T02:34:00.000-08:00</published><updated>2011-01-28T02:34:19.658-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='r2'/><category scheme='http://www.blogger.com/atom/ns#' term='datawarehouse'/><title type='text'>[SQLServer]  Scaling Up Your Data Warehouse with SQL Server 2008 R2</title><content type='html'>Abstract from the Microsoft Official site:&lt;br /&gt;&lt;br /&gt;SQL Server 2008 introduced many new functional and performance improvements for data warehousing, and SQL Server 2008 R2 includes all these and more. This paper discusses how to use SQL Server 2008 R2 to get great performance as your data warehouse scales up. We present lessons learned during extensive internal data warehouse testing on a 64-core HP Integrity Superdome during the development of the SQL Server 2008 release, and via production experience with large-scale SQL Server customers. Our testing indicates that many customers can expect their performance to nearly double on the same hardware they are currently using, merely by upgrading to SQL Server 2008 R2 from SQL Server 2005 or earlier, and compressing their fact tables. We cover techniques to improve manageability and performance at high-scale, encompassing data loading (extract, transform, load), query processing, partitioning, index maintenance, indexed view (aggregate) management, and backup and restore.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-2704805013441912547?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/2704805013441912547/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=2704805013441912547' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/2704805013441912547'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/2704805013441912547'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/01/sqlserver-scaling-up-your-data.html' title='[SQLServer]  Scaling Up Your Data Warehouse with SQL Server 2008 R2'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-7609687162479606187</id><published>2011-01-18T03:03:00.000-08:00</published><updated>2011-01-18T03:03:10.293-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='dbname'/><category scheme='http://www.blogger.com/atom/ns#' term='dbid'/><title type='text'>[T-SQL] DB_ID() and DB_NAME() - PURPOSE</title><content type='html'>-- Get Current DatabaseID&lt;br /&gt;SELECT DB_ID() DatabaseID;&lt;br /&gt;-- Get Current DatabaseName&lt;br /&gt;SELECT DB_NAME() DatabaseName;&lt;br /&gt;-- Get DatabaseName from DatabaseID&lt;br /&gt;SELECT DB_NAME(4) DatabaseID;&lt;br /&gt;-- Get DatabaseID from DatabaseName&lt;br /&gt;SELECT DB_ID('tempdb') DatabaseName;&lt;br /&gt;-- Get all DatabaseName and DBID&lt;br /&gt;SELECT name,database_id&lt;br /&gt;FROM sys.databases;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-7609687162479606187?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/7609687162479606187/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=7609687162479606187' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/7609687162479606187'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/7609687162479606187'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/01/t-sql-dbid-and-dbname-purpose.html' title='[T-SQL] DB_ID() and DB_NAME() - PURPOSE'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-952288555865740244</id><published>2011-01-18T02:26:00.000-08:00</published><updated>2011-01-18T02:26:22.374-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='leap year'/><title type='text'>[T-SQL] Different methods to find leap year</title><content type='html'>Method 1 : General method&lt;br /&gt;&lt;br /&gt;declare @year int&lt;br /&gt;set @year=2000&lt;br /&gt;  &lt;br /&gt;select &lt;br /&gt; case &lt;br /&gt;  when @year%400=0  then 1 &lt;br /&gt;  when @year%100=0  then 0&lt;br /&gt;  when @year%4=0  then 1&lt;br /&gt;  else 0&lt;br /&gt; end as is_leap_year&lt;br /&gt;Method 2 : Find if the day difference between Jan 01 of this year to Jan 01 of next year is 366&lt;br /&gt;&lt;br /&gt;declare @year int&lt;br /&gt;set @year=2000&lt;br /&gt;  &lt;br /&gt;select &lt;br /&gt; case &lt;br /&gt;  when datediff(day,DATEADD(year,@year-1900,0),DATEADD(year,@year-1900+1,0))=366 then 1&lt;br /&gt;  else 0&lt;br /&gt; end as is_leap_year&lt;br /&gt;Method 3 : Find if the day difference between Feb 01 to Mar 01 of this year is 29&lt;br /&gt;&lt;br /&gt;select &lt;br /&gt; case &lt;br /&gt;  when datediff(day,dateadd(month,1,DATEADD(year,@year-1900,0)),dateadd(month,2,DATEADD(year,@year-1900,0)))=29 then 1 &lt;br /&gt;  else 0&lt;br /&gt; end as is_leap_year&lt;br /&gt;Method 4 : Find if the 60th day of this year falls in February last day (Feb 29)&lt;br /&gt;&lt;br /&gt;declare @year int&lt;br /&gt;set @year=2000&lt;br /&gt;  &lt;br /&gt;select &lt;br /&gt; case &lt;br /&gt;  when day(dateadd(day,59,DATEADD(year,@year-1900,0)))=29 then 1 &lt;br /&gt;  else 0&lt;br /&gt; end as is_leap_year&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-952288555865740244?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/952288555865740244/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=952288555865740244' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/952288555865740244'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/952288555865740244'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/01/t-sql-different-methods-to-find-leap.html' title='[T-SQL] Different methods to find leap year'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-4327108318882283680</id><published>2011-01-04T01:23:00.000-08:00</published><updated>2011-01-04T01:23:19.829-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='comparison'/><category scheme='http://www.blogger.com/atom/ns#' term='delete'/><category scheme='http://www.blogger.com/atom/ns#' term='truncate'/><title type='text'>[T-SQL] Delete vs Truncate</title><content type='html'>Here is good comparision between delete and truncate&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;strong&gt;DELETE: &lt;/strong&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;/b&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;DELETE supports a WHERE clause&lt;/li&gt;&lt;li&gt;DELETE removes rows from a table, row-by-row&lt;/li&gt;&lt;li&gt;Because DELETE moves row-by-row, it acquires a row-level lock&lt;/li&gt;&lt;li&gt;Depending upon the recovery model of the database, DELETE is a fully-logged operation.&lt;/li&gt;&lt;li&gt;Because DELETE moves row-by-row, it can fire off triggers&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;strong&gt;TRUNCATE: &lt;/strong&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;/b&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;TRUNCATE does not support a WHERE clause&lt;/li&gt;&lt;li&gt;TRUNCATE works by directly removing the individual data pages of a table&lt;/li&gt;&lt;li&gt;TRUNCATE directly occupies a table-level lock.&lt;/li&gt;&lt;li&gt;(Because a lock is acquired, and because TRUNCATE can also participate in a transaction, it has to be a logged operation)&lt;/li&gt;&lt;li&gt;TRUNCATE is, therefore, a minimally-logged operation; again, this depends upon the recovery model of the database&lt;/li&gt;&lt;li&gt;Triggers are not fired when TRUNCATE is used (because individual row deletions are not logged)&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-4327108318882283680?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/4327108318882283680/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=4327108318882283680' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/4327108318882283680'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/4327108318882283680'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/01/t-sql-delete-vs-truncate.html' title='[T-SQL] Delete vs Truncate'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-2174891718500955911</id><published>2011-01-04T01:15:00.001-08:00</published><updated>2011-01-04T01:15:36.832-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='data'/><category scheme='http://www.blogger.com/atom/ns#' term='cache'/><category scheme='http://www.blogger.com/atom/ns#' term='memory'/><title type='text'>[T-SQL] Data Cache in Memory</title><content type='html'>Here is the query by which you can see data cache in memory:&lt;br /&gt;&lt;br /&gt;USE AdventureWorks&lt;br /&gt;GO&lt;br /&gt;SELECT COUNT(*) AS cached_pages_count,&lt;br /&gt;name AS BaseTableName, IndexName,&lt;br /&gt;IndexTypeDesc&lt;br /&gt;FROM sys.dm_os_buffer_descriptors AS bd&lt;br /&gt;INNER JOIN&lt;br /&gt;(&lt;br /&gt;SELECT s_obj.name, s_obj.index_id,&lt;br /&gt;s_obj.allocation_unit_id, s_obj.OBJECT_ID,&lt;br /&gt;i.name IndexName, i.type_desc IndexTypeDesc&lt;br /&gt;FROM&lt;br /&gt;(&lt;br /&gt;SELECT OBJECT_NAME(OBJECT_ID) AS name,&lt;br /&gt;index_id ,allocation_unit_id, OBJECT_ID&lt;br /&gt;FROM sys.allocation_units AS au&lt;br /&gt;INNER JOIN sys.partitions AS p&lt;br /&gt;ON au.container_id = p.hobt_id&lt;br /&gt;AND (au.TYPE = 1 OR au.TYPE = 3)&lt;br /&gt;UNION ALL&lt;br /&gt;SELECT OBJECT_NAME(OBJECT_ID) AS name,&lt;br /&gt;index_id, allocation_unit_id, OBJECT_ID&lt;br /&gt;FROM sys.allocation_units AS au&lt;br /&gt;INNER JOIN sys.partitions AS p&lt;br /&gt;ON au.container_id = p.partition_id&lt;br /&gt;AND au.TYPE = 2&lt;br /&gt;) AS s_obj&lt;br /&gt;LEFT JOIN sys.indexes i ON i.index_id = s_obj.index_id&lt;br /&gt;AND i.OBJECT_ID = s_obj.OBJECT_ID ) AS obj&lt;br /&gt;ON bd.allocation_unit_id = obj.allocation_unit_id&lt;br /&gt;WHERE database_id = DB_ID()&lt;br /&gt;GROUP BY name, index_id, IndexName, IndexTypeDesc&lt;br /&gt;ORDER BY cached_pages_count DESC;&lt;br /&gt;GO&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-2174891718500955911?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/2174891718500955911/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=2174891718500955911' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/2174891718500955911'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/2174891718500955911'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/01/t-sql-data-cache-in-memory.html' title='[T-SQL] Data Cache in Memory'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-6983523207117944518</id><published>2011-01-04T01:14:00.001-08:00</published><updated>2011-01-04T01:14:49.569-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='cache'/><category scheme='http://www.blogger.com/atom/ns#' term='memory'/><title type='text'>[T-SQL] Plan Cache in Memory</title><content type='html'>Here is the query by which you can see plan cache in memory:&lt;br /&gt;&lt;br /&gt;USE AdventureWorks&lt;br /&gt;GO&lt;br /&gt;SELECT [text], cp.size_in_bytes, plan_handle&lt;br /&gt;FROM sys.dm_exec_cached_plans AS cp&lt;br /&gt;CROSS APPLY sys.dm_exec_sql_text(plan_handle)&lt;br /&gt;WHERE cp.cacheobjtype = N'Compiled Plan'&lt;br /&gt;ORDER BY cp.size_in_bytes DESC&lt;br /&gt;GO&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-6983523207117944518?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/6983523207117944518/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=6983523207117944518' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/6983523207117944518'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/6983523207117944518'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/01/t-sql-plan-cache-in-memory.html' title='[T-SQL] Plan Cache in Memory'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-4910402524098602395</id><published>2011-01-04T01:11:00.000-08:00</published><updated>2011-01-04T01:11:20.962-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='log'/><category scheme='http://www.blogger.com/atom/ns#' term='loginfo'/><category scheme='http://www.blogger.com/atom/ns#' term='dbcc'/><title type='text'>[T-SQL] DBCC LOGINFO</title><content type='html'>Do you know that there are multiple small log files in the large log file (LDF). So now your next question would be how can we know that.&lt;br /&gt;&lt;br /&gt;Veri simple method&lt;br /&gt;&lt;br /&gt;DBCC LOGINFO&lt;br /&gt;&lt;br /&gt;You would find the file size and other relevant information in the resultant.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-4910402524098602395?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/4910402524098602395/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=4910402524098602395' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/4910402524098602395'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/4910402524098602395'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2011/01/t-sql-dbcc-loginfo.html' title='[T-SQL] DBCC LOGINFO'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-1993598110358365573</id><published>2010-12-24T09:12:00.000-08:00</published><updated>2010-12-24T09:12:41.877-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='dump'/><category scheme='http://www.blogger.com/atom/ns#' term='indexfile'/><category scheme='http://www.blogger.com/atom/ns#' term='import'/><title type='text'>[ORACLE] How to import dump file to different table space</title><content type='html'>1.With your .DMP file, create a SQL file containing the structure (Tables):&lt;br /&gt;imp evolvrepo/password@ORCL file=evolvrepo.dmp indexfile=index.sql full=y&lt;br /&gt;&lt;br /&gt;2.Open the indexfile (index.sql) in a text editor that can do find and replace over an entire file, and issue the following find and replace statements IN ORDER (ignore the single quotes.. '):&lt;br /&gt;&lt;br /&gt;    a.Find: 'REM&lt;space&gt;' Replace: &lt;nothing&gt;&lt;br /&gt;&lt;br /&gt;    b.Find: '"&lt;source_tablespace&gt;"' Replace: '"#tablespace#"'&lt;br /&gt;&lt;br /&gt;    c.Find: '...' Replace: 'REM ...'&lt;br /&gt;&lt;br /&gt;    d.Find: 'CONNECT' Replace: 'REM CONNECT'&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3.Save the indexfile, then run it at command prompt&lt;br /&gt;echo exit|sqlplus evolvrepo/password@ORCL @index.sql&lt;br /&gt;&lt;br /&gt;4.Finally run the same .DMP file you created the indexfile with against the same account to import the data, stored procedures, views etc:&lt;br /&gt;imp evolvrepo/password@ORCL full=y file=evolvrepo.dmp buffer=326000 log=evolvrepo.log&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Note: Replace #tablespace# with table space name and #TEMP1# with temporary tablespace name.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-1993598110358365573?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/1993598110358365573/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=1993598110358365573' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/1993598110358365573'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/1993598110358365573'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/12/oracle-how-to-import-dump-file-to.html' title='[ORACLE] How to import dump file to different table space'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-1392465644914704006</id><published>2010-12-14T22:27:00.001-08:00</published><updated>2010-12-14T22:27:38.308-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='paging'/><title type='text'>[T-SQL] Paging in SQL Server 2011</title><content type='html'>So here is now the new feature of sql server in its latest edition , so here is how you can use paging , i mean server side paging for fetching rows or result set in pages.&lt;br /&gt;&lt;br /&gt;USE AdventureWorks2008R2&lt;br /&gt;GO&lt;br /&gt;DECLARE @RowsPerPage INT = 10, @PageNumber INT = 5&lt;br /&gt;SELECT *&lt;br /&gt;FROM Sales.SalesOrderDetail&lt;br /&gt;ORDER BY SalesOrderDetailID&lt;br /&gt;OFFSET @PageNumber*@RowsPerPage ROWS&lt;br /&gt;FETCH NEXT 10 ROWS ONLY&lt;br /&gt;GO&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-1392465644914704006?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/1392465644914704006/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=1392465644914704006' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/1392465644914704006'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/1392465644914704006'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/12/t-sql-paging-in-sql-server-2011.html' title='[T-SQL] Paging in SQL Server 2011'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-7981000896429976703</id><published>2010-12-08T23:37:00.000-08:00</published><updated>2010-12-08T23:37:34.382-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='powermart command prompt'/><category scheme='http://www.blogger.com/atom/ns#' term='pmcmd'/><title type='text'>[Informatica] Powermart Command Prompt pmcmd</title><content type='html'>Here is the way how you can execute the workflow from command prompt:&lt;br /&gt;&lt;br /&gt;./pmcmd&lt;br /&gt;pmcmd&gt; connect -sv TestingRepoIntegrationService1 -d Primatics_corvus.primaticsfinancial.com -u uname -p password&lt;br /&gt;pmcmd&gt; setfolder "Demo Mapping"&lt;br /&gt;pmcmd&gt; startworkflow Main_Model_Bank&lt;br /&gt;&lt;br /&gt;---- Description&lt;br /&gt;sv: Integration Service Name&lt;br /&gt;d: Domain Name&lt;br /&gt;u: username&lt;br /&gt;p: password&lt;br /&gt;setfolder: tell the folder name where workflow has been placed&lt;br /&gt;startworkflow : tell the workflow name&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-7981000896429976703?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/7981000896429976703/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=7981000896429976703' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/7981000896429976703'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/7981000896429976703'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/12/informatica-powermart-command-prompt.html' title='[Informatica] Powermart Command Prompt pmcmd'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-5228159019171053137</id><published>2010-12-08T02:30:00.000-08:00</published><updated>2010-12-08T02:30:38.780-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sp_spaceused'/><category scheme='http://www.blogger.com/atom/ns#' term='space'/><title type='text'>[T-SQL] Find Space Used For Any Particular Table</title><content type='html'>Use Temp;&lt;br /&gt;Go&lt;br /&gt;EXEC sp_spaceused 'Temp1';&lt;br /&gt;GO &lt;br /&gt;&lt;br /&gt;You will get the following details:&lt;br /&gt;&lt;br /&gt;1. Name&lt;br /&gt;2. Rows&lt;br /&gt;3. Reserved&lt;br /&gt;4. Data &lt;br /&gt;5. Index Size&lt;br /&gt;6. Unused&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-5228159019171053137?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/5228159019171053137/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=5228159019171053137' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/5228159019171053137'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/5228159019171053137'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/12/t-sql-find-space-used-for-any.html' title='[T-SQL] Find Space Used For Any Particular Table'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-3547223848531038640</id><published>2010-12-06T22:32:00.001-08:00</published><updated>2010-12-06T22:32:43.832-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='tutorial'/><title type='text'>[Informatica] Tutorials</title><content type='html'>Here are some initial tutorials for how to work with informatica.&lt;br /&gt;&lt;br /&gt;How to create mapping , session , workflow using Informatica Powercenter:&lt;br /&gt;&lt;br /&gt;http://www.youtube.com/watch?v=zkJoet5jBtE&lt;br /&gt;&lt;br /&gt;Workflow Properties:&lt;br /&gt;&lt;br /&gt;http://www.youtube.com/watch?v=2FiFLaNkwnY&lt;br /&gt;&lt;br /&gt;Let me know if you have any queries regarding any steps that are defined in between.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-3547223848531038640?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/3547223848531038640/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=3547223848531038640' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/3547223848531038640'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/3547223848531038640'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/12/informatica-tutorials.html' title='[Informatica] Tutorials'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-1003016291807319322</id><published>2010-12-06T02:23:00.000-08:00</published><updated>2010-12-06T02:23:12.247-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='label'/><title type='text'>[Informatica] New Label</title><content type='html'>I have started working on Informatica , so now i would also start posting some good material realated to Informatica with the label [Informatica]&lt;br /&gt;&lt;br /&gt;I am working on the following tools:&lt;br /&gt;&lt;br /&gt;Informatica 9.0.1&lt;br /&gt;=&gt; Power Center Designer&lt;br /&gt;=&gt; Power Center Workflow Manager&lt;br /&gt;=&gt; Power Center Workflow Monitor&lt;br /&gt;&lt;br /&gt;For any queries , do let me know.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-1003016291807319322?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/1003016291807319322/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=1003016291807319322' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/1003016291807319322'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/1003016291807319322'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/12/informatica-new-label.html' title='[Informatica] New Label'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-2388798960634088297</id><published>2010-11-28T01:20:00.000-08:00</published><updated>2010-11-28T01:20:51.420-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='corrupted'/><category scheme='http://www.blogger.com/atom/ns#' term='mdf'/><title type='text'>[T-SQL] What to do , if mdf file get corrupted</title><content type='html'>Today one of my old friend asked help that he has got mdf file corrupted so what should he do.&lt;br /&gt;&lt;br /&gt;So normally there are different excersies which one can do if he knows about the structure of sql server but i am suggesting two tool which you can download and get the task done.:&lt;br /&gt;&lt;br /&gt;http://www.mdfrepair.com/&lt;br /&gt;http://www.nucleustechnologies.com/sql-recovery.html&lt;br /&gt;&lt;br /&gt;Download it and there are simple steps what you can do to get your db repaired.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-2388798960634088297?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/2388798960634088297/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=2388798960634088297' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/2388798960634088297'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/2388798960634088297'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/11/t-sql-what-to-do-if-mdf-file-get.html' title='[T-SQL] What to do , if mdf file get corrupted'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-7996039074130866656</id><published>2010-11-28T00:48:00.000-08:00</published><updated>2010-11-28T00:49:42.789-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='versions'/><category scheme='http://www.blogger.com/atom/ns#' term='difference'/><category scheme='http://www.blogger.com/atom/ns#' term='2008'/><title type='text'>Different versions of SQL Server 2008</title><content type='html'>Choosing the right SQL Server 2008 Edition is something that requires a bit of a research. The first step is of course to become familiar with the available options. We have seen this question pop up a lot of times at client sites as well as in newsgroups and the e-mails that we get from the readers. Microsoft already has very good, concise and to the point information on the different editions, their capabilities as well as a comparison matrix between Enterprise &amp; Standard Edition as well as a comparison matrix between Compact &amp; Express Edition. There are a lot of choices available for you and depending upon your needs, you can choose from (all the details on these can be obtained from the link above):&lt;br /&gt;&lt;br /&gt;•Enterprise Edition&lt;br /&gt;•Standard Edition&lt;br /&gt;•Workgroup Edition&lt;br /&gt;•Web Edition&lt;br /&gt;•Compact Edition&lt;br /&gt;•Express Edition &lt;br /&gt;◦SQL Server 2008 Express Edition.&lt;br /&gt;◦SQL Server 2008 Express with Tools.&lt;br /&gt;◦SQL Server 2008 Express with Advanced Tools.&lt;br /&gt;&lt;br /&gt;Full comparison sheet link is given below:&lt;br /&gt;&lt;br /&gt;http://download.microsoft.com/download/2/d/f/2df66c0c-fff2-4f2e-b739-bf4581cee533/SQLServer%202008CompareEnterpriseStandard.pdf&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-7996039074130866656?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/7996039074130866656/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=7996039074130866656' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/7996039074130866656'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/7996039074130866656'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/11/difference-versions-of-sql-server-2008.html' title='Different versions of SQL Server 2008'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-6389252273751165778</id><published>2010-11-26T07:30:00.001-08:00</published><updated>2010-11-26T07:30:24.140-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql server'/><category scheme='http://www.blogger.com/atom/ns#' term='price'/><category scheme='http://www.blogger.com/atom/ns#' term='oracle'/><title type='text'>Comparison between prices of SQL Server and Oracle</title><content type='html'>SQL Server is a feature-rich and economical choice compared to Oracle. The base product of Oracle is expensive and to add all the features that are offered by the SQL Server, it requires many more different add-ons. These extra add-ons further increase the price to make SQL Server much more affordable than Oracle, which is ridiculously expensive.&lt;br /&gt;&lt;br /&gt;I suggest that instead of me taking the side of SQL Server, you should compare the prices of the products yourself. The prices that are listed here are as per the process.&lt;br /&gt;&lt;br /&gt;SQL Server Standard: $7,171&lt;br /&gt;SQL Server Enterprise: $27,495&lt;br /&gt;&lt;br /&gt;Oracle Standard One: $5,800&lt;br /&gt;Oracle Standard: $17,500&lt;br /&gt;Oracle Enterprise: $47,500&lt;br /&gt;&lt;br /&gt;Additionally, in case of Oracle, you will have to purchase many additional features which are already available at NO COST in SQL Server Enterprise Edition. For example, in the SQL Server Enterprise edition, partitioning is a part of the package, whereas in the case of Oracle, you will have to pay additional 11,500 per processor along with the enterprise edition purchase. If you have a four-socket CPU, you end up paying almost the same price as Oracle Enterprise. Again this is just one feature we talked about. There are many additional add-ons available for Oracle, which are free in the SQL Server Enterprise or Standard edition (e.g. BI Tools).&lt;br /&gt;&lt;br /&gt;*Prices listed are taken from the official pdf that were available on both companies website on july-2010.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-6389252273751165778?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/6389252273751165778/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=6389252273751165778' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/6389252273751165778'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/6389252273751165778'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/11/comparison-between-prices-of-sql-server.html' title='Comparison between prices of SQL Server and Oracle'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-5146869050095683701</id><published>2010-11-21T20:39:00.000-08:00</published><updated>2010-11-21T20:39:47.484-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='log'/><category scheme='http://www.blogger.com/atom/ns#' term='create'/><category scheme='http://www.blogger.com/atom/ns#' term='file'/><category scheme='http://www.blogger.com/atom/ns#' term='error'/><title type='text'>[T-SQL] How to create new error log file</title><content type='html'>There are total two methods to do this:&lt;br /&gt;&lt;br /&gt;1. Restart the server&lt;br /&gt;2. EXEC sp_cycle_errorlog&lt;br /&gt;&lt;br /&gt;First option is not a suitable one as we restart the server every time.&lt;br /&gt;&lt;br /&gt;Hope this post is helpful to many of the dba's.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-5146869050095683701?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/5146869050095683701/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=5146869050095683701' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/5146869050095683701'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/5146869050095683701'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/11/t-sql-how-to-create-new-error-log-file.html' title='[T-SQL] How to create new error log file'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-1143887247528350566</id><published>2010-11-13T22:16:00.000-08:00</published><updated>2010-11-13T22:16:01.939-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='drop'/><category scheme='http://www.blogger.com/atom/ns#' term='database'/><title type='text'>[T-SQL] Drop Database - Common Error</title><content type='html'>Normally when you try to drop the database , you get common error that its current in use. So here is proper script for how you should drop the database. But please make sure what you know what you are doing , as dropping database on Production can be a big issue.&lt;br /&gt;&lt;br /&gt;USE MASTER&lt;br /&gt;GO&lt;br /&gt;ALTER DATABASE Mabbas_DB&lt;br /&gt;SET SINGLE_USER WITH ROLLBACK IMMEDIATE;&lt;br /&gt;DROP DATABASE Mabbas_DB&lt;br /&gt;GO&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-1143887247528350566?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/1143887247528350566/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=1143887247528350566' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/1143887247528350566'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/1143887247528350566'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/11/t-sql-drop-database-common-error.html' title='[T-SQL] Drop Database - Common Error'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-4671228944828307366</id><published>2010-11-10T02:32:00.001-08:00</published><updated>2010-11-10T02:32:37.791-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='all dbs'/><category scheme='http://www.blogger.com/atom/ns#' term='backup'/><category scheme='http://www.blogger.com/atom/ns#' term='time'/><title type='text'>[T-SQL] Last Backup time for all DBs</title><content type='html'>One more script to share&lt;br /&gt;&lt;br /&gt;SELECT sdb.Name AS DatabaseName,&lt;br /&gt;COALESCE(CONVERT(VARCHAR(12), MAX(bus.backup_finish_date), 101),'-') AS LastBackUpTime&lt;br /&gt;FROM sys.sysdatabases sdb&lt;br /&gt;LEFT OUTER JOIN msdb.dbo.backupset bus ON bus.database_name = sdb.name&lt;br /&gt;GROUP BY sdb.Name&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-4671228944828307366?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/4671228944828307366/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=4671228944828307366' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/4671228944828307366'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/4671228944828307366'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/11/t-sql-last-backup-time-for-all-dbs.html' title='[T-SQL] Last Backup time for all DBs'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-7234304641948455243</id><published>2010-11-10T02:28:00.000-08:00</published><updated>2010-11-10T02:28:35.714-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='backup'/><category scheme='http://www.blogger.com/atom/ns#' term='history'/><title type='text'>[T-SQL] DB Backup History</title><content type='html'>Today i was visiting one blog(Pinal Dave) and found a very interesting query for getting database backup history.&lt;br /&gt;&lt;br /&gt;SELECT TOP 100&lt;br /&gt;s.database_name,&lt;br /&gt;m.physical_device_name,&lt;br /&gt;CAST(CAST(s.backup_size / 1000000 AS INT) AS VARCHAR(14)) + ' ' + 'MB' AS bkSize,&lt;br /&gt;CAST(DATEDIFF(second, s.backup_start_date,&lt;br /&gt;s.backup_finish_date) AS VARCHAR(4)) + ' ' + 'Seconds' TimeTaken,&lt;br /&gt;s.backup_start_date,&lt;br /&gt;CAST(s.first_lsn AS VARCHAR(50)) AS first_lsn,&lt;br /&gt;CAST(s.last_lsn AS VARCHAR(50)) AS last_lsn,&lt;br /&gt;CASE s.[type]&lt;br /&gt;WHEN 'D' THEN 'Full'&lt;br /&gt;WHEN 'I' THEN 'Differential'&lt;br /&gt;WHEN 'L' THEN 'Transaction Log'&lt;br /&gt;END AS BackupType,&lt;br /&gt;s.server_name,&lt;br /&gt;s.recovery_model&lt;br /&gt;FROM msdb.dbo.backupset s&lt;br /&gt;INNER JOIN msdb.dbo.backupmediafamily m ON s.media_set_id = m.media_set_id&lt;br /&gt;WHERE s.database_name = DB_NAME() -- Remove this line for all the database&lt;br /&gt;ORDER BY backup_start_date DESC, backup_finish_date&lt;br /&gt;GO&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-7234304641948455243?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/7234304641948455243/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=7234304641948455243' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/7234304641948455243'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/7234304641948455243'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/11/t-sql-db-backup-history.html' title='[T-SQL] DB Backup History'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-436968814657335877</id><published>2010-11-08T02:50:00.000-08:00</published><updated>2010-11-08T02:50:21.169-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='duplicate'/><category scheme='http://www.blogger.com/atom/ns#' term='delete'/><category scheme='http://www.blogger.com/atom/ns#' term='without identity'/><title type='text'>[T-SQL] Delete duplicate without ID</title><content type='html'>Here is a query by which you can delete duplicate rows without using identity column&lt;br /&gt;&lt;br /&gt;/* Delete Duplicate records */&lt;br /&gt;WITH CTE (COl1,Col2, DuplicateCount)&lt;br /&gt;AS&lt;br /&gt;(&lt;br /&gt;SELECT COl1,Col2,&lt;br /&gt;ROW_NUMBER() OVER(PARTITION BY COl1,Col2 ORDER BY Col1) AS DuplicateCount&lt;br /&gt;FROM DuplicateRcordTable&lt;br /&gt;)&lt;br /&gt;DELETE&lt;br /&gt;FROM CTE&lt;br /&gt;WHERE DuplicateCount &amp;gt; 1&lt;br /&gt;GO&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-436968814657335877?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/436968814657335877/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=436968814657335877' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/436968814657335877'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/436968814657335877'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/11/t-sql-delete-duplicate-without-id.html' title='[T-SQL] Delete duplicate without ID'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-8232598951612814801</id><published>2010-11-05T00:30:00.000-07:00</published><updated>2010-11-05T00:30:57.812-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='union all'/><category scheme='http://www.blogger.com/atom/ns#' term='union'/><category scheme='http://www.blogger.com/atom/ns#' term='difference'/><title type='text'>[T-SQL] Union vs. Union All</title><content type='html'>Now a days , i am taking interview for the post of DWH Engineer and a common question that i am asking is the above one , but i dont know why people dont know this.&lt;br /&gt;&lt;br /&gt;So here is the basic definition:&lt;br /&gt;&lt;br /&gt;UNION&lt;br /&gt;The UNION command is used to select related information from two tables, much like the JOIN command. However, when using the UNION command all selected columns need to be of the same data type. With UNION, only distinct values are selected.&lt;br /&gt;&lt;br /&gt;UNION ALL&lt;br /&gt;The UNION ALL command is equal to the UNION command, except that UNION ALL selects all values. &lt;br /&gt;&lt;br /&gt;The difference between Union and Union all is that Union all will not eliminate duplicate rows, instead it just pulls all rows from all tables fitting your query specifics and combines them into a table.&lt;br /&gt;&lt;br /&gt;If we talk about the performance , then it should be known that Union All is much faster then Union as Union involves distinct clause which itself is a heavy operation.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-8232598951612814801?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/8232598951612814801/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=8232598951612814801' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/8232598951612814801'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/8232598951612814801'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/11/t-sql-union-vs-union-all.html' title='[T-SQL] Union vs. Union All'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-8516868969288289507</id><published>2010-11-04T04:50:00.000-07:00</published><updated>2010-11-04T04:50:37.243-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='dmv'/><category scheme='http://www.blogger.com/atom/ns#' term='database'/><category scheme='http://www.blogger.com/atom/ns#' term='busiest'/><title type='text'>[T-SQL] Find Busiest Database(s)</title><content type='html'>DMV sys.dm_exec_query_stats contained columns total_logical_reads, total_logical_writes, sql_handle. Column sql_handle can help to to determine the original query by CROSS JOINing DMF sys.dm_exec_sql_text. From DMF sys.dm_exec_sql_text Database ID and from Database ID can be figured out very quickly.&lt;br /&gt;&lt;br /&gt;SELECT SUM(deqs.total_logical_reads) TotalPageReads,&lt;br /&gt;SUM(deqs.total_logical_writes) TotalPageWrites,&lt;br /&gt;CASE&lt;br /&gt;WHEN DB_NAME(dest.dbid) IS NULL THEN 'AdhocSQL'&lt;br /&gt;ELSE DB_NAME(dest.dbid) END Databasename&lt;br /&gt;FROM sys.dm_exec_query_stats deqs&lt;br /&gt;CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest&lt;br /&gt;GROUP BY DB_NAME(dest.dbid)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-8516868969288289507?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/8516868969288289507/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=8516868969288289507' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/8516868969288289507'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/8516868969288289507'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/11/t-sql-find-busiest-databases.html' title='[T-SQL] Find Busiest Database(s)'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-1979938235375775221</id><published>2010-11-01T02:00:00.000-07:00</published><updated>2010-11-01T02:00:11.069-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='backup'/><title type='text'>[T-SQL] Taking backup at two places same time</title><content type='html'>If you want to take backup of any DB at two places same time then following tsql need to be executed.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #6aa84f;"&gt;BACKUP DATABASE [AdventureWorks] TO&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #6aa84f;"&gt;DISK = N'D:\AdventureWorks.bak'&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #6aa84f;"&gt;MIRROR TO DISK = N'E:\AdventureWorks.bak'&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #6aa84f;"&gt;WITH FORMAT, INIT,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #6aa84f;"&gt;NAME = N'AdventureWorks-Full Database Backup'&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #6aa84f;"&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Dont use the below tsql as it would break your db backup into two file and it would not serve the purpose. I mean you would be needing both of these files when you are restoring the database.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #741b47;"&gt;BACKUP DATABASE [AdventureWorks] TO&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #741b47;"&gt;DISK = N'D:\AdventureWorks.bak'&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #741b47;"&gt;, DISK = N'E:\AdventureWorks.bak'&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #741b47;"&gt;WITH FORMAT, INIT,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #741b47;"&gt;NAME = N'AdventureWorks-Full Database Backup'&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #741b47;"&gt;GO&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-1979938235375775221?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/1979938235375775221/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=1979938235375775221' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/1979938235375775221'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/1979938235375775221'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/11/t-sql-taking-backup-at-two-places-same.html' title='[T-SQL] Taking backup at two places same time'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-2451751868229008158</id><published>2010-10-27T03:25:00.000-07:00</published><updated>2010-10-27T03:25:16.007-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='identity'/><category scheme='http://www.blogger.com/atom/ns#' term='difference'/><title type='text'>[T-SQL] Difference between  @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT</title><content type='html'>&lt;b&gt;SELECT @@IDENTITY&lt;/b&gt;It returns the last IDENTITY value produced on a connection, regardless of the table that produced the value, and regardless of the scope of the statement that produced the value.&lt;br /&gt;@@IDENTITY will return the last identity value entered into a table in your current session. While @@IDENTITY is limited to the current session, it is not limited to the current scope. If you have a trigger on a table that causes an identity to be created in another table, you will get the identity that was created last, even if it was the trigger that created it.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;SELECT SCOPE_IDENTITY()&lt;/b&gt;It returns the last IDENTITY value produced on a connection and by a statement in the same scope, regardless of the table that produced the value.&lt;br /&gt;SCOPE_IDENTITY(), like @@IDENTITY, will return the last identity value created in the current session, but it will also limit it to your current scope as well. In other words, it will return the last identity value that you explicitly created, rather than any identity that was created by a trigger or a user defined function.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;SELECT IDENT_CURRENT(‘tablename’)&lt;/b&gt;It returns the last IDENTITY value produced in a table, regardless of the connection that created the value, and regardless of the scope of the statement that produced the value.&lt;br /&gt;IDENT_CURRENT is not limited by scope and session; it is limited to a specified table. IDENT_CURRENT returns the identity value generated for a specific table in any session and any scope.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-2451751868229008158?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/2451751868229008158/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=2451751868229008158' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/2451751868229008158'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/2451751868229008158'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/10/t-sql-difference-between-identity-vs.html' title='[T-SQL] Difference between  @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-3583343019198120543</id><published>2010-10-25T23:31:00.000-07:00</published><updated>2010-10-25T23:31:03.527-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='scan'/><category scheme='http://www.blogger.com/atom/ns#' term='index'/><category scheme='http://www.blogger.com/atom/ns#' term='seek'/><title type='text'>[T-SQL] Difference between Index Scan and Index Seek</title><content type='html'>&lt;b&gt;Index Scan:&lt;/b&gt;Since a scan touches every row in the table whether or not it qualifies, the cost is proportional to the total number of rows in the table. Thus, a scan is an efficient strategy if the table is small or if most of the rows qualify for the predicate.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Index Seek:&lt;/b&gt;Since a seek only touches rows that qualify and pages that contain these qualifying rows, the cost is proportional to the number of qualifying rows and pages rather than to the total number of rows in the table.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-3583343019198120543?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/3583343019198120543/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=3583343019198120543' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/3583343019198120543'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/3583343019198120543'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/10/t-sql-difference-between-index-scan-and.html' title='[T-SQL] Difference between Index Scan and Index Seek'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-3202117021328709606</id><published>2010-10-21T22:25:00.000-07:00</published><updated>2010-10-21T22:25:57.188-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='column'/><category scheme='http://www.blogger.com/atom/ns#' term='rename'/><category scheme='http://www.blogger.com/atom/ns#' term='table'/><title type='text'>[T-SQL] How to Rename a Column Name or Table Name</title><content type='html'>This morning i needed to rename column name and table name itself , so tought to share it on blog.&lt;br /&gt;&lt;br /&gt;The script for renaming any column :&lt;br /&gt;sp_RENAME 'TableName.[OldColumnName]' , '[NewColumnName]', 'COLUMN'&lt;br /&gt;&lt;br /&gt;The script for renaming any object (table, sp etc) :&lt;br /&gt;sp_RENAME 'OldTableName' , 'NewTableName'&lt;br /&gt;&lt;br /&gt;This example renames the customers table to custs.&lt;br /&gt;&lt;br /&gt;EXEC sp_rename 'customers', 'custs'&lt;br /&gt;&lt;br /&gt;This example renames the contact title column in the customers table to title.&lt;br /&gt;&lt;br /&gt;EXEC sp_rename 'customers.[contact title]', 'title', 'COLUMN'&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-3202117021328709606?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/3202117021328709606/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=3202117021328709606' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/3202117021328709606'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/3202117021328709606'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/10/t-sql-how-to-rename-column-name-or.html' title='[T-SQL] How to Rename a Column Name or Table Name'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-1100373021249001261</id><published>2010-10-20T00:05:00.000-07:00</published><updated>2010-10-20T00:06:52.829-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='alter'/><category scheme='http://www.blogger.com/atom/ns#' term='not null'/><category scheme='http://www.blogger.com/atom/ns#' term='add'/><title type='text'>[T-SQL] Add new column [Not Null] column in a table already having data</title><content type='html'>This is a very simple question and asked many times, and answer is much simpler then the question.&lt;br /&gt;&lt;br /&gt;Here is one example that we have to add a Transactiondate column into table CommissionEarned.&lt;br /&gt;&lt;br /&gt;So here are the steps:&lt;br /&gt;&lt;br /&gt;1. Add column without specifying not null&lt;br /&gt;&lt;span style="background-color: white; color: #6fa8dc;"&gt;ALTER TABLE COMMISSIONEARNED ADD [CALCULATEDDATE] [datetime]&lt;/span&gt;&lt;br /&gt;2. Add default constraint if its your business requirement&lt;br /&gt;&lt;span style="color: #6fa8dc;"&gt;ALTER TABLE COMMISSIONEARNED ADD CONSTRAINT [DF_CE_CALCULATEDDATE] DEFAULT (getdate()) FOR [CALCULATEDDATE]&lt;/span&gt;&lt;br /&gt;3. Update field with the data according to your business logic&lt;br /&gt;&lt;span style="color: #6fa8dc;"&gt;UPDATE COMMISSIONEARNED SET CALCULATEDDATE=GETDATE()&lt;/span&gt;&lt;br /&gt;4. Update field so that it should not entertain not null any more&lt;br /&gt;&lt;span style="color: #6fa8dc;"&gt;ALTER TABLE COMMISSIONEARNED ALTER COLUMN [CALCULATEDDATE] [datetime] NOT NULL&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Let me know for any questions&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-1100373021249001261?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/1100373021249001261/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=1100373021249001261' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/1100373021249001261'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/1100373021249001261'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/10/t-sql-add-new-column-not-null-column-in.html' title='[T-SQL] Add new column [Not Null] column in a table already having data'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-6987602431261774967</id><published>2010-10-18T02:53:00.000-07:00</published><updated>2010-10-18T02:53:30.879-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql'/><category scheme='http://www.blogger.com/atom/ns#' term='shortcuts'/><title type='text'>[T-SQL] My favourite SQL shortcuts</title><content type='html'>Today i would tell you my favourite sql shortcuts and the way to setup.&lt;br /&gt;&lt;br /&gt;In SSMS , go to Tools and then Options.&lt;br /&gt;&lt;br /&gt;In the tab of Options , you can setup what sql statements you run often.&lt;br /&gt;&lt;br /&gt;You can execute them very simply , just highligh the table and press what ever key you have configured.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_aStpYnZNGVg/TLwY_vRFdzI/AAAAAAAAACM/2hyXIjPzCZ8/s1600/Untitled.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" ex="true" src="http://4.bp.blogspot.com/_aStpYnZNGVg/TLwY_vRFdzI/AAAAAAAAACM/2hyXIjPzCZ8/s1600/Untitled.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-6987602431261774967?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/6987602431261774967/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=6987602431261774967' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/6987602431261774967'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/6987602431261774967'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/10/t-sql-my-favourite-sql-shortcuts.html' title='[T-SQL] My favourite SQL shortcuts'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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://4.bp.blogspot.com/_aStpYnZNGVg/TLwY_vRFdzI/AAAAAAAAACM/2hyXIjPzCZ8/s72-c/Untitled.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-342028597261074516.post-2299148657451642163</id><published>2010-10-13T03:02:00.000-07:00</published><updated>2010-10-13T03:02:12.771-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='advantage'/><category scheme='http://www.blogger.com/atom/ns#' term='stored procedure'/><title type='text'>[T-SQL] Stored Procedure Advantage</title><content type='html'>One of the SQL Expert was asked this question and which one is the best advantage, so here is the answer:&lt;br /&gt;&lt;br /&gt;There are many advantages of Stored Procedures. I was once asked what do I think is the most important feature of Stored Procedure? I have to pick only ONE. It is tough question.&lt;br /&gt;I answered : &lt;b&gt;Execution Plan Retention and Reuse &lt;/b&gt;(SP are compiled and their execution plan is cached and used again to when the same SP is executed again)&lt;br /&gt;&lt;br /&gt;Not to mentioned I received the second question following my answer : Why? Because all the other advantage known (they are mentioned below) of SP can be achieved without using SP. Though Execution Plan Retention and Reuse can only be achieved using Stored Procedure only.&lt;br /&gt;&lt;br /&gt;Execution plan retention and reuse&lt;br /&gt;Query auto-parameterization&lt;br /&gt;Encapsulation of business rules and policies&lt;br /&gt;Application modularization&lt;br /&gt;Sharing of application logic between applications&lt;br /&gt;Access to database objects that is both secure and uniform&lt;br /&gt;Consistent, safe data modification&lt;br /&gt;Network bandwidth conservation&lt;br /&gt;Support for automatic execution at system start-up&lt;br /&gt;Enhanced hardware and software capabilities&lt;br /&gt;Improved security&lt;br /&gt;Reduced development cost and increased reliability&lt;br /&gt;Centralized security, administration, and maintenance for common routines&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-2299148657451642163?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/2299148657451642163/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=2299148657451642163' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/2299148657451642163'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/2299148657451642163'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/10/t-sql-stored-procedure-advantage.html' title='[T-SQL] Stored Procedure Advantage'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-2062212677679013869</id><published>2010-10-13T02:42:00.000-07:00</published><updated>2010-10-13T02:42:29.798-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='tempdb'/><category scheme='http://www.blogger.com/atom/ns#' term='move'/><title type='text'>[T-SQL] Move TempDB from one drive to another drive if TempDB is full.</title><content type='html'>If you come across following errors in log file, please follow the direction below.&lt;br /&gt;&lt;br /&gt;Source: MSSQLSERVER&lt;br /&gt;Event ID: 17052&lt;br /&gt;Description: The LOG FILE FOR DATABASE 'tempdb' IS FULL.&lt;br /&gt;Back up the TRANSACTION LOG FOR the DATABASE TO free&lt;br /&gt;up SOME LOG SPACE&lt;br /&gt;&lt;br /&gt;Make sure that TempDB is set to autogrow and do not set a maximum size for TempDB. If the current drive is too full to allow autogrow events, then arrange a bigger drive, or add files to TempDB on another device (using ALTER DATABASE as described below and allow those files to autogrow.&lt;br /&gt;&lt;br /&gt;Move TempDB from one drive to another drive. There are major two reasons why TempDB needs to move from one drive to other drive.&lt;br /&gt;1) TempDB grows big and the existing drive does not have enough space.&lt;br /&gt;2) Moving TempDB to another file group which is on different physical drive helps to improve database disk read, as they can be read simultaneously.&lt;br /&gt;&lt;br /&gt;Follow direction below exactly to move database and log from one drive (c:) to another drive (d:) and (e:).&lt;br /&gt;&lt;br /&gt;Open Query Analyzer and connect to your server. Run this script to get the names of the files used for TempDB.&lt;br /&gt;USE TempDB&lt;br /&gt;GO&lt;br /&gt;EXEC sp_helpfile&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;Results will be something like:&lt;br /&gt;name fileid filename filegroup size&lt;br /&gt;——- —— ————————————————————– ———- ——-&lt;br /&gt;tempdev 1 C:Program FilesMicrosoft SQL ServerMSSQLdatatempdb.mdf PRIMARY 16000 KB&lt;br /&gt;templog 2 C:Program FilesMicrosoft SQL ServerMSSQLdatatemplog.ldf NULL 1024 KB&lt;br /&gt;along with other information related to the database. The names of the files are usually tempdev and demplog by default. These names will be used in next statement. Run following code, to move mdf and ldf files.&lt;br /&gt;USE master&lt;br /&gt;GO&lt;br /&gt;ALTER DATABASE TempDB MODIFY FILE&lt;br /&gt;(NAME = tempdev, FILENAME = 'd:datatempdb.mdf')&lt;br /&gt;GO&lt;br /&gt;ALTER DATABASE TempDB MODIFY FILE&lt;br /&gt;(NAME = templog, FILENAME = 'e:datatemplog.ldf')&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;The definition of the TempDB is changed. However, no changes are made to TempDB till SQL Server restarts. Please stop and restart SQL Server and it will create TempDB files in new locations.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-2062212677679013869?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/2062212677679013869/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=2062212677679013869' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/2062212677679013869'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/2062212677679013869'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/10/t-sql-move-tempdb-from-one-drive-to.html' title='[T-SQL] Move TempDB from one drive to another drive if TempDB is full.'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-6787264826909901007</id><published>2010-10-13T02:32:00.000-07:00</published><updated>2010-10-13T02:32:05.366-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='data'/><category scheme='http://www.blogger.com/atom/ns#' term='duplicate'/><category scheme='http://www.blogger.com/atom/ns#' term='delete'/><category scheme='http://www.blogger.com/atom/ns#' term='remove'/><title type='text'>[T-SQL] How to remove duplicate data</title><content type='html'>One of the very common question that is asked many times , tell the way how can we delete the duplicate data or an easiest way or fastest way.&lt;br /&gt;&lt;br /&gt;This method has one limitation that the table should have a primary key.&lt;br /&gt;&lt;br /&gt;DELETE&lt;br /&gt;FROM TableName&lt;br /&gt;WHERE ID NOT IN&lt;br /&gt;(&lt;br /&gt;SELECT MAX(ID)&lt;br /&gt;FROM TableName&lt;br /&gt;GROUP BY Col1, Col2, Col3)&lt;br /&gt;&lt;br /&gt;*TableName should be replaced with Table Name&lt;br /&gt;*Col1 , Col2 and Col3 must be replaced with the criteria on which records will qualify as duplicate. It can be increase and decrease.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-6787264826909901007?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/6787264826909901007/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=6787264826909901007' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/6787264826909901007'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/6787264826909901007'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/10/t-sql-how-to-remove-duplicate-data.html' title='[T-SQL] How to remove duplicate data'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-5693811430621941939</id><published>2010-10-13T02:24:00.000-07:00</published><updated>2010-10-13T02:24:22.089-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='data'/><category scheme='http://www.blogger.com/atom/ns#' term='csv'/><title type='text'>[T-SQL] How to generate CSV from Table Data</title><content type='html'>Here is a very simple code:&lt;br /&gt;&lt;br /&gt;DECLARE @Str VARCHAR(MAX)&lt;br /&gt;SELECT @Str = COALESCE(@Str+',' , '') + FieldName&lt;br /&gt;FROM TableName&lt;br /&gt;SELECT @Str&lt;br /&gt;&lt;br /&gt;*Field Name should be replaced with Field Name&lt;br /&gt;*Table Name should be replaced with Table Name&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-5693811430621941939?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/5693811430621941939/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=5693811430621941939' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/5693811430621941939'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/5693811430621941939'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/10/t-sql-how-to-generate-csv-from-table.html' title='[T-SQL] How to generate CSV from Table Data'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-7899903411212193503</id><published>2010-10-13T02:20:00.000-07:00</published><updated>2010-10-13T02:20:03.008-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='query'/><category scheme='http://www.blogger.com/atom/ns#' term='shortcuts'/><title type='text'>[T-SQL] Query Analyzer Shortcuts</title><content type='html'>&lt;table align="center" border="1" cellpadding="2" cellspacing="0"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Shortcut&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Function&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Shortcut&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;strong&gt;Function&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;ALT+BREAK&lt;/td&gt;&lt;td&gt;Cancel a query&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;CTRL+SHIFT+F2&lt;/td&gt;&lt;td&gt;Clear all bookmarks&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;ALT+F1&lt;/td&gt;&lt;td&gt;Database object information&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;CTRL+SHIFT+INSERT&lt;/td&gt;&lt;td&gt;Insert a template&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;ALT+F4&lt;/td&gt;&lt;td&gt;Exit&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;CTRL+SHIFT+L&lt;/td&gt;&lt;td&gt;Make selection lowercase&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CTRL+A&lt;/td&gt;&lt;td&gt;Select all&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;CTRL+SHIFT+M&lt;/td&gt;&lt;td&gt;Replace template parameters&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CTRL+B&lt;/td&gt;&lt;td&gt;Move the splitter&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;CTRL+SHIFT+P&lt;/td&gt;&lt;td&gt;Open&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CTRL+C&lt;/td&gt;&lt;td&gt;Copy&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;CTRL+SHIFT+R&lt;/td&gt;&lt;td&gt;Remove comment&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CTRL+D&lt;/td&gt;&lt;td&gt;Display results in grid format&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;CTRL+SHIFT+S&lt;/td&gt;&lt;td&gt;Show client statistics&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CTRL+Delete&lt;/td&gt;&lt;td&gt;Delete through the end of the line&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;CTRL+SHIFT+T&lt;/td&gt;&lt;td&gt;Show server trace&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CTRL+E&lt;/td&gt;&lt;td&gt;Execute query&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;CTRL+SHIFT+U&lt;/td&gt;&lt;td&gt;Make selection uppercase&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CTRL+F&lt;/td&gt;&lt;td&gt;Find&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;CTRL+T&lt;/td&gt;&lt;td&gt;Display results in text format&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CTRL+F2&lt;/td&gt;&lt;td&gt;Insert/remove bookmark&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;CTRL+U&lt;/td&gt;&lt;td&gt;Change database&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CTRL+F4&lt;/td&gt;&lt;td&gt;Disconnect&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;CTRL+V&lt;/td&gt;&lt;td&gt;Paste&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CTRL+F5&lt;/td&gt;&lt;td&gt;Parse query and check syntax&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;CTRL+W&lt;/td&gt;&lt;td&gt;Window selector&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CTRL+G&lt;/td&gt;&lt;td&gt;Go to line&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;CTRL+X&lt;/td&gt;&lt;td&gt;Delete&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CTRL+H&lt;/td&gt;&lt;td&gt;Replace&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;CTRL+Z&lt;/td&gt;&lt;td&gt;Undo&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CTRL+I&lt;/td&gt;&lt;td&gt;Index Tuning Wizard&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;F1&lt;/td&gt;&lt;td&gt;Help for Query Analyzer&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CTRL+K&lt;/td&gt;&lt;td&gt;Display/hide execution plan&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;F2&lt;/td&gt;&lt;td&gt;Move to next bookmark&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CTRL+L&lt;/td&gt;&lt;td&gt;Display execution plan&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;F3&lt;/td&gt;&lt;td&gt;Repeat last search&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CTRL+N&lt;/td&gt;&lt;td&gt;New query window&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;F4&lt;/td&gt;&lt;td&gt;Object Search&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CTRL+O&lt;/td&gt;&lt;td&gt;Connect&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;F5&lt;/td&gt;&lt;td&gt;Execute a query&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CTRL+P&lt;/td&gt;&lt;td&gt;Print&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;F6&lt;/td&gt;&lt;td&gt;Switch between query and result panes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CTRL+R&lt;/td&gt;&lt;td&gt;Show/Hide results pane&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;F8&lt;/td&gt;&lt;td&gt;Show/hide Object Browser&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CTRL+S&lt;/td&gt;&lt;td&gt;Save&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;SHIFT+F1&lt;/td&gt;&lt;td&gt;Transact-SQL help&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CTRL+SHIFT+0&lt;/td&gt;&lt;td&gt;Show options&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;SHIFT+F2&lt;/td&gt;&lt;td&gt;Move to previous bookmark&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CTRL+SHIFT+C&lt;/td&gt;&lt;td&gt;Comment out code&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;SHIFT+TAB&lt;/td&gt;&lt;td&gt;Decrease indent&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CTRL+SHIFT+DEL&lt;/td&gt;&lt;td&gt;Clear the active Editor pane&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;SHIFT+F6&lt;/td&gt;&lt;td&gt;Switch panes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CTRL+SHIFT+F&lt;/td&gt;&lt;td&gt;Save results to file&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;TAB&lt;/td&gt;&lt;td&gt;Increase indent&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-7899903411212193503?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/7899903411212193503/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=7899903411212193503' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/7899903411212193503'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/7899903411212193503'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/10/t-sql-query-analyzer-shortcuts.html' title='[T-SQL] Query Analyzer Shortcuts'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-1757292512885977522</id><published>2010-10-11T22:20:00.001-07:00</published><updated>2010-10-11T22:20:58.488-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='dml'/><category scheme='http://www.blogger.com/atom/ns#' term='ddl'/><category scheme='http://www.blogger.com/atom/ns#' term='tcl dcl'/><category scheme='http://www.blogger.com/atom/ns#' term='statements'/><title type='text'>[T-SQL] What is – DML, DDL, DCL and TCL – Introduction and Examples</title><content type='html'>&lt;b&gt;DML&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;DML is abbreviation of Data Manipulation Language. It is used to retrieve, store, modify, delete, insert and update data in database.&lt;br /&gt;&lt;br /&gt;Examples: SELECT, UPDATE, INSERT statements&lt;br /&gt;&lt;br /&gt;&lt;b&gt;DDL&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;DDL is abbreviation of Data Definition Language. It is used to create and modify the structure of database objects in database.&lt;br /&gt;&lt;br /&gt;Examples: CREATE, ALTER, DROP statements&lt;br /&gt;&lt;br /&gt;&lt;b&gt;DCL&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;DCL is abbreviation of Data Control Language. It is used to create roles, permissions, and referential integrity as well it is used to control access to database by securing it.&lt;br /&gt;&lt;br /&gt;Examples: GRANT, REVOKE statements&lt;br /&gt;&lt;br /&gt;&lt;b&gt;TCL&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;TCL is abbreviation of Transactional Control Language. It is used to manage different transactions occurring within a database.&lt;br /&gt;&lt;br /&gt;Examples: COMMIT, ROLLBACK statements&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-1757292512885977522?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/1757292512885977522/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=1757292512885977522' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/1757292512885977522'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/1757292512885977522'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/10/t-sql-what-is-dml-ddl-dcl-and-tcl.html' title='[T-SQL] What is – DML, DDL, DCL and TCL – Introduction and Examples'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-8478043539002650931</id><published>2010-10-11T22:13:00.000-07:00</published><updated>2010-10-11T22:13:33.696-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='jd'/><category scheme='http://www.blogger.com/atom/ns#' term='dba'/><title type='text'>[My-Exp] Job Description for DBA/DB Developer</title><content type='html'>This JD is copied from one of the SQL Server Experts:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Job Description of Database Administrator (DBA) or Database Developer&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;Develop standards and guidelines to guide the use and acquisition of software and to protect vulnerable information.&lt;br /&gt;&lt;br /&gt;Modify existing databases and database management systems or direct programmers and analysts to make changes.&lt;br /&gt;&lt;br /&gt;Test programs or databases, correct errors and make necessary modifications.&lt;br /&gt;&lt;br /&gt;Plan, coordinate and implement security measures to safeguard information in computer files against accidental or unauthorized damage, modification or disclosure.&lt;br /&gt;&lt;br /&gt;Approve, schedule, plan, and supervise the installation and testing of new products and improvements to computer systems, such as the installation of new databases.&lt;br /&gt;&lt;br /&gt;Train users and answer questions.&lt;br /&gt;&lt;br /&gt;Establish and calculate optimum values for database parameters, using manuals and calculator.&lt;br /&gt;&lt;br /&gt;Specify users and user access levels for each segment of database.&lt;br /&gt;&lt;br /&gt;Develop data model describing data elements and how they are used, following procedures and using pen, template or computer software.&lt;br /&gt;&lt;br /&gt;Develop methods for integrating different products so they work properly together, such as customizing commercial databases to fit specific needs.&lt;br /&gt;&lt;br /&gt;Review project requests describing database user needs to estimate time and cost required to accomplish project.&lt;br /&gt;&lt;br /&gt;Review procedures in database management system manuals for making changes to database.&lt;br /&gt;&lt;br /&gt;Work as part of a project team to coordinate database development and determine project scope and limitations.&lt;br /&gt;&lt;br /&gt;Select and enter codes to monitor database performance and to create production database.&lt;br /&gt;&lt;br /&gt;Identify and evaluate industry trends in database systems to serve as a source of information and advice for upper management.&lt;br /&gt;&lt;br /&gt;Write and code logical and physical database descriptions and specify identifiers of database to management system or direct others in coding descriptions.&lt;br /&gt;&lt;br /&gt;Review workflow charts developed by programmer analyst to understand tasks computer will perform, such as updating records.&lt;br /&gt;&lt;br /&gt;Revise company definition of data as defined in data dictionary.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-8478043539002650931?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/8478043539002650931/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=8478043539002650931' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/8478043539002650931'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/8478043539002650931'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/10/my-exp-job-description-for-dbadb.html' title='[My-Exp] Job Description for DBA/DB Developer'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-397726990490710021</id><published>2010-10-11T22:06:00.000-07:00</published><updated>2010-10-11T22:06:28.691-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='create'/><category scheme='http://www.blogger.com/atom/ns#' term='encrypted'/><category scheme='http://www.blogger.com/atom/ns#' term='stored procedure'/><title type='text'>[T-SQL] Create and Encrypted Stored Procedure</title><content type='html'>An answer to a very simple question , how to create a stored procedure any problem if we create it.&lt;br /&gt;&lt;br /&gt;Here is the script&lt;br /&gt;&lt;br /&gt;USE AdventureWorks&lt;br /&gt;GO&lt;br /&gt;-- Create Encyrpted SP&lt;br /&gt;CREATE PROCEDURE uspEnc&lt;br /&gt;WITH ENCRYPTION&lt;br /&gt;AS&lt;br /&gt;SELECT *&lt;br /&gt;FROM Sales.SalesOrderDetail&lt;br /&gt;UNION&lt;br /&gt;SELECT *&lt;br /&gt;FROM Sales.SalesOrderDetail&lt;br /&gt;GO&lt;br /&gt;-- Execute SP&lt;br /&gt;EXEC uspEnc&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;Question:  if any stored procedure is encrypted can we see its definition in Activity Monitor.&lt;br /&gt;Answer: No&lt;br /&gt;&lt;br /&gt;Question: Any tool to decrypt the SP&lt;br /&gt;Answer: SQL Decryptor, Decrypt SQL&lt;br /&gt;&lt;br /&gt;Question: Should a DBA recommend it&lt;br /&gt;Answer: Encrypted stored procedures are horrible. You can’t see what queries are executed, you don’t have a clue what the execution plan is. So if users are complaining about the slowness of the system, and everything is encrypted… then it will not be possible to look into it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-397726990490710021?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/397726990490710021/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=397726990490710021' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/397726990490710021'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/397726990490710021'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/10/t-sql-create-and-encrypted-stored.html' title='[T-SQL] Create and Encrypted Stored Procedure'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-1000758764935926830</id><published>2010-10-11T21:56:00.000-07:00</published><updated>2010-10-11T21:56:20.294-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='query'/><category scheme='http://www.blogger.com/atom/ns#' term='session'/><category scheme='http://www.blogger.com/atom/ns#' term='running'/><title type='text'>[T-SQL] Get Running Query from the Sessions</title><content type='html'>If you want to get the query running of one of the session then you can get from the query below , just answering that if you want to know the running sessions then you can use sp_who and sp_who2.&lt;br /&gt;&lt;br /&gt;Before executing this statement please change the option from result to grid to result to text. For this you can use shortcut CTRL+T.&lt;br /&gt;&lt;br /&gt;Here is the script, 55 can be replaced from your desired session id.&lt;br /&gt;&lt;br /&gt;DECLARE @sqltext VARBINARY(128)&lt;br /&gt;SELECT @sqltext = sql_handle&lt;br /&gt;FROM sys.sysprocesses&lt;br /&gt;WHERE spid = 55&lt;br /&gt;SELECT TEXT&lt;br /&gt;FROM sys.dm_exec_sql_text(@sqltext)&lt;br /&gt;GO&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-1000758764935926830?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/1000758764935926830/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=1000758764935926830' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/1000758764935926830'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/1000758764935926830'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/10/t-sql-get-running-query-from-sessions.html' title='[T-SQL] Get Running Query from the Sessions'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-5474756970593283093</id><published>2010-10-11T21:40:00.000-07:00</published><updated>2010-10-11T21:56:56.160-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='stored procedure'/><category scheme='http://www.blogger.com/atom/ns#' term='get numbers'/><title type='text'>[T-SQL] Get Numbers from Alpha Numeric Value</title><content type='html'>Here is the procedure i just saw from one of the sql expert blog that will rreturn Numbers from Alpha Numeric Values.&lt;br /&gt;&lt;br /&gt;CREATE PROCEDURE [dbo].[GetNumbers]&lt;br /&gt;@alpha VARCHAR(50),&lt;br /&gt;@decimal DECIMAL(14, 5) OUTPUT&lt;br /&gt;AS BEGIN&lt;br /&gt;SET NOCOUNT ON;&lt;br /&gt;DECLARE @ErrorMsg VARCHAR(50)&lt;br /&gt;DECLARE @Pos INT&lt;br /&gt;DECLARE @CommaPos INT&lt;br /&gt;DECLARE @ZeroExists INT&lt;br /&gt;DECLARE @alphaReverse VARCHAR(50)&lt;br /&gt;DECLARE @NumPos INT&lt;br /&gt;DECLARE @Len INT&lt;br /&gt;-- 1 Reverse the alpha in order to get the last position of a numeric value&lt;br /&gt;SET @alphaReverse = REVERSE(@alpha)&lt;br /&gt;-- 2 Get the last position of a numeric figure&lt;br /&gt;SET @NumPos = PATINDEX('%[0-9]%', @alphaReverse)&lt;br /&gt;-- 3 Get the lenght of the string&lt;br /&gt;SET @Len = LEN(@alpha)&lt;br /&gt;-- 4 Add a comma after the numeric data in case it's no decimal number&lt;br /&gt;SET @alpha = SUBSTRING(@alpha, 1, (@Len - @NumPos + 1))&lt;br /&gt;+ ','&lt;br /&gt;+ SUBSTRING(@alpha, (@Len - @NumPos + 2), 50)&lt;br /&gt;-- Check if there is a zero (0) in the @alpha, then we later set the @decimal to 0&lt;br /&gt;-- if it's 0 after the handling, else we set @decimal to NULL&lt;br /&gt;-- If 0 no match, else there is a match&lt;br /&gt;SET @ZeroExists = CHARINDEX ( '0' , @alpha ,1 )&lt;br /&gt;-- Find position of , (comma)&lt;br /&gt;SET @CommaPos = 1&lt;br /&gt;SET @CommaPos = PATINDEX('%,%', @alpha)&lt;br /&gt;IF (@CommaPos = '') BEGIN&lt;br /&gt;SET @CommaPos = 20&lt;br /&gt;END&lt;br /&gt;SET @Pos = PATINDEX('%[^0-9]%',@alpha)&lt;br /&gt;-- Replaces any aplha with '0' since we otherwice can't keep track of where the decimal&lt;br /&gt;-- should be put in. We assume the numeric number has no aplhe inside. The regular way&lt;br /&gt;-- to solve this is to replace with ”, but then we miss the way to find the place to&lt;br /&gt;-- put in the decimal.&lt;br /&gt;WHILE (@Pos &gt; 0) BEGIN&lt;br /&gt;SET @alpha = STUFF(@alpha, @pos, 1, '0')&lt;br /&gt;SET @Pos = PATINDEX('%[^0-9]%',@alpha)&lt;br /&gt;END&lt;br /&gt;IF (@alpha IS NOT NULL AND @alpha != '') BEGIN&lt;br /&gt;SET @decimal = CONVERT(DECIMAL(14, 5), SUBSTRING(@alpha, 1, (@CommaPos - 1))&lt;br /&gt;+ '.'&lt;br /&gt;+ SUBSTRING(@alpha, (@CommaPos + 1), 20))&lt;br /&gt;END&lt;br /&gt;-- Since we in this case don't want to set 0 if where is no numeric value, we set NULL to be safe&lt;br /&gt;IF (@decimal = 0 AND @ZeroExists = 0) BEGIN&lt;br /&gt;SET @decimal = NULL&lt;br /&gt;END&lt;br /&gt;END&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;If you run above SP as shown below it will work&lt;br /&gt;DECLARE @myVal DECIMAL(14,5)&lt;br /&gt;EXEC [GetNumbers] 'ABC455,88ghf', @myVal OUTPUT&lt;br /&gt;SELECT @myVal RValue&lt;br /&gt;&lt;br /&gt;RValue&lt;br /&gt;---------------------------------------&lt;br /&gt;455.88000&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-5474756970593283093?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/5474756970593283093/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=5474756970593283093' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/5474756970593283093'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/5474756970593283093'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/10/t-sql-get-numbers-from-alpha-numeric.html' title='[T-SQL] Get Numbers from Alpha Numeric Value'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-4612114186661849047</id><published>2010-10-08T00:55:00.000-07:00</published><updated>2010-10-08T00:55:20.853-07:00</updated><title type='text'>[My-Exp] Query Optimized</title><content type='html'>Few days back i blogged that my manager said to me to optimize an sp , so here is the story for this:&lt;br /&gt;&lt;br /&gt;The sp was not running for one day data even in 45 mins, but now its running in 4 mins for one month data. So here are the tips of what i did.&lt;br /&gt;&lt;br /&gt;1. Added "with recompile" in sp.&lt;br /&gt;2. Added "SET NOCOUNT ON;&amp;nbsp;&amp;nbsp;" &lt;br /&gt;3. Applied Parameter sniffing&lt;br /&gt;4. Created two Non clustered indexes on one of the table.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-4612114186661849047?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/4612114186661849047/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=4612114186661849047' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/4612114186661849047'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/4612114186661849047'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/10/my-exp-query-optimized.html' title='[My-Exp] Query Optimized'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-1159755349761574315</id><published>2010-10-07T04:05:00.000-07:00</published><updated>2010-10-07T04:05:07.415-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='cache'/><category scheme='http://www.blogger.com/atom/ns#' term='clear'/><category scheme='http://www.blogger.com/atom/ns#' term='buffer'/><category scheme='http://www.blogger.com/atom/ns#' term='stored procedure'/><title type='text'>[T-SQL] Clear Cache and Buffer of Stored Procedure</title><content type='html'>Use DBCC FREEPROCCACHE to clear the procedure cache. Freeing the procedure cache would cause, for example, an ad-hoc SQL statement to be recompiled rather than reused from the cache. If observing through SQL Profiler, one can watch the Cache Remove events occur as DBCC FREEPROCCACHE goes to work. DBCC FREEPROCCACHE will invalidate all stored procedure plans that the optimizer has cached in memory and force SQL Server to compile new plans the next time those procedures are run.&lt;br /&gt;&lt;br /&gt;Use DBCC DROPCLEANBUFFERS to test queries with a cold buffer cache without shutting down and restarting the server. DBCC DROPCLEANBUFFERS serves to empty the data cache. Any data loaded into the buffer cache due to the prior execution of a query is removed.&lt;br /&gt;&lt;br /&gt;DBCC FREEPROCCACHE&lt;br /&gt;DBCC DROPCLEANBUFFERS&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-1159755349761574315?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/1159755349761574315/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=1159755349761574315' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/1159755349761574315'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/1159755349761574315'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/10/t-sql-clear-cache-and-buffer-of-stored.html' title='[T-SQL] Clear Cache and Buffer of Stored Procedure'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-7732031317112699657</id><published>2010-10-06T23:23:00.001-07:00</published><updated>2010-10-06T23:24:08.808-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='reorganize'/><category scheme='http://www.blogger.com/atom/ns#' term='index'/><category scheme='http://www.blogger.com/atom/ns#' term='rebuild'/><title type='text'>[T-SQL] Index rebuild or reorganize , which one to use ?</title><content type='html'>Index Rebuild : &lt;strong&gt;This process drops the existing Index and Recreates the index.&lt;/strong&gt;&lt;br /&gt;USE AdventureWorks;&lt;br /&gt;GO&lt;br /&gt;ALTER INDEX ALL ON Production.Product REBUILD&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;Index Reorganize : &lt;strong&gt;This process physically reorganizes the leaf nodes of the index.&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;USE AdventureWorks;&lt;/strong&gt;&lt;br /&gt;GO&lt;br /&gt;ALTER INDEX ALL ON Production.Product REORGANIZE&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Recommendation:&lt;/strong&gt; Index should be rebuild when index fragmentation is great than 40%. Index should be reorganized when index fragmentation is between 10% to 40%. Index rebuilding process uses more CPU and it locks the database resources. SQL Server development version and Enterprise version has option ONLINE, which can be turned on when Index is rebuilt. ONLINE option will keep index available during the rebuilding.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-7732031317112699657?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/7732031317112699657/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=7732031317112699657' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/7732031317112699657'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/7732031317112699657'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/10/t-sql-index-rebuild-or-reorganize-which.html' title='[T-SQL] Index rebuild or reorganize , which one to use ?'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-3526478773656540962</id><published>2010-10-06T22:38:00.000-07:00</published><updated>2010-10-06T22:38:09.673-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='index'/><category scheme='http://www.blogger.com/atom/ns#' term='identify'/><category scheme='http://www.blogger.com/atom/ns#' term='fragmentation'/><title type='text'>[T-SQL] How to find index fragmentation</title><content type='html'>This script will tell you the index fragmentation stats:&lt;br /&gt;&lt;br /&gt;SELECT ps.database_id, ps.OBJECT_ID,&lt;br /&gt;ps.index_id, b.name,&lt;br /&gt;ps.avg_fragmentation_in_percent&lt;br /&gt;FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL, NULL, NULL) AS ps&lt;br /&gt;INNER JOIN sys.indexes AS b ON ps.OBJECT_ID = b.OBJECT_ID&lt;br /&gt;AND ps.index_id = b.index_id&lt;br /&gt;WHERE ps.database_id = DB_ID()&lt;br /&gt;ORDER BY ps.OBJECT_ID&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-3526478773656540962?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/3526478773656540962/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=3526478773656540962' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/3526478773656540962'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/3526478773656540962'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/10/t-sql-how-to-find-index-fragmentation.html' title='[T-SQL] How to find index fragmentation'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-8431269335910115485</id><published>2010-10-06T21:57:00.000-07:00</published><updated>2010-10-06T21:57:56.283-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='query'/><category scheme='http://www.blogger.com/atom/ns#' term='identify'/><category scheme='http://www.blogger.com/atom/ns#' term='session'/><category scheme='http://www.blogger.com/atom/ns#' term='blocking'/><title type='text'>[T-SQL] Identify Blocking Query / Session</title><content type='html'>One of the most common problem that DBA faces is that one or many sessions get blocked by some sessions due to long execution or deadlock. I have many times faced this problem and also read the same problem which is faced by many DBAs every day.&lt;br /&gt;&lt;br /&gt;Here is the query by which you can kill the blocking session:&lt;br /&gt;Kill 3 ( 3 is the blocking session )&lt;br /&gt;&lt;br /&gt;But now your question would be how to identify the blocking session , so here we go...&lt;br /&gt;&lt;br /&gt;SELECT&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;db.name DBName,&lt;br /&gt;&lt;br /&gt;tl.request_session_id,&lt;br /&gt;&lt;br /&gt;wt.blocking_session_id,&lt;br /&gt;&lt;br /&gt;OBJECT_NAME(p.OBJECT_ID) BlockedObjectName,&lt;br /&gt;&lt;br /&gt;tl.resource_type,&lt;br /&gt;&lt;br /&gt;h1.TEXT AS RequestingText,&lt;br /&gt;&lt;br /&gt;h2.TEXT AS BlockingTest,&lt;br /&gt;&lt;br /&gt;tl.request_mode&lt;br /&gt;&lt;br /&gt;FROM sys.dm_tran_locks AS tl&lt;br /&gt;&lt;br /&gt;INNER JOIN sys.databases db ON db.database_id = tl.resource_database_id&lt;br /&gt;&lt;br /&gt;INNER JOIN sys.dm_os_waiting_tasks AS wt ON tl.lock_owner_address = wt.resource_address&lt;br /&gt;&lt;br /&gt;INNER JOIN sys.partitions AS p ON p.hobt_id = tl.resource_associated_entity_id&lt;br /&gt;&lt;br /&gt;INNER JOIN sys.dm_exec_connections ec1 ON ec1.session_id = tl.request_session_id&lt;br /&gt;&lt;br /&gt;INNER JOIN sys.dm_exec_connections ec2 ON ec2.session_id = wt.blocking_session_id&lt;br /&gt;&lt;br /&gt;CROSS APPLY sys.dm_exec_sql_text(ec1.most_recent_sql_handle) AS h1&lt;br /&gt;&lt;br /&gt;CROSS APPLY sys.dm_exec_sql_text(ec2.most_recent_sql_handle) AS h2&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/342028597261074516-8431269335910115485?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/8431269335910115485/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=8431269335910115485' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/8431269335910115485'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/8431269335910115485'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/10/t-sql-identify-blocking-query-session.html' title='[T-SQL] Identify Blocking Query / Session'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-4033956940501224900</id><published>2010-10-05T22:58:00.000-07:00</published><updated>2010-10-05T22:58:25.181-07:00</updated><title type='text'>[T-SQL] Optimize Stored Procedure</title><content type='html'>Today in morning when i came , i was having an email of my boss telling that there is an high priority issue which need to solved on immediate basis. And it was to optimize sp as it was creating a huge problem. I am currently working on it but here are some tips to get the job done:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;1. Include SET NOCOUNT ON statement: &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;With every SELECT and DML statement, the SQL server returns a message that indicates the number of affected rows by that statement. This information is mostly helpful in debugging the code, but it is useless after that. By setting SET NOCOUNT ON, we can disable the feature of returning this extra information. For stored procedures that contain several statements or contain Transact-SQL loops, setting SET NOCOUNT to ON can provide a significant performance boost because network traffic is greatly reduced.&lt;br /&gt;CREATE PROC dbo.ProcName&lt;br /&gt;AS&lt;br /&gt;SET NOCOUNT ON;&lt;br /&gt;--Procedure code here&lt;br /&gt;SELECT column1 FROM dbo.TblTable1&lt;br /&gt;-- Reset SET NOCOUNT to OFF&lt;br /&gt;SET NOCOUNT OFF;&lt;br /&gt;GO &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;2. Use schema name with object name:&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;The object name is qualified if used with schema name. Schema name should be used with the stored procedure name and with all objects referenced inside the stored procedure. This help in directly finding the complied plan instead of searching the objects in other possible schema before finally deciding to use a cached plan, if available. This process of searching and deciding a schema for an object leads to COMPILE lock on stored procedure and decreases the stored procedure’s performance. Therefore, always refer the objects with qualified name in the stored procedure like&lt;br /&gt;SELECT * FROM dbo.MyTable -- Preferred method&lt;br /&gt;-- Instead of&lt;br /&gt;SELECT * FROM MyTable -- Avoid this method&lt;br /&gt;--And finally call the stored procedure with qualified name like:&lt;br /&gt;EXEC dbo.MyProc -- Preferred method&lt;br /&gt;--Instead of&lt;br /&gt;EXEC MyProc -- Avoid this method&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;3. Do not use the prefix “sp_” in the stored procedure name: &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;If a stored procedure name begins with “SP_,” then SQL server first searches in the master database and then in the current session database. Searching in the master database causes extra overhead and even a wrong result if another stored procedure with the same name is found in master database.&lt;br /&gt;Use IF EXISTS (SELECT 1) instead of (SELECT *): To check the existence of a record in another table, we uses the IF EXISTS clause. The IF EXISTS clause returns True if any value is returned from an internal statement, either a single value “1” or all columns of a record or complete recordset. The output of the internal statement is not used. Hence, to minimize the data for processing and network transferring, we should use “1” in the SELECT clause of an internal statement, as shown below:&lt;br /&gt;IF EXISTS (SELECT 1 FROM sysobjects&lt;br /&gt;WHERE name = 'MyTable' AND type = 'U') &lt;br /&gt;Use the sp_executesql stored procedure instead of the EXECUTE statement.&lt;br /&gt;The sp_executesql stored procedure supports parameters. So, using the sp_executesql stored procedure instead of the EXECUTE statement improve the re-usability of your code. The execution plan of a dynamic statement can be reused only if each and every character, including case, space, comments and parameter, is same for two statements. For example, if we execute the below batch:&lt;br /&gt;DECLARE @Query VARCHAR(100)&lt;br /&gt;DECLARE @Age INT&lt;br /&gt;SET @Age = 25&lt;br /&gt;SET @Query = 'SELECT * FROM dbo.tblPerson WHERE Age = ' + CONVERT(VARCHAR(3),@Age)&lt;br /&gt;EXEC (@Query)&lt;br /&gt;&lt;br /&gt;If we again execute the above batch using different @Age value, then the execution plan for SELECT statement created for @Age =25 would not be reused. However, if we write the above batch as given below,&lt;br /&gt;&lt;br /&gt;DECLARE @Query NVARCHAR(100)&lt;br /&gt;SET @Query = N'SELECT * FROM dbo.tblPerson WHERE Age = @Age'&lt;br /&gt;EXECUTE sp_executesql @Query, N'@Age int', @Age = 25&lt;br /&gt;&lt;br /&gt;the compiled plan of this SELECT statement will be reused for different value of @Age parameter. The reuse of the existing complied plan will result in improved performance.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;4. Try to avoid using SQL Server cursors whenever possible: &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Cursor uses a lot of resources for overhead processing to maintain current record position in a recordset and this decreases the performance. If we need to process records one-by-one in a loop, then we should use the WHILE clause. Wherever possible, we should replace the cursor-based approach with SET-based approach. Because the SQL Server engine is designed and optimized to perform SET-based operation very fast. Again, please note cursor is also a kind of WHILE Loop.&lt;br /&gt;Keep the Transaction as short as possible: The length of transaction affects blocking and deadlocking. Exclusive lock is not released until the end of transaction. In higher isolation level, the shared locks are also aged with transaction. Therefore, lengthy transaction means locks for longer time and locks for longer time turns into blocking. In some cases, blocking also converts into deadlocks. So, for faster execution and less blocking, the transaction should be kept as short as possible.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;5. Use TRY-Catch for error handling: &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Prior to SQL server 2005 version code for error handling, there was a big portion of actual code because an error check statement was written after every t-sql statement. More code always consumes more resources and time. In SQL Server 2005, a new simple way is introduced for the same purpose. The syntax is as follows:&lt;br /&gt;BEGIN TRY&lt;br /&gt;--Your t-sql code goes here&lt;br /&gt;END TRY&lt;br /&gt;BEGIN CATCH&lt;br /&gt;--Your error handling code goes here&lt;br /&gt;END CATCH&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-4033956940501224900?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/4033956940501224900/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=4033956940501224900' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/4033956940501224900'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/4033956940501224900'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/10/t-sql-optimize-stored-procedure.html' title='[T-SQL] Optimize Stored Procedure'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-7708379976159051783</id><published>2010-10-05T02:41:00.000-07:00</published><updated>2010-10-05T02:41:00.870-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='restore'/><category scheme='http://www.blogger.com/atom/ns#' term='ldf'/><category scheme='http://www.blogger.com/atom/ns#' term='database'/><category scheme='http://www.blogger.com/atom/ns#' term='mdf'/><title type='text'>[T-SQL] Restore database trough mdf file only , ldf missing</title><content type='html'>One of my friend just call me and told that he has an mdf file but no ldf file , so if want to restore db then what to do , i searched over internet and found two fastest methods for it&lt;br /&gt;&lt;br /&gt;USE [master]&lt;br /&gt;GO&lt;br /&gt;-- Method 1: I use this method&lt;br /&gt;EXEC sp_attach_single_file_db @dbname='TestDb',&lt;br /&gt;@physname=N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\TestDb.mdf'&lt;br /&gt;GO&lt;br /&gt;-- Method 2:&lt;br /&gt;CREATE DATABASE TestDb ON&lt;br /&gt;(FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\TestDb.mdf')&lt;br /&gt;FOR ATTACH_REBUILD_LOG&lt;br /&gt;GO&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-7708379976159051783?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/7708379976159051783/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=7708379976159051783' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/7708379976159051783'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/7708379976159051783'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/10/t-sql-restore-database-trough-mdf-file.html' title='[T-SQL] Restore database trough mdf file only , ldf missing'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-1201336582615279503</id><published>2010-10-05T02:20:00.000-07:00</published><updated>2010-10-05T02:20:28.799-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='process'/><category scheme='http://www.blogger.com/atom/ns#' term='kill'/><title type='text'>[T-SQL]  Kill All Process in Database</title><content type='html'>I was just going trough one query and find out that it was giving one error , but its really useful script for killing all process. One thing just be sure that you are not killing the process from the db instance from where you are running the query.&lt;br /&gt;&lt;br /&gt;CREATE TABLE #TmpWho&lt;br /&gt;(spid INT, ecid INT, status VARCHAR(150), loginame VARCHAR(150),&lt;br /&gt;hostname VARCHAR(150), blk INT, dbname VARCHAR(150), cmd VARCHAR(150), rquest_id INT)&lt;br /&gt;INSERT INTO #TmpWho&lt;br /&gt;EXEC sp_who&lt;br /&gt;DECLARE @spid INT&lt;br /&gt;DECLARE @tString VARCHAR(15)&lt;br /&gt;DECLARE @getspid CURSOR&lt;br /&gt;SET @getspid =   CURSOR FOR&lt;br /&gt;SELECT spid&lt;br /&gt;FROM #TmpWho&lt;br /&gt;WHERE dbname = 'mydb'OPEN @getspid&lt;br /&gt;FETCH NEXT FROM @getspid INTO @spid&lt;br /&gt;WHILE @@FETCH_STATUS = 0&lt;br /&gt;BEGIN&lt;br /&gt;SET @tString = 'KILL ' + CAST(@spid AS VARCHAR(5))&lt;br /&gt;EXEC(@tString)&lt;br /&gt;FETCH NEXT FROM @getspid INTO @spid&lt;br /&gt;END&lt;br /&gt;CLOSE @getspid&lt;br /&gt;DEALLOCATE @getspid&lt;br /&gt;DROP TABLE #TmpWho&lt;br /&gt;GO&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-1201336582615279503?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/1201336582615279503/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=1201336582615279503' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/1201336582615279503'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/1201336582615279503'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/10/t-sql-kill-all-process-in-database.html' title='[T-SQL]  Kill All Process in Database'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-756438882148711483</id><published>2010-10-04T22:03:00.000-07:00</published><updated>2010-10-04T22:03:05.253-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rename'/><category scheme='http://www.blogger.com/atom/ns#' term='physical file name'/><category scheme='http://www.blogger.com/atom/ns#' term='data files'/><title type='text'>[T-SQL] Renaming the Physical Filename for Datafiles in SQL Server 2008</title><content type='html'>I just got a question in morning  , that how can one rename the physical filename for data files in sql server 2008. So here is the link and then some of the methods which ever suits you&lt;br /&gt;&lt;br /&gt;http://technet.microsoft.com/en-us/library/ms174269.aspx&lt;br /&gt;&lt;br /&gt;There are several ways to make this change, however to rename the physical database files at operating system level you will have to take the database offline&lt;br /&gt;&lt;br /&gt;1. Use SSMS to take the database Offline (right-click on Database, select Tasks, Take Offline), change the name of the files at the OS level and then Bring it Online.&lt;br /&gt;&lt;br /&gt;2. You could Detach the database, rename the files and then Attach the database pointing to the renamed files to do so.&lt;br /&gt;&lt;br /&gt;3. You could Backup the database and then restore, changing the file location during the restore process.&lt;br /&gt;&lt;br /&gt;4. using T SQL&lt;br /&gt;&lt;br /&gt;ALTER DATABASE databaseName SET OFFLINE&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;ALTER DATABASE databaseNAme MODIFY FILE (NAME =db, FILENAME = 'C:\Program&lt;br /&gt;Files\Microsoft SQL Server\MSSQL.2\MSSQL\Data\db.mdf')&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;--if changing log file name &lt;br /&gt;ALTER DATABASE  databaseNAme MODIFY FILE (NAME = db_log, FILENAME =&lt;br /&gt;'C:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\Data\db.ldf')&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;ALTER DATABASE databaseName SET ONLINE&lt;br /&gt;GO&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-756438882148711483?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/756438882148711483/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=756438882148711483' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/756438882148711483'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/756438882148711483'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/10/t-sql-renaming-physical-filename-for.html' title='[T-SQL] Renaming the Physical Filename for Datafiles in SQL Server 2008'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-4477289357804109906</id><published>2010-09-30T01:45:00.000-07:00</published><updated>2010-09-30T01:45:23.707-07:00</updated><title type='text'>Differnces between a RDBMS schema and a data warehouse schema</title><content type='html'>RDBMS Schema&lt;br /&gt;* Main Purpose: Record&lt;br /&gt;* Used for OLTP systems&lt;br /&gt;* Highly Normalized&lt;br /&gt;* Difficult to understand and navigate&lt;br /&gt;* Difficult to extract and solve complex problems&lt;br /&gt;&lt;br /&gt;DWH Schema&lt;br /&gt;* Main Purpose: Respond&lt;br /&gt;* Used for OLAP systems&lt;br /&gt;* De-normalized&lt;br /&gt;* Easy to understand and navigate&lt;br /&gt;* Relatively easier in extracting the data and solving complex problems&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-4477289357804109906?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/4477289357804109906/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=4477289357804109906' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/4477289357804109906'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/4477289357804109906'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/09/differnces-between-rdbms-schema-and.html' title='Differnces between a RDBMS schema and a data warehouse schema'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-6516843558801136803</id><published>2010-09-30T01:42:00.001-07:00</published><updated>2010-09-30T01:42:39.911-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='oltp'/><category scheme='http://www.blogger.com/atom/ns#' term='olap'/><category scheme='http://www.blogger.com/atom/ns#' term='difference'/><title type='text'>Differences between OLTP and OLAP</title><content type='html'>Main Differences between OLTP and OLAP are:-&lt;br /&gt;1. User and System Orientation&lt;br /&gt;OLTP: customer-oriented, used for data analysis and querying by clerks, clients and IT professionals.&lt;br /&gt;OLAP: market-oriented, used for data analysis by knowledge workers( managers, executives, analysis).&lt;br /&gt;2. Data Contents&lt;br /&gt;OLTP: manages current data, very detail-oriented.&lt;br /&gt;OLAP: manages large amounts of historical data, provides facilities for summarization and aggregation, stores information at different levels of granularity to support decision making process.&lt;br /&gt;3. Database Design&lt;br /&gt;OLTP: adopts an entity relationship(ER) model and an application-oriented database design.&lt;br /&gt;OLAP: adopts star, snowflake or fact constellation model and a subject-oriented database design.&lt;br /&gt;4. View&lt;br /&gt;OLTP: focuses on the current data within an enterprise or department.&lt;br /&gt;OLAP: spans multiple versions of a database schema due to the evolutionary process of an organization; integrates information from many organizational locations and data stores&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-6516843558801136803?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/6516843558801136803/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=6516843558801136803' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/6516843558801136803'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/6516843558801136803'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/09/differences-between-oltp-and-olap.html' title='Differences between OLTP and OLAP'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-637768631309543926</id><published>2010-09-27T04:43:00.000-07:00</published><updated>2010-09-27T04:43:45.387-07:00</updated><title type='text'>Difference between Database and Data Warehouse</title><content type='html'>I was just searching on net for basic difference between the two of my core expertise and one of the best extract I found is pasted below:&lt;br /&gt;&lt;br /&gt;So how is a data warehouse different from you regular database? After all, both are databases, and both have some tables containing data. If you look deeper, you'd find that both have indexes, keys, views, and the regular jing-bang. So is that 'Data warehouse' really different from the tables in you application? And if the two aren't really different, maybe you can just run your queries and reports directly from your application databases!&lt;br /&gt;&lt;br /&gt;Well, to be fair, that may be just what you are doing right now, running some EOD (end-of-day) reports as complex SQL queries and shipping them off to those who need them. And this scheme might just be serving you fine right now. Nothing wrong with that if it works for you.&lt;br /&gt;&lt;br /&gt;But before you start patting yourself on the back for having avoided a data warehouse altogether, do spend a moment to understand the differences, and to appreciate the pros and cons of either approach.&lt;br /&gt;&lt;br /&gt;The primary difference betwen you application database and a data warehouse is that while the former is designed (and optimized) to record , the latter has to be designed (and optimized) to respond to analysis questions that are critical for your business. &lt;br /&gt;&lt;br /&gt;Application databases are OLTP (On-Line Transaction Processing) systems where every transaction has to be recorded, and super-fast at that. Consider the scenario where a bank ATM has disbursed cash to a customer but was unable to record this event in the bank records. If this started happening frequently, the bank wouldn't stay in business for too long. So the banking system is designed to make sure that every trasaction gets recorded within the time you stand before the ATM machine. This system is write-optimized, and you shouldn't crib if your analysis query (read operation) takes a lot of time on such a system.&lt;br /&gt;&lt;br /&gt;A Data Warehouse (DW) on the other end, is a database (yes, you are right, it's a database) that is designed for facilitating querying and analysis. Often designed as OLAP (On-Line Analytical Processing) systems, these databases contain read-only data that can be queried and analysed far more efficiently as compared to your regular OLTP application databases. In this sense an OLAP system is designed to be read-optimized.&lt;br /&gt;&lt;br /&gt;Separation from your application database also ensures that your business intelligence solution is scalable (your bank and ATMs don't go down just because the CFO asked for a report), better documented and managed (god help the novice who is given the application database diagrams and asked to locate the needle of data in the proverbial haystack of table proliferation), and can answer questions far more efficietly and frequently.&lt;br /&gt;&lt;br /&gt;Creation of a DW leads to a direct increase in quality of analyses as the table structures are simpler (you keep only the needed information in simpler tables), standardized (well-documented table structures), and often denormalized (to reduce the linkages between tables and the corresponding complexity of queries). A DW drastically reduces the 'cost-per-analysis' and thus permits more analysis per FTE. Having a well-designed DW is the foundation successful BI/Analytics initiatives are built upon.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-637768631309543926?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/637768631309543926/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=637768631309543926' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/637768631309543926'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/637768631309543926'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/09/difference-between-database-and-data.html' title='Difference between Database and Data Warehouse'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-6402131573720301867</id><published>2010-09-26T23:25:00.000-07:00</published><updated>2010-09-26T23:25:28.170-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='log'/><category scheme='http://www.blogger.com/atom/ns#' term='grow'/><category scheme='http://www.blogger.com/atom/ns#' term='truncate'/><title type='text'>[T-SQL] How to Stop Growing Log File Too Big</title><content type='html'>In continuation of my last post "http://muhammadabbas.blogspot.com/2010/09/t-sql-truncate-log-file.html" , i am writing this article.&lt;br /&gt;&lt;br /&gt;Today i was reading an article and this article highlighted that how could we stop the log file to grow. Here is the text:&lt;br /&gt;&lt;br /&gt;Two different solutions for it:&lt;br /&gt;&lt;br /&gt;1) Convert the Recovery Model to Simple Recovery&lt;br /&gt;&lt;br /&gt;If you are truncating the transaction logs, this means you are breaking the T-Log LSN (Log Sequence Numbers). This follows that if disaster comes, you would not be able to restore your T-Logs and there would be no option for you to do point in time recovery. If you are fine with this situation and there is nothing to worry, I suggest that you change your recovery model to Simple Recovery Model. This way, you will not have extra ordinary growth of your log file.&lt;br /&gt;&lt;br /&gt;2) Start Taking Transaction Log Backup&lt;br /&gt;&lt;br /&gt;If your business does not support loss of data or requires having point in time recovery, you cannot afford anything less than Full Recovery Model. In Full Recovery Model, your transaction log will grow until you take a backup of it. You need to take the T-Log Backup at a regular interval. This way, your log would not grow beyond some limits. If you are taking an hourly T-Log backup, your T-Log would grow until one hour but after this the T-Log backup would truncate all the ‘committed’ transactions once you take it. Doing this would lead the size of the T-Log not to go down much, but it would rather be marked as empty for the next hour’s T-Log to populate.&lt;br /&gt;&lt;br /&gt;With this method, you can restore your database at Point of Time if a disaster ever happens at your server.&lt;br /&gt;&lt;br /&gt;Let us run an example to demonstrate this. In this case, I have done the following steps:&lt;br /&gt;&lt;br /&gt;1.Create Sample Database in FULL RECOVERY Model&lt;br /&gt;2.Take Full Backup (full backup is must for taking subsequent backup)&lt;br /&gt;3.Repeat Following Operation &lt;br /&gt;1.Take Log Backup&lt;br /&gt;2.Insert Some rows&lt;br /&gt;3.Check the size of Log File&lt;br /&gt;4.Clean Up&lt;br /&gt;After a short while, you will notice that the Log file (ldf) will stop increasing but the size of the backup will increase.&lt;br /&gt;&lt;br /&gt;If you have an issue with your log file growth, I suggest that you follow either of the above solutions instead of truncating it.&lt;br /&gt;&lt;br /&gt;/* FULL Recovery and Log File Growth */&lt;br /&gt;USE [master]&lt;br /&gt;GO&lt;br /&gt;-- Create Database SimpleTran&lt;br /&gt;IF EXISTS (SELECT name FROM sys.databases WHERE name = N'SimpleTran')&lt;br /&gt;BEGIN&lt;br /&gt;ALTER DATABASE [SimpleTran] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;&lt;br /&gt;DROP DATABASE [SimpleTran]&lt;br /&gt;END&lt;br /&gt;GO&lt;br /&gt;CREATE DATABASE [SimpleTran]&lt;br /&gt;GO&lt;br /&gt;-- Set Database backup model to FULL&lt;br /&gt;ALTER DATABASE [SimpleTran] SET RECOVERY FULL&lt;br /&gt;GO&lt;br /&gt;BACKUP DATABASE [SimpleTran] TO  DISK = N'D:\SimpleTran.bak' WITH NOFORMAT, NOINIT, NAME = N'SimpleTran-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10&lt;br /&gt;GO&lt;br /&gt;-- Check Database Log File Size&lt;br /&gt;SELECT DB_NAME(database_id) AS DatabaseName,&lt;br /&gt;Name AS Logical_Name,&lt;br /&gt;Physical_Name, (size*8)/1024 SizeMB&lt;br /&gt;FROM sys.master_files&lt;br /&gt;WHERE DB_NAME(database_id) = 'SimpleTran'&lt;br /&gt;GO&lt;br /&gt;-- Create Table in Database with Transaction&lt;br /&gt;USE SimpleTran&lt;br /&gt;GO&lt;br /&gt;IF EXISTS (SELECT * FROM sys.objects WHERE OBJECT_ID = OBJECT_ID(N'[dbo].[RealTempTable]') AND TYPE IN (N'U'))&lt;br /&gt;DROP TABLE [dbo].[RealTempTable]&lt;br /&gt;GO&lt;br /&gt;CREATE TABLE RealTempTable (ID INT)&lt;br /&gt;INSERT INTO RealTempTable (ID)&lt;br /&gt;SELECT TOP 50000 ROW_NUMBER() OVER (ORDER BY a.name) RowID&lt;br /&gt;FROM sys.all_objects a&lt;br /&gt;CROSS JOIN sys.all_objects b&lt;br /&gt;GO&lt;br /&gt;-- Check the size of the Database&lt;br /&gt;SELECT DB_NAME(database_id) AS DatabaseName,&lt;br /&gt;Name AS Logical_Name,&lt;br /&gt;Physical_Name, (size*8)/1024 SizeMB&lt;br /&gt;FROM sys.master_files&lt;br /&gt;WHERE DB_NAME(database_id) = 'SimpleTran'&lt;br /&gt;GO&lt;br /&gt;-- Take Full Backup&lt;br /&gt;BACKUP LOG [SimpleTran] TO  DISK = N'D:\SimpleTran.bak' WITH NOFORMAT, NOINIT, NAME = N'SimpleTran-Transaction Log  Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10&lt;br /&gt;GO&lt;br /&gt;-- Run following transaction multiple times and check the size of T-Log&lt;br /&gt;INSERT INTO RealTempTable (ID)&lt;br /&gt;SELECT TOP 50000 ROW_NUMBER() OVER (ORDER BY a.name) RowID&lt;br /&gt;FROM sys.all_objects a&lt;br /&gt;CROSS JOIN sys.all_objects b&lt;br /&gt;GO&lt;br /&gt;-- Check the size of the Database&lt;br /&gt;SELECT DB_NAME(database_id) AS DatabaseName,&lt;br /&gt;Name AS Logical_Name,&lt;br /&gt;Physical_Name, (size*8)/1024 SizeMB&lt;br /&gt;FROM sys.master_files&lt;br /&gt;WHERE DB_NAME(database_id) = 'SimpleTran'&lt;br /&gt;GO&lt;br /&gt;/*&lt;br /&gt;Now run following code multiple times.&lt;br /&gt;You will notice that it will not increase the size of .ldf file but will for sure&lt;br /&gt;increasethe size of the log backup.&lt;br /&gt;*/&lt;br /&gt;-- Second Time&lt;br /&gt;-- START&lt;br /&gt;BACKUP LOG [SimpleTran] TO  DISK = N'D:\SimpleTran.log' WITH NOFORMAT, NOINIT, NAME = N'SimpleTran-Transaction Log  Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10&lt;br /&gt;GO&lt;br /&gt;-- Run following transaction and check the size of T-Log&lt;br /&gt;INSERT INTO RealTempTable (ID)&lt;br /&gt;SELECT TOP 50000 ROW_NUMBER() OVER (ORDER BY a.name) RowID&lt;br /&gt;FROM sys.all_objects a&lt;br /&gt;CROSS JOIN sys.all_objects b&lt;br /&gt;GO&lt;br /&gt;-- Check the size of the Database&lt;br /&gt;SELECT DB_NAME(database_id) AS DatabaseName,&lt;br /&gt;Name AS Logical_Name,&lt;br /&gt;Physical_Name, (size*8)/1024 SizeMB&lt;br /&gt;FROM sys.master_files&lt;br /&gt;WHERE DB_NAME(database_id) = 'SimpleTran'&lt;br /&gt;GO&lt;br /&gt;-- END&lt;br /&gt;--Clean Up&lt;br /&gt;USE MASTER&lt;br /&gt;GO&lt;br /&gt;IF EXISTS (SELECT name FROM sys.databases WHERE name = N'SimpleTran')&lt;br /&gt;BEGIN&lt;br /&gt;ALTER DATABASE [SimpleTran] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;&lt;br /&gt;DROP DATABASE [SimpleTran]&lt;br /&gt;END&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-6402131573720301867?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/6402131573720301867/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=6402131573720301867' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/6402131573720301867'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/6402131573720301867'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/09/t-sql-how-to-stop-growing-log-file-too.html' title='[T-SQL] How to Stop Growing Log File Too Big'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-1411866822471946277</id><published>2010-09-26T23:19:00.000-07:00</published><updated>2010-09-26T23:19:41.866-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='log'/><category scheme='http://www.blogger.com/atom/ns#' term='truncate'/><title type='text'>[T-SQL] Truncate Log File</title><content type='html'>Few days back , i was called by my friend who was working on community database with a problem that log file of his db was growing bigger and he was worried about it. So i went there and saw that its not a big issue and told him that i would prepare a script and give him so that he could run that once in a month:&lt;br /&gt;&lt;br /&gt;USE TEST;&lt;br /&gt;GO&lt;br /&gt;-- Truncate the log by changing the database recovery model to SIMPLE.&lt;br /&gt;ALTER DATABASE TEST&lt;br /&gt;SET RECOVERY SIMPLE;&lt;br /&gt;GO&lt;br /&gt;-- Shrink the truncated log file to 1 MB.&lt;br /&gt;DBCC SHRINKFILE (TEST_log, 1);&lt;br /&gt;GO&lt;br /&gt;-- Reset the database recovery model.&lt;br /&gt;ALTER DATABASE TEST&lt;br /&gt;SET RECOVERY FULL;&lt;br /&gt;GO&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-1411866822471946277?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/1411866822471946277/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=1411866822471946277' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/1411866822471946277'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/1411866822471946277'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/09/t-sql-truncate-log-file.html' title='[T-SQL] Truncate Log File'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-7231444189216290921</id><published>2010-09-23T02:24:00.001-07:00</published><updated>2010-09-23T02:24:55.484-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='delete'/><category scheme='http://www.blogger.com/atom/ns#' term='generate'/><category scheme='http://www.blogger.com/atom/ns#' term='script'/><title type='text'>[T-SQL] Generate Delete script for all tables</title><content type='html'>You can use this script for generate delete script or even trncate&lt;br /&gt;&lt;br /&gt;select 'delete from ' + o.name + ';'&lt;br /&gt;from sysobjects o &lt;br /&gt;where o.type = 'U';&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-7231444189216290921?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/7231444189216290921/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=7231444189216290921' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/7231444189216290921'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/7231444189216290921'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/09/t-sql-generate-delete-script-for-all.html' title='[T-SQL] Generate Delete script for all tables'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-6300609219753719000</id><published>2010-09-22T23:22:00.001-07:00</published><updated>2010-09-22T23:22:41.679-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='data'/><category scheme='http://www.blogger.com/atom/ns#' term='delete'/><category scheme='http://www.blogger.com/atom/ns#' term='fk'/><title type='text'>[T-SQL] Delete all data in database (when you have FKs)</title><content type='html'>SET NOCOUNT ON&lt;br /&gt;GO&lt;br /&gt; &lt;br /&gt;SELECT 'USE [' + db_name() +']';&lt;br /&gt; &lt;br /&gt;SELECT 'ALTER TABLE ' + &lt;br /&gt;       '[' + s.name + '].[' + t.name + ']' +&lt;br /&gt;       ' DROP CONSTRAINT [' + f.name +']'&lt;br /&gt;  FROM sys.foreign_keys f&lt;br /&gt; INNER JOIN sys.TABLES t ON f.parent_object_id=t.object_id&lt;br /&gt; INNER JOIN sys.schemas s ON t.schema_id=s.schema_id&lt;br /&gt; WHERE t.is_ms_shipped=0;&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;SELECT 'TRUNCATE TABLE ' + '[' + s.name + '].[' + t.name + ']'      &lt;br /&gt;  FROM sys.TABLES t&lt;br /&gt; INNER JOIN sys.schemas s ON t.schema_id=s.schema_id&lt;br /&gt; WHERE t.is_ms_shipped=0;&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;SELECT 'ALTER TABLE ' + &lt;br /&gt;       '[' + s.name + '].[' + t.name + ']' +&lt;br /&gt;       ' ADD CONSTRAINT [' + f.name + ']' +&lt;br /&gt;       ' FOREIGN KEY (' +        &lt;br /&gt;       Stuff( (SELECT ', ['+col_name(fk.parent_object_id, fk.parent_column_id) +']'&lt;br /&gt;                 FROM sys.foreign_key_columns fk&lt;br /&gt;                WHERE constraint_object_id = f.object_id &lt;br /&gt;                ORDER BY constraint_column_id&lt;br /&gt;                  FOR XML Path('')&lt;br /&gt;            ), 1,2,'') + ')' +&lt;br /&gt;       ' REFERENCES [' + &lt;br /&gt;       object_schema_name(f.referenced_object_id)+'].['+object_name(f.referenced_object_id) + '] (' +&lt;br /&gt;       Stuff((SELECT ', ['+col_name(fc.referenced_object_id, fc.referenced_column_id)+']' &lt;br /&gt;                FROM sys.foreign_key_columns fc&lt;br /&gt;               WHERE constraint_object_id = f.object_id &lt;br /&gt;               ORDER BY constraint_column_id&lt;br /&gt;                 FOR XML Path('')),&lt;br /&gt;              1,2,'') +&lt;br /&gt;        ')' + &lt;br /&gt;        ' ON DELETE ' + REPLACE(f.delete_referential_action_desc, '_', ' ')  +&lt;br /&gt;        ' ON UPDATE ' + REPLACE(f.update_referential_action_desc , '_', ' ') collate database_default &lt;br /&gt;  FROM sys.foreign_keys f&lt;br /&gt; INNER JOIN sys.TABLES t ON f.parent_object_id=t.object_id&lt;br /&gt; INNER JOIN sys.schemas s ON t.schema_id=s.schema_id&lt;br /&gt; WHERE t.is_ms_shipped=0;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-6300609219753719000?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/6300609219753719000/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=6300609219753719000' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/6300609219753719000'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/6300609219753719000'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/09/t-sql-delete-all-data-in-database-when.html' title='[T-SQL] Delete all data in database (when you have FKs)'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-5954827789034614820</id><published>2010-09-20T02:23:00.001-07:00</published><updated>2010-09-20T02:23:44.845-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='row count'/><title type='text'>[T-SQL] Row Count in Tables</title><content type='html'>Below is the query trough which you can get row counts from all the tables:&lt;br /&gt;&lt;br /&gt;SELECT sc.name +'.'+ ta.name TableName&lt;br /&gt;,SUM(pa.rows) RowCnt&lt;br /&gt;FROM sys.tables ta&lt;br /&gt;INNER JOIN sys.partitions pa&lt;br /&gt;ON pa.OBJECT_ID = ta.OBJECT_ID&lt;br /&gt;INNER JOIN sys.schemas sc&lt;br /&gt;ON ta.schema_id = sc.schema_id&lt;br /&gt;WHERE ta.is_ms_shipped = 0 AND pa.index_id IN (1,0)&lt;br /&gt;GROUP BY sc.name,ta.name&lt;br /&gt;ORDER BY SUM(pa.rows) DESC&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-5954827789034614820?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/5954827789034614820/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=5954827789034614820' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/5954827789034614820'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/5954827789034614820'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/09/t-sql-row-count-in-tables.html' title='[T-SQL] Row Count in Tables'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-5753939201333075497</id><published>2010-09-20T02:06:00.001-07:00</published><updated>2010-09-20T02:07:33.614-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sys.stats'/><category scheme='http://www.blogger.com/atom/ns#' term='stats'/><category scheme='http://www.blogger.com/atom/ns#' term='delete'/><title type='text'>[T-SQL] Find Auto Created Stats and Delete query for them</title><content type='html'>Query for getting them:&lt;br /&gt;&lt;br /&gt;SELECT name, OBJECT_NAME(OBJECT_ID)&lt;br /&gt;FROM sys.stats&lt;br /&gt;WHERE auto_created = 1;&lt;br /&gt;&lt;br /&gt;Delete query for one of the table stats:&lt;br /&gt;&lt;br /&gt;DROP STATISTICS TableName.StatisticsName&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-5753939201333075497?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/5753939201333075497/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=5753939201333075497' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/5753939201333075497'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/5753939201333075497'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/09/t-sql-find-auto-created-stats-and.html' title='[T-SQL] Find Auto Created Stats and Delete query for them'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-7450116287896001059</id><published>2010-09-16T04:27:00.000-07:00</published><updated>2010-09-16T04:27:02.556-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='personal'/><title type='text'>[Personal] Blessed by a baby boy</title><content type='html'>On 23rd Ramazan , i was blessed by a baby boy. Too cuteeeee.&lt;br /&gt;&lt;br /&gt;His grand father has kept his name "Ali Imran".&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-7450116287896001059?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/7450116287896001059/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=7450116287896001059' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/7450116287896001059'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/7450116287896001059'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/09/personal-blessed-by-baby-boy.html' title='[Personal] Blessed by a baby boy'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-8413031652253426407</id><published>2010-09-16T03:38:00.000-07:00</published><updated>2010-09-16T03:38:27.400-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='error'/><title type='text'>[T-SQL] Transport Level Error</title><content type='html'>This is the error which i encountered now a days very much:&lt;br /&gt;&lt;br /&gt;A transport-level error has occurred when sending the request to the&lt;br /&gt;server.&lt;br /&gt;&lt;br /&gt;Here is the reason for it:&lt;br /&gt;&lt;br /&gt;You used to have an open connection to a server but you don’t any more. It was closed or killed from the server side. Maybe the server rebooted (or failed-over to another cluster node). You’re talking into one tin can, but nobody’s on the tin can on the other end of the string.&lt;br /&gt;&lt;br /&gt;Annoying, but not a problem… open a new connection and try again. If you see this error message from inside SQL Server Management Studio, just hit F5 again (or Alt-X or Ctrl-E depending on preference).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-8413031652253426407?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/8413031652253426407/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=8413031652253426407' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/8413031652253426407'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/8413031652253426407'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/09/t-sql-transport-level-error.html' title='[T-SQL] Transport Level Error'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-94435497895717964</id><published>2010-09-16T03:12:00.000-07:00</published><updated>2010-09-16T03:12:07.938-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='link'/><category scheme='http://www.blogger.com/atom/ns#' term='article'/><title type='text'>[T-SQL] Very Nice Article Regarding T-SQL</title><content type='html'>A very nice article regarding Dont's of T-SQL:&lt;br /&gt;&lt;br /&gt;http://michaeljswart.com/?p=823&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-94435497895717964?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/94435497895717964/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=94435497895717964' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/94435497895717964'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/94435497895717964'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/09/t-sql-very-nice-article-regarding-t-sql.html' title='[T-SQL] Very Nice Article Regarding T-SQL'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-4920684039937874592</id><published>2010-08-23T23:58:00.000-07:00</published><updated>2010-08-23T23:58:33.216-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='function'/><category scheme='http://www.blogger.com/atom/ns#' term='first word'/><category scheme='http://www.blogger.com/atom/ns#' term='string'/><title type='text'>[T-SQL] Function to Retrieve First Word of Sentence</title><content type='html'>--This code/function can help to get you first word from a sentence.&lt;br /&gt;--TEST SCRIPT&lt;br /&gt;DECLARE @StringVar VARCHAR(100)&lt;br /&gt;SET @StringVar = ' anything '&lt;br /&gt;SELECT CASE CHARINDEX(' ', LTRIM(@StringVar), 1)&lt;br /&gt;WHEN 0 THEN LTRIM(@StringVar)&lt;br /&gt;ELSE SUBSTRING(LTRIM(@StringVar), 1, CHARINDEX(' ',LTRIM(@StringVar), 1) - 1)&lt;br /&gt;END FirstWordofSentence&lt;br /&gt;&lt;br /&gt;--FUNCTION CODE&lt;br /&gt;CREATE FUNCTION GetFirstWord (@StringVar VARCHAR(MAX))&lt;br /&gt;RETURNS VARCHAR(MAX)&lt;br /&gt;AS&lt;br /&gt;BEGIN&lt;br /&gt;DECLARE @rtStringVar VARCHAR(MAX)&lt;br /&gt;SELECT @rtStringVar = CASE CHARINDEX(' ', LTRIM(@StringVar), 1)&lt;br /&gt;WHEN 0 THEN LTRIM(@StringVar)&lt;br /&gt;ELSE SUBSTRING(LTRIM(@StringVar), 1, CHARINDEX(' ',LTRIM(@StringVar), 1) - 1)&lt;br /&gt;END&lt;br /&gt;RETURN @rtStringVar&lt;br /&gt;END&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-4920684039937874592?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/4920684039937874592/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=4920684039937874592' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/4920684039937874592'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/4920684039937874592'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/08/t-sql-function-to-retrieve-first-word.html' title='[T-SQL] Function to Retrieve First Word of Sentence'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-6873123571362562558</id><published>2010-08-18T22:20:00.001-07:00</published><updated>2010-08-18T22:20:43.665-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='column into row'/><category scheme='http://www.blogger.com/atom/ns#' term='concatenate'/><title type='text'>[T-SQL] To concatenate the values of a column in all rows into one row.</title><content type='html'>USE pubs&lt;br /&gt;GO&lt;br /&gt;DECLARE @title_ids varchar(150), @delimiter char&lt;br /&gt;SET @delimiter = ','&lt;br /&gt;SELECT @title_ids = COALESCE(@title_ids + @delimiter, '') + title_id FROM titles&lt;br /&gt;SELECT @title_ids AS [List of Title IDs]&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-6873123571362562558?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/6873123571362562558/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=6873123571362562558' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/6873123571362562558'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/6873123571362562558'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/08/t-sql-to-concatenate-values-of-column.html' title='[T-SQL] To concatenate the values of a column in all rows into one row.'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-3782889817754738893</id><published>2010-08-18T22:18:00.001-07:00</published><updated>2010-08-18T22:18:18.014-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='function'/><category scheme='http://www.blogger.com/atom/ns#' term='proper case'/><title type='text'>[T-SQL] To convert a given string to proper case</title><content type='html'>CREATE FUNCTION PROPERCASE&lt;br /&gt;(&lt;br /&gt;--The string to be converted to proper case&lt;br /&gt;@input varchar(8000)&lt;br /&gt;)&lt;br /&gt;--This function returns the proper case string of varchar type&lt;br /&gt;RETURNS varchar(8000)&lt;br /&gt;AS&lt;br /&gt;BEGIN&lt;br /&gt; IF @input IS NULL &lt;br /&gt; BEGIN&lt;br /&gt;  --Just return NULL if input string is NULL&lt;br /&gt;  RETURN NULL&lt;br /&gt; END&lt;br /&gt; &lt;br /&gt; --Character variable declarations&lt;br /&gt; DECLARE @output varchar(8000)&lt;br /&gt; --Integer variable declarations&lt;br /&gt; DECLARE @ctr int, @len int, @found_at int&lt;br /&gt; --Constant declarations&lt;br /&gt; DECLARE @LOWER_CASE_a int, @LOWER_CASE_z int, @Delimiter char(3), @UPPER_CASE_A int, @UPPER_CASE_Z int&lt;br /&gt; &lt;br /&gt; --Variable/Constant initializations&lt;br /&gt; SET @ctr = 1&lt;br /&gt; SET @len = LEN(@input)&lt;br /&gt; SET @output = ''&lt;br /&gt; SET @LOWER_CASE_a = 97&lt;br /&gt; SET @LOWER_CASE_z = 122&lt;br /&gt; SET @Delimiter = ' ,-'&lt;br /&gt; SET @UPPER_CASE_A = 65&lt;br /&gt; SET @UPPER_CASE_Z = 90&lt;br /&gt; &lt;br /&gt; WHILE @ctr &lt;= @len BEGIN  --This loop will take care of reccuring white spaces  WHILE CHARINDEX(SUBSTRING(@input,@ctr,1), @Delimiter) &gt; 0&lt;br /&gt;  BEGIN&lt;br /&gt;   SET @output = @output + SUBSTRING(@input,@ctr,1)&lt;br /&gt;   SET @ctr = @ctr + 1&lt;br /&gt;  END&lt;br /&gt;&lt;br /&gt;  IF ASCII(SUBSTRING(@input,@ctr,1)) BETWEEN @LOWER_CASE_a AND @LOWER_CASE_z&lt;br /&gt;  BEGIN&lt;br /&gt;   --Converting the first character to upper case&lt;br /&gt;   SET @output = @output + UPPER(SUBSTRING(@input,@ctr,1))&lt;br /&gt;  END&lt;br /&gt;  ELSE&lt;br /&gt;  BEGIN&lt;br /&gt;   SET @output = @output + SUBSTRING(@input,@ctr,1)&lt;br /&gt;  END&lt;br /&gt;  &lt;br /&gt;  SET @ctr = @ctr + 1&lt;br /&gt;&lt;br /&gt;  WHILE CHARINDEX(SUBSTRING(@input,@ctr,1), @Delimiter) = 0 AND (@ctr &lt;= @len)&lt;br /&gt;  BEGIN&lt;br /&gt;   IF ASCII(SUBSTRING(@input,@ctr,1)) BETWEEN @UPPER_CASE_A AND @UPPER_CASE_Z&lt;br /&gt;   BEGIN&lt;br /&gt;    SET @output = @output + LOWER(SUBSTRING(@input,@ctr,1))&lt;br /&gt;   END&lt;br /&gt;   ELSE&lt;br /&gt;   BEGIN&lt;br /&gt;    SET @output = @output + SUBSTRING(@input,@ctr,1)&lt;br /&gt;   END&lt;br /&gt;   SET @ctr = @ctr + 1&lt;br /&gt;  END&lt;br /&gt;  &lt;br /&gt; END&lt;br /&gt;RETURN @output&lt;br /&gt;END&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-3782889817754738893?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/3782889817754738893/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=3782889817754738893' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/3782889817754738893'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/3782889817754738893'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/08/t-sql-to-convert-given-string-to-proper.html' title='[T-SQL] To convert a given string to proper case'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-6365276451589363313</id><published>2010-08-18T22:16:00.000-07:00</published><updated>2010-08-18T22:16:09.538-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='biggest'/><category scheme='http://www.blogger.com/atom/ns#' term='list'/><category scheme='http://www.blogger.com/atom/ns#' term='table'/><category scheme='http://www.blogger.com/atom/ns#' term='database'/><title type='text'>[T-SQL] Get Biggest Table on Your Production DB</title><content type='html'>USE master&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;IF EXISTS (SELECT 1 FROM sysobjects WHERE name = 'sp_show_huge_tables' AND type = 'P')&lt;br /&gt;DROP PROC sp_show_huge_tables&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;CREATE PROC sp_show_huge_tables&lt;br /&gt;(&lt;br /&gt;@top   int = NULL,&lt;br /&gt;@include_system_tables  bit  = 0&lt;br /&gt;)&lt;br /&gt;AS&lt;br /&gt;&lt;br /&gt;BEGIN&lt;br /&gt; IF @top &gt; 0&lt;br /&gt; SET ROWCOUNT @top&lt;br /&gt;&lt;br /&gt; SELECT [Table Name], (SELECT rows FROM sysindexes s WHERE s.indid &lt; 2 AND s.id = OBJECT_ID(a.[Table Name])) AS [Row count], [Total space used (MB)] FROM  &lt;br /&gt; (&lt;br /&gt; SELECT QUOTENAME(USER_NAME(o.uid)) + '.' + QUOTENAME(OBJECT_NAME(i.id)) AS [Table Name],&lt;br /&gt;  CONVERT(numeric(15,2),(((CONVERT(numeric(15,2),SUM(i.reserved)) * (SELECT low FROM master.dbo.spt_values (NOLOCK) WHERE number = 1 AND type = 'E')) / 1024.)/1024.)) AS [Total space used (MB)]&lt;br /&gt; FROM sysindexes i (NOLOCK)&lt;br /&gt;   INNER JOIN &lt;br /&gt;  sysobjects o (NOLOCK) &lt;br /&gt;   ON &lt;br /&gt;  i.id = o.id AND &lt;br /&gt;  ((@include_system_tables = 1 AND o.type IN ('U', 'S')) OR o.type = 'U') AND &lt;br /&gt;  ((@include_system_tables = 1)OR (OBJECTPROPERTY(i.id, 'IsMSShipped') = 0))&lt;br /&gt; WHERE indid IN (0, 1, 255)&lt;br /&gt; GROUP BY QUOTENAME(USER_NAME(o.uid)) + '.' + QUOTENAME(OBJECT_NAME(i.id))&lt;br /&gt; &lt;br /&gt; ) as a&lt;br /&gt;ORDER BY [Total space used (MB)] DESC&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; SET ROWCOUNT 0&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;GRANT EXEC ON sp_show_huge_tables TO Public&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-6365276451589363313?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/6365276451589363313/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=6365276451589363313' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/6365276451589363313'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/6365276451589363313'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/08/t-sql-get-biggest-table-on-your.html' title='[T-SQL] Get Biggest Table on Your Production DB'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-2697333782080778634</id><published>2010-08-18T22:11:00.000-07:00</published><updated>2010-08-18T22:11:01.629-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='data'/><category scheme='http://www.blogger.com/atom/ns#' term='script'/><category scheme='http://www.blogger.com/atom/ns#' term='insert'/><title type='text'>[T-SQL] Procedure to script your data (to generate INSERT statements from the existing data)</title><content type='html'>SET NOCOUNT ON&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;PRINT 'Using Master database'&lt;br /&gt;USE master&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;PRINT 'Checking for the existence of this procedure'&lt;br /&gt;IF (SELECT OBJECT_ID('sp_generate_inserts','P')) IS NOT NULL --means, the procedure already exists&lt;br /&gt; BEGIN&lt;br /&gt;  PRINT 'Procedure already exists. So, dropping it'&lt;br /&gt;  DROP PROC sp_generate_inserts&lt;br /&gt; END&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;CREATE PROC sp_generate_inserts&lt;br /&gt;(&lt;br /&gt; @table_name varchar(776),    -- The table/view for which the INSERT statements will be generated using the existing data&lt;br /&gt; @target_table varchar(776) = NULL,  -- Use this parameter to specify a different table name into which the data will be inserted&lt;br /&gt; @include_column_list bit = 1,  -- Use this parameter to include/ommit column list in the generated INSERT statement&lt;br /&gt; @from varchar(800) = NULL,   -- Use this parameter to filter the rows based on a filter condition (using WHERE)&lt;br /&gt; @include_timestamp bit = 0,   -- Specify 1 for this parameter, if you want to include the TIMESTAMP/ROWVERSION column's data in the INSERT statement&lt;br /&gt; @debug_mode bit = 0,   -- If @debug_mode is set to 1, the SQL statements constructed by this procedure will be printed for later examination&lt;br /&gt; @owner varchar(64) = NULL,  -- Use this parameter if you are not the owner of the table&lt;br /&gt; @ommit_images bit = 0,   -- Use this parameter to generate INSERT statements by omitting the 'image' columns&lt;br /&gt; @ommit_identity bit = 0,  -- Use this parameter to ommit the identity columns&lt;br /&gt; @top int = NULL,   -- Use this parameter to generate INSERT statements only for the TOP n rows&lt;br /&gt; @cols_to_include varchar(8000) = NULL, -- List of columns to be included in the INSERT statement&lt;br /&gt; @cols_to_exclude varchar(8000) = NULL, -- List of columns to be excluded from the INSERT statement&lt;br /&gt; @disable_constraints bit = 0,  -- When 1, disables foreign key constraints and enables them after the INSERT statements&lt;br /&gt; @ommit_computed_cols bit = 0  -- When 1, computed columns will not be included in the INSERT statement&lt;br /&gt; &lt;br /&gt;)&lt;br /&gt;AS&lt;br /&gt;BEGIN&lt;br /&gt;&lt;br /&gt;/***********************************************************************************************************&lt;br /&gt;Procedure: sp_generate_inserts  (Build 22) &lt;br /&gt;  (Copyright © 2002 Narayana Vyas Kondreddi. All rights reserved.)&lt;br /&gt;                                          &lt;br /&gt;Purpose: To generate INSERT statements from existing data. &lt;br /&gt;  These INSERTS can be executed to regenerate the data at some other location.&lt;br /&gt;  This procedure is also useful to create a database setup, where in you can &lt;br /&gt;  script your data along with your table definitions.&lt;br /&gt;&lt;br /&gt;Written by: Narayana Vyas Kondreddi&lt;br /&gt;         http://vyaskn.tripod.com&lt;br /&gt;&lt;br /&gt;Acknowledgements:&lt;br /&gt;  Divya Kalra -- For beta testing&lt;br /&gt;  Mark Charsley -- For reporting a problem with scripting uniqueidentifier columns with NULL values&lt;br /&gt;  Artur Zeygman -- For helping me simplify a bit of code for handling non-dbo owned tables&lt;br /&gt;  Joris Laperre   -- For reporting a regression bug in handling text/ntext columns&lt;br /&gt;&lt;br /&gt;Tested on:  SQL Server 7.0 and SQL Server 2000 and SQL Server 2005&lt;br /&gt;&lt;br /&gt;Date created: January 17th 2001 21:52 GMT&lt;br /&gt;&lt;br /&gt;Date modified: May 1st 2002 19:50 GMT&lt;br /&gt;&lt;br /&gt;Email:   vyaskn@hotmail.com&lt;br /&gt;&lt;br /&gt;NOTE:  This procedure may not work with tables with too many columns.&lt;br /&gt;  Results can be unpredictable with huge text columns or SQL Server 2000's sql_variant data types&lt;br /&gt;  Whenever possible, Use @include_column_list parameter to ommit column list in the INSERT statement, for better results&lt;br /&gt;  IMPORTANT: This procedure is not tested with internation data (Extended characters or Unicode). If needed&lt;br /&gt;  you might want to convert the datatypes of character variables in this procedure to their respective unicode counterparts&lt;br /&gt;  like nchar and nvarchar&lt;br /&gt;&lt;br /&gt;  ALSO NOTE THAT THIS PROCEDURE IS NOT UPDATED TO WORK WITH NEW DATA TYPES INTRODUCED IN SQL SERVER 2005 / YUKON&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;Example 1: To generate INSERT statements for table 'titles':&lt;br /&gt;  &lt;br /&gt;  EXEC sp_generate_inserts 'titles'&lt;br /&gt;&lt;br /&gt;Example 2:  To ommit the column list in the INSERT statement: (Column list is included by default)&lt;br /&gt;  IMPORTANT: If you have too many columns, you are advised to ommit column list, as shown below,&lt;br /&gt;  to avoid erroneous results&lt;br /&gt;  &lt;br /&gt;  EXEC sp_generate_inserts 'titles', @include_column_list = 0&lt;br /&gt;&lt;br /&gt;Example 3: To generate INSERT statements for 'titlesCopy' table from 'titles' table:&lt;br /&gt;&lt;br /&gt;  EXEC sp_generate_inserts 'titles', 'titlesCopy'&lt;br /&gt;&lt;br /&gt;Example 4: To generate INSERT statements for 'titles' table for only those titles &lt;br /&gt;  which contain the word 'Computer' in them:&lt;br /&gt;  NOTE: Do not complicate the FROM or WHERE clause here. It's assumed that you are good with T-SQL if you are using this parameter&lt;br /&gt;&lt;br /&gt;  EXEC sp_generate_inserts 'titles', @from = "from titles where title like '%Computer%'"&lt;br /&gt;&lt;br /&gt;Example 5:  To specify that you want to include TIMESTAMP column's data as well in the INSERT statement:&lt;br /&gt;  (By default TIMESTAMP column's data is not scripted)&lt;br /&gt;&lt;br /&gt;  EXEC sp_generate_inserts 'titles', @include_timestamp = 1&lt;br /&gt;&lt;br /&gt;Example 6: To print the debug information:&lt;br /&gt;  &lt;br /&gt;  EXEC sp_generate_inserts 'titles', @debug_mode = 1&lt;br /&gt;&lt;br /&gt;Example 7:  If you are not the owner of the table, use @owner parameter to specify the owner name&lt;br /&gt;  To use this option, you must have SELECT permissions on that table&lt;br /&gt;&lt;br /&gt;  EXEC sp_generate_inserts Nickstable, @owner = 'Nick'&lt;br /&gt;&lt;br /&gt;Example 8:  To generate INSERT statements for the rest of the columns excluding images&lt;br /&gt;  When using this otion, DO NOT set @include_column_list parameter to 0.&lt;br /&gt;&lt;br /&gt;  EXEC sp_generate_inserts imgtable, @ommit_images = 1&lt;br /&gt;&lt;br /&gt;Example 9:  To generate INSERT statements excluding (ommiting) IDENTITY columns:&lt;br /&gt;  (By default IDENTITY columns are included in the INSERT statement)&lt;br /&gt;&lt;br /&gt;  EXEC sp_generate_inserts mytable, @ommit_identity = 1&lt;br /&gt;&lt;br /&gt;Example 10:  To generate INSERT statements for the TOP 10 rows in the table:&lt;br /&gt;  &lt;br /&gt;  EXEC sp_generate_inserts mytable, @top = 10&lt;br /&gt;&lt;br /&gt;Example 11:  To generate INSERT statements with only those columns you want:&lt;br /&gt;  &lt;br /&gt;  EXEC sp_generate_inserts titles, @cols_to_include = "'title','title_id','au_id'"&lt;br /&gt;&lt;br /&gt;Example 12:  To generate INSERT statements by omitting certain columns:&lt;br /&gt;  &lt;br /&gt;  EXEC sp_generate_inserts titles, @cols_to_exclude = "'title','title_id','au_id'"&lt;br /&gt;&lt;br /&gt;Example 13: To avoid checking the foreign key constraints while loading data with INSERT statements:&lt;br /&gt;  &lt;br /&gt;  EXEC sp_generate_inserts titles, @disable_constraints = 1&lt;br /&gt;&lt;br /&gt;Example 14:  To exclude computed columns from the INSERT statement:&lt;br /&gt;  EXEC sp_generate_inserts MyTable, @ommit_computed_cols = 1&lt;br /&gt;***********************************************************************************************************/&lt;br /&gt;&lt;br /&gt;SET NOCOUNT ON&lt;br /&gt;&lt;br /&gt;--Making sure user only uses either @cols_to_include or @cols_to_exclude&lt;br /&gt;IF ((@cols_to_include IS NOT NULL) AND (@cols_to_exclude IS NOT NULL))&lt;br /&gt; BEGIN&lt;br /&gt;  RAISERROR('Use either @cols_to_include or @cols_to_exclude. Do not use both the parameters at once',16,1)&lt;br /&gt;  RETURN -1 --Failure. Reason: Both @cols_to_include and @cols_to_exclude parameters are specified&lt;br /&gt; END&lt;br /&gt;&lt;br /&gt;--Making sure the @cols_to_include and @cols_to_exclude parameters are receiving values in proper format&lt;br /&gt;IF ((@cols_to_include IS NOT NULL) AND (PATINDEX('''%''',@cols_to_include) = 0))&lt;br /&gt; BEGIN&lt;br /&gt;  RAISERROR('Invalid use of @cols_to_include property',16,1)&lt;br /&gt;  PRINT 'Specify column names surrounded by single quotes and separated by commas'&lt;br /&gt;  PRINT 'Eg: EXEC sp_generate_inserts titles, @cols_to_include = "''title_id'',''title''"'&lt;br /&gt;  RETURN -1 --Failure. Reason: Invalid use of @cols_to_include property&lt;br /&gt; END&lt;br /&gt;&lt;br /&gt;IF ((@cols_to_exclude IS NOT NULL) AND (PATINDEX('''%''',@cols_to_exclude) = 0))&lt;br /&gt; BEGIN&lt;br /&gt;  RAISERROR('Invalid use of @cols_to_exclude property',16,1)&lt;br /&gt;  PRINT 'Specify column names surrounded by single quotes and separated by commas'&lt;br /&gt;  PRINT 'Eg: EXEC sp_generate_inserts titles, @cols_to_exclude = "''title_id'',''title''"'&lt;br /&gt;  RETURN -1 --Failure. Reason: Invalid use of @cols_to_exclude property&lt;br /&gt; END&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;--Checking to see if the database name is specified along wih the table name&lt;br /&gt;--Your database context should be local to the table for which you want to generate INSERT statements&lt;br /&gt;--specifying the database name is not allowed&lt;br /&gt;IF (PARSENAME(@table_name,3)) IS NOT NULL&lt;br /&gt; BEGIN&lt;br /&gt;  RAISERROR('Do not specify the database name. Be in the required database and just specify the table name.',16,1)&lt;br /&gt;  RETURN -1 --Failure. Reason: Database name is specified along with the table name, which is not allowed&lt;br /&gt; END&lt;br /&gt;&lt;br /&gt;--Checking for the existence of 'user table' or 'view'&lt;br /&gt;--This procedure is not written to work on system tables&lt;br /&gt;--To script the data in system tables, just create a view on the system tables and script the view instead&lt;br /&gt;&lt;br /&gt;IF @owner IS NULL&lt;br /&gt; BEGIN&lt;br /&gt;  IF ((OBJECT_ID(@table_name,'U') IS NULL) AND (OBJECT_ID(@table_name,'V') IS NULL)) &lt;br /&gt;   BEGIN&lt;br /&gt;    RAISERROR('User table or view not found.',16,1)&lt;br /&gt;    PRINT 'You may see this error, if you are not the owner of this table or view. In that case use @owner parameter to specify the owner name.'&lt;br /&gt;    PRINT 'Make sure you have SELECT permission on that table or view.'&lt;br /&gt;    RETURN -1 --Failure. Reason: There is no user table or view with this name&lt;br /&gt;   END&lt;br /&gt; END&lt;br /&gt;ELSE&lt;br /&gt; BEGIN&lt;br /&gt;  IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = @table_name AND (TABLE_TYPE = 'BASE TABLE' OR TABLE_TYPE = 'VIEW') AND TABLE_SCHEMA = @owner)&lt;br /&gt;   BEGIN&lt;br /&gt;    RAISERROR('User table or view not found.',16,1)&lt;br /&gt;    PRINT 'You may see this error, if you are not the owner of this table. In that case use @owner parameter to specify the owner name.'&lt;br /&gt;    PRINT 'Make sure you have SELECT permission on that table or view.'&lt;br /&gt;    RETURN -1 --Failure. Reason: There is no user table or view with this name  &lt;br /&gt;   END&lt;br /&gt; END&lt;br /&gt;&lt;br /&gt;--Variable declarations&lt;br /&gt;DECLARE  @Column_ID int,   &lt;br /&gt;  @Column_List varchar(8000), &lt;br /&gt;  @Column_Name varchar(128), &lt;br /&gt;  @Start_Insert varchar(786), &lt;br /&gt;  @Data_Type varchar(128), &lt;br /&gt;  @Actual_Values varchar(8000), --This is the string that will be finally executed to generate INSERT statements&lt;br /&gt;  @IDN varchar(128)  --Will contain the IDENTITY column's name in the table&lt;br /&gt;&lt;br /&gt;--Variable Initialization&lt;br /&gt;SET @IDN = ''&lt;br /&gt;SET @Column_ID = 0&lt;br /&gt;SET @Column_Name = ''&lt;br /&gt;SET @Column_List = ''&lt;br /&gt;SET @Actual_Values = ''&lt;br /&gt;&lt;br /&gt;IF @owner IS NULL &lt;br /&gt; BEGIN&lt;br /&gt;  SET @Start_Insert = 'INSERT INTO ' + '[' + RTRIM(COALESCE(@target_table,@table_name)) + ']' &lt;br /&gt; END&lt;br /&gt;ELSE&lt;br /&gt; BEGIN&lt;br /&gt;  SET @Start_Insert = 'INSERT ' + '[' + LTRIM(RTRIM(@owner)) + '].' + '[' + RTRIM(COALESCE(@target_table,@table_name)) + ']'   &lt;br /&gt; END&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;--To get the first column's ID&lt;br /&gt;&lt;br /&gt;SELECT @Column_ID = MIN(ORDINAL_POSITION)  &lt;br /&gt;FROM INFORMATION_SCHEMA.COLUMNS (NOLOCK) &lt;br /&gt;WHERE  TABLE_NAME = @table_name AND&lt;br /&gt;(@owner IS NULL OR TABLE_SCHEMA = @owner)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;--Loop through all the columns of the table, to get the column names and their data types&lt;br /&gt;WHILE @Column_ID IS NOT NULL&lt;br /&gt; BEGIN&lt;br /&gt;  SELECT  @Column_Name = QUOTENAME(COLUMN_NAME), &lt;br /&gt;  @Data_Type = DATA_TYPE &lt;br /&gt;  FROM  INFORMATION_SCHEMA.COLUMNS (NOLOCK) &lt;br /&gt;  WHERE  ORDINAL_POSITION = @Column_ID AND &lt;br /&gt;  TABLE_NAME = @table_name AND&lt;br /&gt;  (@owner IS NULL OR TABLE_SCHEMA = @owner)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  IF @cols_to_include IS NOT NULL --Selecting only user specified columns&lt;br /&gt;  BEGIN&lt;br /&gt;   IF CHARINDEX( '''' + SUBSTRING(@Column_Name,2,LEN(@Column_Name)-2) + '''',@cols_to_include) = 0 &lt;br /&gt;   BEGIN&lt;br /&gt;    GOTO SKIP_LOOP&lt;br /&gt;   END&lt;br /&gt;  END&lt;br /&gt;&lt;br /&gt;  IF @cols_to_exclude IS NOT NULL --Selecting only user specified columns&lt;br /&gt;  BEGIN&lt;br /&gt;   IF CHARINDEX( '''' + SUBSTRING(@Column_Name,2,LEN(@Column_Name)-2) + '''',@cols_to_exclude) &lt;&gt; 0 &lt;br /&gt;   BEGIN&lt;br /&gt;    GOTO SKIP_LOOP&lt;br /&gt;   END&lt;br /&gt;  END&lt;br /&gt;&lt;br /&gt;  --Making sure to output SET IDENTITY_INSERT ON/OFF in case the table has an IDENTITY column&lt;br /&gt;  IF (SELECT COLUMNPROPERTY( OBJECT_ID(QUOTENAME(COALESCE(@owner,USER_NAME())) + '.' + @table_name),SUBSTRING(@Column_Name,2,LEN(@Column_Name) - 2),'IsIdentity')) = 1 &lt;br /&gt;  BEGIN&lt;br /&gt;   IF @ommit_identity = 0 --Determing whether to include or exclude the IDENTITY column&lt;br /&gt;    SET @IDN = @Column_Name&lt;br /&gt;   ELSE&lt;br /&gt;    GOTO SKIP_LOOP   &lt;br /&gt;  END&lt;br /&gt;  &lt;br /&gt;  --Making sure whether to output computed columns or not&lt;br /&gt;  IF @ommit_computed_cols = 1&lt;br /&gt;  BEGIN&lt;br /&gt;   IF (SELECT COLUMNPROPERTY( OBJECT_ID(QUOTENAME(COALESCE(@owner,USER_NAME())) + '.' + @table_name),SUBSTRING(@Column_Name,2,LEN(@Column_Name) - 2),'IsComputed')) = 1 &lt;br /&gt;   BEGIN&lt;br /&gt;    GOTO SKIP_LOOP     &lt;br /&gt;   END&lt;br /&gt;  END&lt;br /&gt;  &lt;br /&gt;  --Tables with columns of IMAGE data type are not supported for obvious reasons&lt;br /&gt;  IF(@Data_Type in ('image'))&lt;br /&gt;   BEGIN&lt;br /&gt;    IF (@ommit_images = 0)&lt;br /&gt;     BEGIN&lt;br /&gt;      RAISERROR('Tables with image columns are not supported.',16,1)&lt;br /&gt;      PRINT 'Use @ommit_images = 1 parameter to generate INSERTs for the rest of the columns.'&lt;br /&gt;      PRINT 'DO NOT ommit Column List in the INSERT statements. If you ommit column list using @include_column_list=0, the generated INSERTs will fail.'&lt;br /&gt;      RETURN -1 --Failure. Reason: There is a column with image data type&lt;br /&gt;     END&lt;br /&gt;    ELSE&lt;br /&gt;     BEGIN&lt;br /&gt;     GOTO SKIP_LOOP&lt;br /&gt;     END&lt;br /&gt;   END&lt;br /&gt;&lt;br /&gt;  --Determining the data type of the column and depending on the data type, the VALUES part of&lt;br /&gt;  --the INSERT statement is generated. Care is taken to handle columns with NULL values. Also&lt;br /&gt;  --making sure, not to lose any data from flot, real, money, smallmomey, datetime columns&lt;br /&gt;  SET @Actual_Values = @Actual_Values  +&lt;br /&gt;  CASE &lt;br /&gt;   WHEN @Data_Type IN ('char','varchar','nchar','nvarchar') &lt;br /&gt;    THEN &lt;br /&gt;     'COALESCE('''''''' + REPLACE(RTRIM(' + @Column_Name + '),'''''''','''''''''''')+'''''''',''NULL'')'&lt;br /&gt;   WHEN @Data_Type IN ('datetime','smalldatetime') &lt;br /&gt;    THEN &lt;br /&gt;     'COALESCE('''''''' + RTRIM(CONVERT(char,' + @Column_Name + ',109))+'''''''',''NULL'')'&lt;br /&gt;   WHEN @Data_Type IN ('uniqueidentifier') &lt;br /&gt;    THEN  &lt;br /&gt;     'COALESCE('''''''' + REPLACE(CONVERT(char(255),RTRIM(' + @Column_Name + ')),'''''''','''''''''''')+'''''''',''NULL'')'&lt;br /&gt;   WHEN @Data_Type IN ('text','ntext') &lt;br /&gt;    THEN  &lt;br /&gt;     'COALESCE('''''''' + REPLACE(CONVERT(char(8000),' + @Column_Name + '),'''''''','''''''''''')+'''''''',''NULL'')'     &lt;br /&gt;   WHEN @Data_Type IN ('binary','varbinary') &lt;br /&gt;    THEN  &lt;br /&gt;     'COALESCE(RTRIM(CONVERT(char,' + 'CONVERT(int,' + @Column_Name + '))),''NULL'')'  &lt;br /&gt;   WHEN @Data_Type IN ('timestamp','rowversion') &lt;br /&gt;    THEN  &lt;br /&gt;     CASE &lt;br /&gt;      WHEN @include_timestamp = 0 &lt;br /&gt;       THEN &lt;br /&gt;        '''DEFAULT''' &lt;br /&gt;       ELSE &lt;br /&gt;        'COALESCE(RTRIM(CONVERT(char,' + 'CONVERT(int,' + @Column_Name + '))),''NULL'')'  &lt;br /&gt;     END&lt;br /&gt;   WHEN @Data_Type IN ('float','real','money','smallmoney')&lt;br /&gt;    THEN&lt;br /&gt;     'COALESCE(LTRIM(RTRIM(' + 'CONVERT(char, ' +  @Column_Name  + ',2)' + ')),''NULL'')' &lt;br /&gt;   ELSE &lt;br /&gt;    'COALESCE(LTRIM(RTRIM(' + 'CONVERT(char, ' +  @Column_Name  + ')' + ')),''NULL'')' &lt;br /&gt;  END   + '+' +  ''',''' + ' + '&lt;br /&gt;  &lt;br /&gt;  --Generating the column list for the INSERT statement&lt;br /&gt;  SET @Column_List = @Column_List +  @Column_Name + ',' &lt;br /&gt;&lt;br /&gt;  SKIP_LOOP: --The label used in GOTO&lt;br /&gt;&lt;br /&gt;  SELECT  @Column_ID = MIN(ORDINAL_POSITION) &lt;br /&gt;  FROM  INFORMATION_SCHEMA.COLUMNS (NOLOCK) &lt;br /&gt;  WHERE  TABLE_NAME = @table_name AND &lt;br /&gt;  ORDINAL_POSITION &gt; @Column_ID AND&lt;br /&gt;  (@owner IS NULL OR TABLE_SCHEMA = @owner)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; --Loop ends here!&lt;br /&gt; END&lt;br /&gt;&lt;br /&gt;--To get rid of the extra characters that got concatenated during the last run through the loop&lt;br /&gt;SET @Column_List = LEFT(@Column_List,len(@Column_List) - 1)&lt;br /&gt;SET @Actual_Values = LEFT(@Actual_Values,len(@Actual_Values) - 6)&lt;br /&gt;&lt;br /&gt;IF LTRIM(@Column_List) = '' &lt;br /&gt; BEGIN&lt;br /&gt;  RAISERROR('No columns to select. There should at least be one column to generate the output',16,1)&lt;br /&gt;  RETURN -1 --Failure. Reason: Looks like all the columns are ommitted using the @cols_to_exclude parameter&lt;br /&gt; END&lt;br /&gt;&lt;br /&gt;--Forming the final string that will be executed, to output the INSERT statements&lt;br /&gt;IF (@include_column_list &lt;&gt; 0)&lt;br /&gt; BEGIN&lt;br /&gt;  SET @Actual_Values = &lt;br /&gt;   'SELECT ' +  &lt;br /&gt;   CASE WHEN @top IS NULL OR @top &lt; 0 THEN '' ELSE ' TOP ' + LTRIM(STR(@top)) + ' ' END +    '''' + RTRIM(@Start_Insert) +    ' ''+' + '''(' + RTRIM(@Column_List) +  '''+' + ''')''' +    ' +''VALUES(''+ ' +  @Actual_Values  + '+'')''' + ' ' +    COALESCE(@from,' FROM ' + CASE WHEN @owner IS NULL THEN '' ELSE '[' + LTRIM(RTRIM(@owner)) + '].' END + '[' + rtrim(@table_name) + ']' + '(NOLOCK)') ENDELSE IF (@include_column_list = 0) BEGIN  SET @Actual_Values =    'SELECT ' +    CASE WHEN @top IS NULL OR @top &lt; 0 THEN '' ELSE ' TOP ' + LTRIM(STR(@top)) + ' ' END +    '''' + RTRIM(@Start_Insert) +    ' '' +''VALUES(''+ ' +  @Actual_Values + '+'')''' + ' ' +    COALESCE(@from,' FROM ' + CASE WHEN @owner IS NULL THEN '' ELSE '[' + LTRIM(RTRIM(@owner)) + '].' END + '[' + rtrim(@table_name) + ']' + '(NOLOCK)') END --Determining whether to ouput any debug informationIF @debug_mode =1 BEGIN  PRINT '/*****START OF DEBUG INFORMATION*****'  PRINT 'Beginning of the INSERT statement:'  PRINT @Start_Insert  PRINT ''  PRINT 'The column list:'  PRINT @Column_List  PRINT ''  PRINT 'The SELECT statement executed to generate the INSERTs'  PRINT @Actual_Values  PRINT ''  PRINT '*****END OF DEBUG INFORMATION*****/'  PRINT '' END  PRINT '--INSERTs generated by ''sp_generate_inserts'' stored procedure written by Vyas'PRINT '--Build number: 22'PRINT '--Problems/Suggestions? Contact Vyas @ vyaskn@hotmail.com'PRINT '--http://vyaskn.tripod.com'PRINT ''PRINT 'SET NOCOUNT ON'PRINT ''--Determining whether to print IDENTITY_INSERT or notIF (@IDN &lt;&gt; '')&lt;br /&gt; BEGIN&lt;br /&gt;  PRINT 'SET IDENTITY_INSERT ' + QUOTENAME(COALESCE(@owner,USER_NAME())) + '.' + QUOTENAME(@table_name) + ' ON'&lt;br /&gt;  PRINT 'GO'&lt;br /&gt;  PRINT ''&lt;br /&gt; END&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;IF @disable_constraints = 1 AND (OBJECT_ID(QUOTENAME(COALESCE(@owner,USER_NAME())) + '.' + @table_name, 'U') IS NOT NULL)&lt;br /&gt; BEGIN&lt;br /&gt;  IF @owner IS NULL&lt;br /&gt;   BEGIN&lt;br /&gt;    SELECT  'ALTER TABLE ' + QUOTENAME(COALESCE(@target_table, @table_name)) + ' NOCHECK CONSTRAINT ALL' AS '--Code to disable constraints temporarily'&lt;br /&gt;   END&lt;br /&gt;  ELSE&lt;br /&gt;   BEGIN&lt;br /&gt;    SELECT  'ALTER TABLE ' + QUOTENAME(@owner) + '.' + QUOTENAME(COALESCE(@target_table, @table_name)) + ' NOCHECK CONSTRAINT ALL' AS '--Code to disable constraints temporarily'&lt;br /&gt;   END&lt;br /&gt;&lt;br /&gt;  PRINT 'GO'&lt;br /&gt; END&lt;br /&gt;&lt;br /&gt;PRINT ''&lt;br /&gt;PRINT 'PRINT ''Inserting values into ' + '[' + RTRIM(COALESCE(@target_table,@table_name)) + ']' + ''''&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;--All the hard work pays off here!!! You'll get your INSERT statements, when the next line executes!&lt;br /&gt;EXEC (@Actual_Values)&lt;br /&gt;&lt;br /&gt;PRINT 'PRINT ''Done'''&lt;br /&gt;PRINT ''&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;IF @disable_constraints = 1 AND (OBJECT_ID(QUOTENAME(COALESCE(@owner,USER_NAME())) + '.' + @table_name, 'U') IS NOT NULL)&lt;br /&gt; BEGIN&lt;br /&gt;  IF @owner IS NULL&lt;br /&gt;   BEGIN&lt;br /&gt;    SELECT  'ALTER TABLE ' + QUOTENAME(COALESCE(@target_table, @table_name)) + ' CHECK CONSTRAINT ALL'  AS '--Code to enable the previously disabled constraints'&lt;br /&gt;   END&lt;br /&gt;  ELSE&lt;br /&gt;   BEGIN&lt;br /&gt;    SELECT  'ALTER TABLE ' + QUOTENAME(@owner) + '.' + QUOTENAME(COALESCE(@target_table, @table_name)) + ' CHECK CONSTRAINT ALL' AS '--Code to enable the previously disabled constraints'&lt;br /&gt;   END&lt;br /&gt;&lt;br /&gt;  PRINT 'GO'&lt;br /&gt; END&lt;br /&gt;&lt;br /&gt;PRINT ''&lt;br /&gt;IF (@IDN &lt;&gt; '')&lt;br /&gt; BEGIN&lt;br /&gt;  PRINT 'SET IDENTITY_INSERT ' + QUOTENAME(COALESCE(@owner,USER_NAME())) + '.' + QUOTENAME(@table_name) + ' OFF'&lt;br /&gt;  PRINT 'GO'&lt;br /&gt; END&lt;br /&gt;&lt;br /&gt;PRINT 'SET NOCOUNT OFF'&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SET NOCOUNT OFF&lt;br /&gt;RETURN 0 --Success. We are done!&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;PRINT 'Created the procedure'&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;--Mark procedure as system object&lt;br /&gt;EXEC sys.sp_MS_marksystemobject sp_generate_inserts&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;PRINT 'Granting EXECUTE permission on sp_generate_inserts to all users'&lt;br /&gt;GRANT EXEC ON sp_generate_inserts TO public&lt;br /&gt;&lt;br /&gt;SET NOCOUNT OFF&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;PRINT 'Done'&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;Usage:&lt;br /&gt;&lt;br /&gt;Example 1: To generate INSERT statements for table 'titles':&lt;br /&gt;EXEC sp_generate_inserts 'titles' &lt;br /&gt;Example 2: To ommit the column list in the INSERT statement: (Column list is included by default)&lt;br /&gt;NOTE: If you have too many columns, you are advised to ommit column list, as shown below, to avoid erroneous results&lt;br /&gt;EXEC sp_generate_inserts 'titles', @Include_Column_List = 0 &lt;br /&gt;Example 3: To generate INSERT statements for 'titlesCopy' table from 'titles' table:&lt;br /&gt;EXEC sp_generate_inserts 'titles', 'titlesCopy' &lt;br /&gt;Example 4: To generate INSERT statements for 'titles' table for only those titles which contain the word 'Computer' in them:&lt;br /&gt;EXEC sp_generate_inserts 'titles', @From = "from titles where title like '%Computer%'" &lt;br /&gt;Example 5: To specify that you want to include TIMESTAMP column's data as well in the INSERT statement:&lt;br /&gt;NOTE: By default TIMESTAMP column's data is not scripted&lt;br /&gt;EXEC sp_generate_inserts 'titles', @Include_Timestamp = 1 &lt;br /&gt;Example 6:  To print the debug information:&lt;br /&gt;EXEC sp_generate_inserts 'titles', @debug_mode = 1 &lt;br /&gt;Example 7: If you are not the owner of the table, use @owner parameter to specify the owner name:&lt;br /&gt;NOTE: To use this option, you must have SELECT permissions on that table&lt;br /&gt;EXEC sp_generate_inserts Nickstable, @owner = 'Nick' &lt;br /&gt;Example 8: To generate INSERT statements for the rest of the columns excluding images:&lt;br /&gt;NOTE: When using this otion, DO NOT set @include_column_list parameter to 0&lt;br /&gt;EXEC sp_generate_inserts imgtable, @ommit_images = 1 &lt;br /&gt;Example 9: To generate INSERT statements for the rest of the columns excluding IDENTITY column:&lt;br /&gt;EXEC sp_generate_inserts mytable, @ommit_identity = 1 &lt;br /&gt;Example 10: To generate INSERT statements for the top 10 rows in the table:&lt;br /&gt;EXEC sp_generate_inserts mytable, @top = 10 &lt;br /&gt;Example 11: To generate INSERT statements only with the columns you want:&lt;br /&gt;EXEC sp_generate_inserts titles, @cols_to_include = "'title','title_id','au_id'" &lt;br /&gt;Example 12: To generate INSERT statements by ommitting some columns:&lt;br /&gt;EXEC sp_generate_inserts titles, @cols_to_exclude = "'title','title_id','au_id'" &lt;br /&gt;Example 13: To avoid checking the foreign key constraints while loading data with INSERT statements:&lt;br /&gt;NOTE: The @disable_constraints option will disable foreign key constraints, by assuming that the source data is valid and referentially sound&lt;br /&gt;EXEC sp_generate_inserts titles, @disable_constraints = 1 &lt;br /&gt;Example 14: To avoid scripting data from computed columns:&lt;br /&gt;EXEC sp_generate_inserts MyTable, @ommit_computed_cols = 1 &lt;br /&gt;&lt;br /&gt;*/&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-2697333782080778634?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/2697333782080778634/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=2697333782080778634' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/2697333782080778634'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/2697333782080778634'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/08/t-sql-procedure-to-script-your-data-to.html' title='[T-SQL] Procedure to script your data (to generate INSERT statements from the existing data)'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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-342028597261074516.post-2112712244845279794</id><published>2010-08-18T00:51:00.001-07:00</published><updated>2010-08-18T00:51:43.167-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='function'/><category scheme='http://www.blogger.com/atom/ns#' term='split'/><title type='text'>[T-SQL] Script for Split Function</title><content type='html'>CREATE FUNCTION dbo.Split(@String varchar(8000), @Delimiter char(1))     &lt;br /&gt;returns @temptable TABLE (items varchar(8000))     &lt;br /&gt;as     &lt;br /&gt;begin     &lt;br /&gt; declare @idx int     &lt;br /&gt; declare @slice varchar(8000)     &lt;br /&gt;    &lt;br /&gt; select @idx = 1     &lt;br /&gt;  if len(@String)&lt;1 or @String is null  return          while @idx!= 0      begin       set @idx = charindex(@Delimiter,@String)       if @idx!=0        set @slice = left(@String,@idx - 1)       else        set @slice = @String         if(len(@slice)&gt;0)&lt;br /&gt;   insert into @temptable(Items) values(@slice)     &lt;br /&gt;&lt;br /&gt;  set @String = right(@String,len(@String) - @idx)     &lt;br /&gt;  if len(@String) = 0 break     &lt;br /&gt; end &lt;br /&gt;return     &lt;br /&gt;end&lt;br /&gt;--how to use&lt;br /&gt;select top 10 * from dbo.split('Karachi , Lahore , Isb',',')&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/342028597261074516-2112712244845279794?l=muhammadabbas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://muhammadabbas.blogspot.com/feeds/2112712244845279794/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=342028597261074516&amp;postID=2112712244845279794' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/2112712244845279794'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/342028597261074516/posts/default/2112712244845279794'/><link rel='alternate' type='text/html' href='http://muhammadabbas.blogspot.com/2010/08/t-sql-script-for-split-function.html' title='[T-SQL] Script for Split Function'/><author><name>Muhammad Abbas</name><uri>http://www.blogger.com/profile/11595777617813527247</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>
