<?xml version="1.0" encoding="UTF-8" standalone="no"?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0"><channel><title>Official MS SQL</title><description></description><managingEditor>noreply@blogger.com (Unknown)</managingEditor><pubDate>Thu, 29 Aug 2024 23:06:08 -0700</pubDate><generator>Blogger http://www.blogger.com</generator><openSearch:totalResults xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">9</openSearch:totalResults><openSearch:startIndex xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">1</openSearch:startIndex><openSearch:itemsPerPage xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">25</openSearch:itemsPerPage><link>http://officialsql.blogspot.com/</link><language>en-us</language><itunes:explicit>no</itunes:explicit><itunes:subtitle/><itunes:owner><itunes:email>noreply@blogger.com</itunes:email></itunes:owner><item><title>select range of data rows  in MSSQL2005</title><link>http://officialsql.blogspot.com/2009/08/select-range-of-data-rows-in-mssql2005.html</link><category>rangeof data</category><category>rowid</category><category>select row</category><author>noreply@blogger.com (Unknown)</author><pubDate>Sat, 22 Aug 2009 12:10:00 -0700</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-8439742687240311021.post-6925370215538454949</guid><description>&lt;span&gt;&lt;span class="keyword"&gt;We  all know if we have to find range of data  then we use sub queries  but  sql2005  provide  row_number  to find  range of  data&lt;br /&gt;&lt;br /&gt;for ex.&lt;br /&gt;if we have to select  data from 21 row to 30 the n&lt;br /&gt;&lt;br /&gt;SELECT&lt;/span&gt;&lt;span&gt; * &lt;/span&gt;&lt;span class="keyword"&gt;FROM&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt; (  &lt;/span&gt;&lt;br /&gt;&lt;span&gt; &lt;span class="keyword"&gt;SELECT&lt;/span&gt;&lt;span&gt; Row_Number() OVER (&lt;/span&gt;&lt;span class="keyword"&gt;ORDER&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class="keyword"&gt;BY&lt;/span&gt;&lt;span&gt; last_name, first_name) &lt;/span&gt;&lt;span class="keyword"&gt;as&lt;/span&gt;&lt;span&gt; rowid,  &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;   user_id,   &lt;/span&gt;&lt;br /&gt;&lt;span&gt;   last_name,   &lt;/span&gt;&lt;br /&gt;&lt;span&gt;   first_name  &lt;/span&gt;&lt;br /&gt;&lt;span&gt; &lt;span class="keyword"&gt;FROM&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class="func"&gt;user&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt; ) &lt;span class="keyword"&gt;as&lt;/span&gt;&lt;span&gt; a  &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span class="keyword"&gt;where&lt;/span&gt;&lt;span&gt; rowid &gt;20 and rowid &lt;31&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;same if i want 28 record  the n&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="keyword"&gt;SELECT&lt;/span&gt;&lt;span&gt; * &lt;/span&gt;&lt;span class="keyword"&gt;FROM&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt; (  &lt;/span&gt;&lt;br /&gt;&lt;span&gt; &lt;span class="keyword"&gt;SELECT&lt;/span&gt;&lt;span&gt; Row_Number() OVER (&lt;/span&gt;&lt;span class="keyword"&gt;ORDER&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class="keyword"&gt;BY&lt;/span&gt;&lt;span&gt; last_name, first_name) &lt;/span&gt;&lt;span class="keyword"&gt;as&lt;/span&gt;&lt;span&gt; rowid,  &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;   user_id,   &lt;/span&gt;&lt;br /&gt;&lt;span&gt;   last_name,   &lt;/span&gt;&lt;br /&gt;&lt;span&gt;   first_name  &lt;/span&gt;&lt;br /&gt;&lt;span&gt; &lt;span class="keyword"&gt;FROM&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class="func"&gt;user&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt; ) &lt;span class="keyword"&gt;as&lt;/span&gt;&lt;span&gt; a  &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;span class="keyword"&gt;where&lt;/span&gt;&lt;span&gt; rowid = 28&lt;/span&gt;&lt;/span&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>@@rowcount with MSSQL</title><link>http://officialsql.blogspot.com/2009/08/rowcount-with-mssql.html</link><category>rowcount</category><author>noreply@blogger.com (Unknown)</author><pubDate>Sat, 22 Aug 2009 11:55:00 -0700</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-8439742687240311021.post-3751709145313976499</guid><description>@@ROWCOUNT returns the number of rows affected or read depending on the operation.&lt;br /&gt;&lt;br /&gt;terms as follows&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt; @@ROWCOUNT returns the number of rows returned to the user for a SELECT.&lt;/li&gt;&lt;li&gt;@@ROWCOUNT returns the number of rows affected after issuing a INSERT, DELETE, or UPDATE. &lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;e.g&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="kw1"&gt;SELECT&lt;/span&gt; &lt;span class="kw1"&gt;emp_firstname,emp_lastname &lt;/span&gt;from emp_details ;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;out put is&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="kw1"&gt;emp_firstname           &lt;/span&gt;&lt;span class="kw1"&gt;emp_lastname&lt;br /&gt;&lt;br /&gt;yogesh                          k&lt;br /&gt;&lt;br /&gt;Jhon                             Bush&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;out put  returns  two rows&lt;br /&gt;&lt;br /&gt;if we execute  following after this  the n&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="kw1"&gt;SELECT&lt;/span&gt; &lt;span class="kw2"&gt;@@ROWCOUNT&lt;/span&gt; &lt;span class="kw1"&gt;AS&lt;/span&gt; &lt;span class="st0"&gt;'Rows previously affected'&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;then out put will be&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="escaped"&gt;Rows previously affected&lt;br /&gt;------------------------&lt;br /&gt;2&lt;br /&gt;&lt;br /&gt;(1 row(s) affected&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;But if  we execute query like&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="kw1"&gt;SELECT&lt;/span&gt; &lt;span class="kw1"&gt;Count(*)  &lt;/span&gt;as rowcount from emp_details&lt;br /&gt;then&lt;br /&gt;&lt;br /&gt;out put is&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="escaped"&gt;rowcount&lt;br /&gt;-----------&lt;br /&gt;2&lt;br /&gt;&lt;br /&gt;(1 row(s) affected)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;and  we  execute  following after this&lt;br /&gt;&lt;span class="kw1"&gt;SELECT&lt;/span&gt; &lt;span class="kw2"&gt;@@ROWCOUNT&lt;/span&gt; &lt;span class="kw1"&gt;AS&lt;/span&gt; &lt;span class="st0"&gt;'Rows previously affected'&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;then&lt;br /&gt;&lt;br /&gt;out put is&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="escaped"&gt;Rows previously affected&lt;br /&gt;------------------------&lt;br /&gt;1&lt;br /&gt;&lt;br /&gt;(1 row(s) affected)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Notice it tells you that it sent back &lt;strong&gt;only 1 row&lt;/strong&gt; to the user.because only one row is return to user&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>dealy in sql  or wait in sql  query</title><link>http://officialsql.blogspot.com/2008/06/dealy-in-sql-or-wait-in-sql-query.html</link><category>dealy in sql</category><author>noreply@blogger.com (Unknown)</author><pubDate>Mon, 30 Jun 2008 04:10:00 -0700</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-8439742687240311021.post-8280527945109321787</guid><description>&lt;span style="font-size:180%;"&gt;I&lt;/span&gt;&lt;span style="font-size:85%;"&gt;n&lt;/span&gt; many application or process we required &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_0"&gt;dealy&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;there is &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_1"&gt;dealy&lt;/span&gt; in &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_2"&gt;sql&lt;/span&gt; server&lt;br /&gt;call &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_3"&gt;WAITFOR&lt;/span&gt;&lt;br /&gt;&lt;div bgcolor="#ccccc1" width="100%"&gt;&lt;br /&gt;select '1'&lt;br /&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_4"&gt;WAITFOR&lt;/span&gt; DELAY '00:00:30'&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;above query run and wait 30 sec for output&lt;br /&gt;&lt;br /&gt;select '2'&lt;br /&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_5"&gt;WAITFOR&lt;/span&gt; Time '15:00'&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;above query run and wait for 3:00pm for output&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_6"&gt;WAITFOR&lt;/span&gt; gives out put after end of process if you want out put after each wait then use code as follows&lt;br /&gt;&lt;br /&gt;select &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_7"&gt;getdate&lt;/span&gt;()&lt;br /&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_8"&gt;WAITFOR&lt;/span&gt; DELAY '00:00:30'&lt;br /&gt;Go&lt;br /&gt;select &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_9"&gt;getdate&lt;/span&gt;()&lt;br /&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_10"&gt;WAITFOR&lt;/span&gt; DELAY '00:00:30'&lt;br /&gt;Go&lt;br /&gt;select &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_11"&gt;getdate&lt;/span&gt;()&lt;br /&gt;Go&lt;br /&gt;&lt;br /&gt;alternate logic for delay is  while loop but its not &lt;span class="blsp-spelling-corrected" id="SPELLING_ERROR_12"&gt;accurate&lt;/span&gt;&lt;br /&gt;&lt;span class="blsp-spelling-corrected"&gt;it gives differnt interval on different configuration server.&lt;/span&gt;&lt;br /&gt;&lt;span class="blsp-spelling-corrected"&gt;&lt;/span&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>text  file as data source</title><link>http://officialsql.blogspot.com/2008/06/text-file-as-data-source.html</link><author>noreply@blogger.com (Unknown)</author><pubDate>Sat, 28 Jun 2008 00:56:00 -0700</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-8439742687240311021.post-8655686990300639853</guid><description>&lt;span style="font-size:180%;"&gt;I&lt;/span&gt;n many application we need Text file as datasource or as table&lt;br /&gt;&lt;br /&gt;many ways to do this one of that as follows&lt;br /&gt;&lt;br /&gt;create one folder on c drive name &lt;em&gt;textfiles&lt;br /&gt;&lt;/em&gt;and execute following code&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;EXEC sp_addlinkedserver txtdatasrc, 'Jet 4.0',&lt;br /&gt;'Microsoft.Jet.OLEDB.4.0', 'c:\textfiles', NULL, 'Text'&lt;br /&gt;&lt;br /&gt;now your link server with name " txtdatasrc" is created&lt;br /&gt;&lt;br /&gt;execute following code&lt;br /&gt;&lt;br /&gt;EXEC sp_tables_ex txtdatasrc&lt;br /&gt;&lt;br /&gt;see there is no record because folder does not contain any text file .&lt;br /&gt;&lt;br /&gt;add new text file name table1 to folder&lt;br /&gt;&lt;br /&gt;and again run command&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;EXEC sp_tables_ex txtdatasrc&lt;br /&gt;&lt;br /&gt;see there is table name "table1#txt" in out put&lt;br /&gt;&lt;br /&gt;now you can select rows from table1#txt by using select statment as follows&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;select * from txtsrv...table1#txt&lt;br /&gt;&lt;br /&gt;this link server is  very useful to access text as datasource&lt;br /&gt;&lt;br /&gt;there are many othere methods and tricks in this stuff we will discuss soon...</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>Nesting Stored Procedures</title><link>http://officialsql.blogspot.com/2008/06/nesting-stored-procedures.html</link><category>Nesting Stored Procedures limit in sql</category><author>noreply@blogger.com (Unknown)</author><pubDate>Mon, 16 Jun 2008 04:23:00 -0700</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-8439742687240311021.post-1689600700691162348</guid><description>&lt;span style="font-size:180%;"&gt;N&lt;/span&gt;esting Stored Procedures&lt;br /&gt;&lt;br /&gt;Stored procedures are nested when one stored procedure calls another or executes managed code by referencing a CLR routine, type, or aggregate. You can nest stored procedures and managed code references up to 32 levels. The nesting level increases by one when the called stored procedure or managed code reference begins execution and decreases by one when the called stored procedure or managed code reference completes execution. Attempting to exceed the maximum of 32 levels of nesting causes the whole calling chain to fail. The current nesting level for the stored procedures in execution is stored in the @@NESTLEVEL function.&lt;br /&gt;&lt;br /&gt;When a stored procedure executes managed code by referencing a CLR routine, type, or aggregate, this reference also counts as one level of nesting. Methods invoked from within managed code do not count against this limit. The current nesting level is returned by the @@NESTLEVEL function. When a CLR stored procedure performs data access operations through the Microsoft SQL Server managed provider, an additional nesting level is added in the transition from managed code to SQL and this level is reflected in the @@NESTLEVEL function.&lt;br /&gt;&lt;br /&gt;An error in a nested stored procedure is not necessarily fatal to the calling stored procedure. When invoking stored procedures within stored procedures, use the Transact-SQL RETURN statement to return a return code and check the return code from the calling stored procedure. In this way, you can specify the behavior of your stored procedures when errors occur. For more information about using return codes, see Returning Data Using a Return Code.&lt;br /&gt;&lt;br /&gt;Stored procedures can even do a nested call to themselves, a technique known as recursion.&lt;br /&gt;&lt;br /&gt;Although the nesting limit is 32 levels, Microsoft SQL Server 2005 has no limit on the number of stored procedures that can be invoked from a given stored procedure, provided that the subordinate stored procedures do not invoke other subordinate stored procedures and the maximum nesting level is never exceeded.</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>How To get last updated  Row  from table ?</title><link>http://officialsql.blogspot.com/2008/06/how-to-get-last-updated-row-from-table.html</link><category>last modify Row ID</category><category>last updated  Row</category><author>noreply@blogger.com (Unknown)</author><pubDate>Mon, 16 Jun 2008 02:51:00 -0700</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-8439742687240311021.post-32535747221098467</guid><description>&lt;span style="font-weight: bold;"&gt;timestamp (Transact-SQL)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Is a data type that exposes automatically generated, unique binary numbers within a database. timestamp is generally used as a mechanism for version-stamping table rows. The storage size is 8 bytes. The timestamp data type is just an incrementing number and does not preserve a date or a time. To record a date or time, use a datetime data type.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Each database has a counter that is incremented for each insert or update operation that is performed on a table that contains a timestamp column within the database. This counter is the database timestamp. This tracks a relative time within a database, not an actual time that can be associated with a clock. A table can have only one timestamp column. Every time that a row with a timestamp column is modified or inserted, the incremented database timestamp value is inserted in the timestamp column. This property makes a timestamp column a poor candidate for keys, especially primary keys. Any update made to the row changes the timestamp value and, therefore, changes the key value. If the column is in a primary key, the old key value is no longer valid, and foreign keys referencing the old value are no longer valid. If the table is referenced in a dynamic cursor, all updates change the position of the rows in the cursor. If the column is in an index key, all updates to the data row also generate updates of the index.&lt;br /&gt;&lt;br /&gt;You can use the timestamp column of a row to easily determine whether any value in the row has changed since the last time it was read. If any change is made to the row, the timestamp value is updated. If no change is made to the row, the timestamp value is the same as when it was previously read. To return the current timestamp value for a database, use @@DBTS.&lt;br /&gt;&lt;br /&gt;The Transact-SQL timestamp data type is different from the timestamp data type defined in the SQL-2003 standard. The SQL-2003 timestamp data type is equivalent to the Transact-SQL datetime data type.&lt;br /&gt;&lt;br /&gt;rowversion is the synonym for the timestamp data type and is subject to the behavior of data type synonyms. In DDL statements, use rowversion instead of timestamp wherever possible. For more information, see Data Type Synonyms (Transact-SQL).&lt;br /&gt;&lt;br /&gt;In a CREATE TABLE or ALTER TABLE statement, you do not have to specify a column name for the timestamp data type, for example:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;CREATE TABLE ExampleTable (PriKey int PRIMARY KEY, timestamp);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;insert into  ExampleTable(PriKey) values(1)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;insert into  ExampleTable(PriKey) values(2)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;insert into  ExampleTable(PriKey) values(3)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;insert into  ExampleTable(PriKey) values(4)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;Select MAX(timestamp) from ExampleTable&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;update ExampleTable set PriKey =110 where PriKey =3&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;Select MAX(timestamp) from ExampleTable&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you do not specify a column name, the Microsoft SQL Server 2005 Database Engine generates the timestamp column name; however, the rowversion synonym does not follow this behavior. When you use rowversion, you must specify a column name.&lt;br /&gt;&lt;br /&gt;Duplicate timestamp values can be generated by using the SELECT INTO statement in which a timestamp column is in the SELECT list. We do not recommend using timestamp in this manner.&lt;br /&gt;&lt;br /&gt;A nonnullable timestamp column is semantically equivalent to a binary(8) column. A nullable timestamp column is semantically equivalent to a varbinary(8) column.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;rowversion (Transact-SQL)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Is a data type that exposes automatically generated, unique binary numbers within a database. rowversion is generally used as a mechanism for version-stamping table rows. The storage size is 8 bytes. The rowversion data type is just an incrementing number and does not preserve a date or a time. To record a date or time, use a datetime2 data type.&lt;br /&gt;&lt;br /&gt;Each database has a counter that is incremented for each insert or update operation that is performed on a table that contains a rowversion column within the database. This counter is the database rowversion. This tracks a relative time within a database, not an actual time that can be associated with a clock. A table can have only one rowversion column. Every time that a row with a rowversion column is modified or inserted, the incremented database rowversion value is inserted in the rowversion column. This property makes a rowversion column a poor candidate for keys, especially primary keys. Any update made to the row changes the rowversion value and, therefore, changes the key value. If the column is in a primary key, the old key value is no longer valid, and foreign keys referencing the old value are no longer valid. If the table is referenced in a dynamic cursor, all updates change the position of the rows in the cursor. If the column is in an index key, all updates to the data row also generate updates of the index.&lt;br /&gt;&lt;br /&gt;timestamp is the synonym for the rowversion data type and is subject to the behavior of data type synonyms. In DDL statements, use rowversion instead of timestamp wherever possible. For more information, see Data Type Synonyms (Transact-SQL).&lt;br /&gt;&lt;br /&gt;The Transact-SQL timestamp data type is different from the timestamp data type defined in the ISO standard.&lt;br /&gt;&lt;br /&gt;In a CREATE TABLE or ALTER TABLE statement, you do not have to specify a column name for the timestamp data type, for example:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;CREATE TABLE ExampleTable (PriKey int PRIMARY KEY, timestamp);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If you do not specify a column name, the SQL Server Database Engine generates the timestamp column name; however, the rowversion synonym does not follow this behavior. When you use rowversion, you must specify a column name, for example:&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;CREATE TABLE ExampleTable2 (PriKey int PRIMARY KEY, VerCol rowversion) ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;A nonnullable rowversion column is semantically equivalent to a binary(8) column. A nullable rowversion column is semantically equivalent to a varbinary(8) column.&lt;br /&gt;&lt;br /&gt;You can use the rowversion column of a row to easily determine whether any value in the row has changed since the last time it was read. If any change is made to the row, the rowversion value is updated. If no change is made to the row, the rowversion value is the same as when it was previously read. To return the current rowversion value for a database, use @@DBTS.&lt;br /&gt;&lt;br /&gt;You can add a rowversion column to a table to help maintain the integrity of the database when multiple users are updating rows at the same time. You may also want to know how many rows and which rows were updated without re-querying the table.</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>how to get new inserted row id in sql</title><link>http://officialsql.blogspot.com/2008/06/how-to-get-new-inserted-row-id-in-sql.html</link><category>last updated  value  from table sql</category><author>noreply@blogger.com (Unknown)</author><pubDate>Mon, 16 Jun 2008 00:58:00 -0700</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-8439742687240311021.post-3176716669319308456</guid><description>&lt;span style="font-weight: bold;"&gt;SCOPE_IDENTITY&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Returns the last IDENTITY value inserted into an IDENTITY column in the same scope. A scope is a module -- a stored procedure, trigger, function, or batch. Thus, two statements are in the same scope if they are in the same stored procedure, function, or batch.&lt;br /&gt;Syntax&lt;br /&gt;&lt;br /&gt;SCOPE_IDENTITY( )&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Return Types&lt;br /&gt;&lt;br /&gt;sql_variant&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;@@IDENTITY&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Returns the last-inserted identity value.&lt;br /&gt;Syntax&lt;br /&gt;&lt;br /&gt;@@IDENTITY&lt;br /&gt;&lt;br /&gt;Return Types&lt;br /&gt;&lt;br /&gt;numeric&lt;br /&gt;&lt;br /&gt;After an INSERT, SELECT INTO, or bulk copy statement completes, @@IDENTITY contains the last identity value generated by the statement. If the statement did not affect any tables with identity columns, @@IDENTITY returns NULL. If multiple rows are inserted, generating multiple identity values, @@IDENTITY returns the last identity value generated. If the statement fires one or more triggers that perform inserts that generate identity values, calling @@IDENTITY immediately after the statement returns the last identity value generated by the triggers. If a trigger is fired after an insert action on a table that has an identity column, and the trigger inserts into another table that does not have an identity column, @@IDENTITY will return the identity value of the first insert. The @@IDENTITY value does not revert to a previous setting if the INSERT or SELECT INTO statement or bulk copy fails, or if the transaction is rolled back.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;USE tempdb&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;CREATE TABLE TZ (&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;   Z_id  int IDENTITY(1,1)PRIMARY KEY,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;   Z_name varchar(20) NOT NULL)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;INSERT TZ&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;   VALUES ('Lisa')&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;INSERT TZ&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;   VALUES ('Mike')&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;INSERT TZ&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;   VALUES ('Carla')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;SELECT * FROM TZ&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;--Result set: This is how table TZ looks&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;Z_id   Z_name&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;-------------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;1      Lisa&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;2      Mike&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;3      Carla&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;CREATE TABLE TY (&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;   Y_id  int IDENTITY(100,5)PRIMARY KEY,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;   Y_name varchar(20) NULL)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;INSERT TY (Y_name)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;   VALUES ('boathouse')&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;INSERT TY (Y_name)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;   VALUES ('rocks')&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;INSERT TY (Y_name)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;   VALUES ('elevator')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;SELECT * FROM TY&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;--Result set: This is how TY looks:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;Y_id  Y_name&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;---------------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;100   boathouse&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;105   rocks&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;110   elevator&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;/*Create the trigger that inserts a row in table TY&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;when a row is inserted in table TZ*/&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;CREATE TRIGGER Ztrig&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;ON TZ&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;FOR INSERT AS&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;   BEGIN&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;   INSERT TY VALUES ('')&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;   END&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;/*FIRE the trigger and find out what identity values you get&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;with the @@IDENTITY and SCOPE_IDENTITY functions*/&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;INSERT TZ VALUES ('Rosalie')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;SELECT SCOPE_IDENTITY() AS [SCOPE_IDENTITY]&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;SELECT   @@IDENTITY AS [@@IDENTITY]&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;--Here is the result set.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;SCOPE_IDENTITY&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;4&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;/*SCOPE_IDENTITY returned the last identity value in the same scope, which was the insert on table TZ*/&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;@@IDENTITY&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;115&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;/*@@IDENTITY returned the last identity value inserted to TY by the trigger, which fired due to an earlier insert on TZ*/&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;IDENT_CURRENT&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Returns the last identity value generated for a specified table in any session and any scope.&lt;br /&gt;Syntax&lt;br /&gt;&lt;br /&gt;IDENT_CURRENT('table_name')&lt;br /&gt;Arguments&lt;br /&gt;&lt;br /&gt;table_name&lt;br /&gt;&lt;br /&gt;Is the name of the table whose identity value will be returned. table_name is varchar, with no default.&lt;br /&gt;Return Types&lt;br /&gt;&lt;br /&gt;sql_variant&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;IDENT_CURRENT is similar to the Microsoft® SQL Server™ 2000 identity functions SCOPE_IDENTITY and @@IDENTITY. All three functions return last-generated identity values. However, the scope and session on which 'last' is defined in each of these functions differ.&lt;br /&gt;&lt;br /&gt;   * IDENT_CURRENT returns the last identity value generated for a specific table in any session and any scope.&lt;br /&gt;&lt;br /&gt;   * @@IDENTITY returns the last identity value generated for any table in the current session, across all scopes.&lt;br /&gt;&lt;br /&gt;   * SCOPE_IDENTITY returns the last identity value generated for any table in the current session and the current scope.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This example illustrates the different identity values returned by IDENT_CURRENT, @@IDENTITY, and SCOPE_IDENTITY.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;USE pubs&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;DROP TABLE t6&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;DROP TABLE t7&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;CREATE TABLE t6(id int IDENTITY)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;CREATE TABLE t7(id int IDENTITY(100,1))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;CREATE TRIGGER t6ins ON t6 FOR INSERT&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;AS&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;BEGIN&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;   INSERT t7 DEFAULT VALUES&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;END&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;--end of trigger definition&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;SELECT   * FROM t6&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;--id is empty.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;SELECT   * FROM t7&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;--id is empty.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;--Do the following in Session 1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;INSERT t6 DEFAULT VALUES&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;SELECT @@IDENTITY     &lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;/*Returns the value 100, which was inserted by the trigger.*/&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;SELECT SCOPE_IDENTITY()  &lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;/* Returns the value 1, which was inserted by the&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;INSERT stmt 2 statements before this query.*/&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;SELECT IDENT_CURRENT('t7')&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;/* Returns value inserted into t7, i.e. in the trigger.*/&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;SELECT IDENT_CURRENT('t6')&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;/* Returns value inserted into t6, which was the INSERT statement 4 stmts before this query.*/&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;-- Do the following in Session 2&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;SELECT @@IDENTITY&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;/* Returns NULL since there has been no INSERT action&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;so far in this session.*/&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;SELECT SCOPE_IDENTITY()&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;/* Returns NULL since there has been no INSERT action&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;so far in this scope in this session.*/&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;SELECT IDENT_CURRENT('t7')&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;/* Returns the last value inserted into t7.*/&lt;/span&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>Varchar(Max)  limit  of  max in Sql2005 ?</title><link>http://officialsql.blogspot.com/2008/06/varcharmax-limit-of-max-in-sql2005.html</link><category>configure varchar max</category><category>varchar max sql2005</category><category>varchar(max) size</category><author>noreply@blogger.com (Unknown)</author><pubDate>Tue, 3 Jun 2008 22:25:00 -0700</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-8439742687240311021.post-2679347594961567896</guid><description>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTnqQiyouRgRZxW_tLZaDKNq7i5xI4MhhWImXPDpwJJEMgir-V88jgEwkKbRHjRmzlnTfyw7WXKadFrs-gLD4ThppxXFZK4b1hZavCI-IwPKtDZ48Lai0duzRqccxMlK-UJTz1mjHTMJCT/s1600-h/1.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5207902182127695218" style="FLOAT: left; MARGIN: 0pt 10px 10px 0pt; CURSOR: pointer" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTnqQiyouRgRZxW_tLZaDKNq7i5xI4MhhWImXPDpwJJEMgir-V88jgEwkKbRHjRmzlnTfyw7WXKadFrs-gLD4ThppxXFZK4b1hZavCI-IwPKtDZ48Lai0duzRqccxMlK-UJTz1mjHTMJCT/s320/1.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;W&lt;/span&gt;hile developing one store proc i face problem of varchar(max)&lt;br /&gt;&lt;br /&gt;my string was genreated more than 100000 charactes and by default varchar(max) size is 65,536&lt;br /&gt;&lt;br /&gt;actual size of any max type is 2^30-1&lt;br /&gt;if you place max text size is 1 then it set to max available size</description><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTnqQiyouRgRZxW_tLZaDKNq7i5xI4MhhWImXPDpwJJEMgir-V88jgEwkKbRHjRmzlnTfyw7WXKadFrs-gLD4ThppxXFZK4b1hZavCI-IwPKtDZ48Lai0duzRqccxMlK-UJTz1mjHTMJCT/s72-c/1.JPG" width="72"/><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>ms sql optimization tips</title><link>http://officialsql.blogspot.com/2008/06/ms-sql-optimization-tips.html</link><category>ms sql optimization tips</category><category>Performace Improvement</category><author>noreply@blogger.com (Unknown)</author><pubDate>Sun, 1 Jun 2008 21:45:00 -0700</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-8439742687240311021.post-4318547337296996608</guid><description>&lt;span style="font-size:180%;"&gt;S&lt;/span&gt;ome Tips For optimization&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;Include the SET NOCOUNT ON statement into your stored procedures to stop the message indicating the number of rows affected by a Transact-SQL statement.&lt;br /&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;This can reduce network traffic, because your client will not receive the message indicating the number of rows affected by a Transact-SQL statement.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;Call stored procedure using its fully qualified name.&lt;/b&gt;&lt;br /&gt;The complete name of an object consists of four identifiers: the server name, database name, owner name, and object name. An object name that specifies all four parts is known as a fully qualified name. Using fully qualified names eliminates any confusion about which stored procedure you want to run and can boost performance because SQL Server has a better chance to reuse the stored procedures execution plans if they were executed using fully qualified names.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;Consider returning the integer value as an RETURN statement instead of an integer value as part of a recordset.&lt;/b&gt;&lt;br /&gt;The RETURN statement exits unconditionally from a stored procedure, so the statements following RETURN are not executed. Though the RETURN statement is generally used for error checking, you can use this statement to return an integer value for any other reason. Using RETURN statement can boost performance because SQL Server will not create a recordset.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;Don't use the prefix "sp_" in the stored procedure name if you need to create a stored procedure to run in a database other than the master database.&lt;/b&gt;&lt;br /&gt;The prefix "sp_" is used in the system stored procedures names. Microsoft does not recommend to use the prefix "sp_" in the user-created stored procedure name, because SQL Server always looks for a stored procedure beginning with "sp_" in the following order: the master database, the stored procedure based on the fully qualified name provided, the stored procedure using dbo as the owner, if one is not specified. So, when you have the stored procedure with the prefix "sp_" in the database other than master, the master database is always checked first, and if the user-created stored procedure has the same name as a system stored procedure, the user-created stored procedure will never be executed.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;Use the sp_executesql stored procedure instead of the EXECUTE statement.&lt;/b&gt;&lt;br /&gt;The sp_executesql stored procedure supports parameters. So, using the sp_executesql stored procedure instead of the EXECUTE statement improve readability of your code when there are many parameters are used. When you use the sp_executesql stored procedure to executes a Transact-SQL statements that will be reused many times, the SQL Server query optimizer will reuse the execution plan it generates for the first execution when the change in parameter values to the statement is the only variation.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;Use SQL Server Profiler to determine which stored procedures has been recompiled too often.&lt;/b&gt;&lt;br /&gt;To check the stored procedure has been recompiled, run SQL Server Profiler and choose to trace the event in the "Stored Procedures" category called "SP:Recompile". You can also trace the event "SP:StmtStarting" to see at what point in the procedure it is being recompiled. When you identify these stored procedures, you can take some correction actions to reduce or eliminate the excessive recompilations.&lt;/span&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item></channel></rss>