<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;CU8HQ3o9eyp7ImA9WxNVEkU.&quot;"><id>tag:blogger.com,1999:blog-8325677720139466792</id><updated>2009-10-23T03:43:52.463-04:00</updated><title>TechFruits</title><subtitle type="html">Sybase ASE SQL Tips Tricks Performance and UNIX ksh How to, Office Humor</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://www.techfruits.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://www.techfruits.com/" /><link rel="hub" href="http://pubsubhubbub.appspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>Samir Badhe</name><uri>http://www.blogger.com/profile/03722292367204759886</uri><email>noreply@blogger.com</email></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>37</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-nc/2.0/" /><link rel="self" href="http://feeds.feedburner.com/Techfruits" type="application/atom+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><entry gd:etag="W/&quot;CE4FQ345fCp7ImA9WxJTGEU.&quot;"><id>tag:blogger.com,1999:blog-8325677720139466792.post-5031746083376080952</id><published>2009-04-27T13:14:00.006-04:00</published><updated>2009-04-27T21:41:52.024-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-04-27T21:41:52.024-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Tricks" /><title>SQL to find first and last day of a month</title><content type="html">How to get the first and last day of any month.&lt;br /&gt;&lt;br /&gt;To get the first and last day of any month when given a date we can use the date functions&lt;br /&gt;as below.&lt;br /&gt;&lt;br /&gt;Suppose we want the first and last day for the date '04/28/2009', that is for April 2009.&lt;br /&gt;&lt;br /&gt;declare @given_date datetime&lt;br /&gt;select @given_date = '04/28/2009'&lt;br /&gt;&lt;br /&gt;-- SQL to get the first day of the month&lt;br /&gt;&lt;span style="COLOR: rgb(0,0,153)"&gt;select dateadd(dd,-(day(dateadd(mm,1,@given_date))-1),dateadd(mm,&lt;strong style="FONT-WEIGHT: bold"&gt;0&lt;/strong&gt;,@given_date&lt;/span&gt;&lt;span style="COLOR: rgb(51,51,255)"&gt;&lt;span style="COLOR: rgb(0,0,153)"&gt;))&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;strong&gt;&lt;span style="COLOR: rgb(0,153,0)"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;-- SQL to get the last day of the month&lt;br /&gt;&lt;span style="COLOR: rgb(0,0,153)"&gt;select dateadd(dd, -day(dateadd(mm,1,@given_date)), dateadd(mm,&lt;strong style="FONT-WEIGHT: bold"&gt;1&lt;/strong&gt;,@given_date))&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To get next or previous month's first or last day change the highlighted number accordingly.&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;br /&gt;--SQL to get the first day of the second next month&lt;br /&gt;&lt;span style="COLOR: rgb(0,0,153)"&gt;select dateadd(dd,-(day(dateadd(mm,1,@given_date))-1),dateadd(mm,&lt;span style="FONT-WEIGHT: bold"&gt;2&lt;/span&gt;&lt;strong style="FONT-WEIGHT: bold"&gt;&lt;/strong&gt;,@given_date&lt;/span&gt;&lt;span style="COLOR: rgb(51,51,255)"&gt;&lt;span style="COLOR: rgb(0,0,153)"&gt;))&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;-- SQL to get the last day of the second next month&lt;br /&gt;&lt;span style="COLOR: rgb(0,0,153)"&gt;select dateadd(dd, -day(dateadd(mm,1,@given_date)), dateadd(mm,&lt;strong style="FONT-WEIGHT: bold"&gt;3&lt;/strong&gt;,@given_date))&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8325677720139466792-5031746083376080952?l=www.techfruits.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.techfruits.com/feeds/5031746083376080952/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=8325677720139466792&amp;postID=5031746083376080952" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/5031746083376080952?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/5031746083376080952?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Techfruits/~3/2W9acTWcnzc/find-first-and-last-day-of-month.html" title="SQL to find first and last day of a month" /><author><name>Samir Badhe</name><uri>http://www.blogger.com/profile/03722292367204759886</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="06566258307108868142" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://www.techfruits.com/2009/04/find-first-and-last-day-of-month.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkcHQXw_eSp7ImA9WxJTEkk.&quot;"><id>tag:blogger.com,1999:blog-8325677720139466792.post-1790253643510875952</id><published>2009-04-20T11:42:00.003-04:00</published><updated>2009-04-20T12:13:50.241-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-04-20T12:13:50.241-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Tips" /><title>How to get underlying table information of a proxy table ?</title><content type="html">How to check proxy table information ?&lt;br /&gt;&lt;br /&gt;To know underlying server, database and table information of a proxy table we can&lt;br /&gt;query sysattributes table from within local database.&lt;br /&gt;&lt;br /&gt;The query can be as below.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;select object_type, object_cinfo, char_value from sysattributes where object_type = 'OD'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;OD stands for 'Object Definition' , no clue as of now why 'OD' though :( , will get it some where&lt;br /&gt;down the line... no rush :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8325677720139466792-1790253643510875952?l=www.techfruits.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.techfruits.com/feeds/1790253643510875952/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=8325677720139466792&amp;postID=1790253643510875952" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/1790253643510875952?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/1790253643510875952?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Techfruits/~3/NDQlGfAwtJc/how-to-get-underlying-table-information.html" title="How to get underlying table information of a proxy table ?" /><author><name>Samir Badhe</name><uri>http://www.blogger.com/profile/03722292367204759886</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="06566258307108868142" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.techfruits.com/2009/04/how-to-get-underlying-table-information.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkIBRX4_eCp7ImA9WxJTEUw.&quot;"><id>tag:blogger.com,1999:blog-8325677720139466792.post-2310580948088784196</id><published>2009-04-18T14:04:00.003-04:00</published><updated>2009-04-19T01:22:34.040-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-04-19T01:22:34.040-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Performance" /><title>How does a view works ?</title><content type="html">How does a sybase view works internally?&lt;br /&gt;How does a view perform as against a direct SQL?&lt;br /&gt;&lt;br /&gt;While trying to understand the performance aspect of a view, this is what i came across in &lt;a href="http://infocenter.sybase.com/help/index.jsp"&gt;Sybase infocenter&lt;/a&gt; documentation.&lt;br /&gt;&lt;br /&gt;A view can be derived from one or more underlying tables. Only the definition of the view is stored int e database (syscomments table), and not the view data.&lt;br /&gt;&lt;br /&gt;When we use a view in a SQL statement, ASE combines the statement with this stored definition&lt;br /&gt;to translate the statement to query underlying tables. This process is called as view resolution.&lt;br /&gt;&lt;br /&gt;Consider the following view definition&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;create view hiprice &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;as select * &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;from titles &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;where price &gt; $15 &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;and advance &gt; $5000&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now, if we use this view like below,&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;select title, type &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;from hiprice &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;where type = "popular_comp" &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;br /&gt;Internally, ASE combines the query with "hiprice" view's definition, converting the query to:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;select title, type &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;from titles &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;where price &gt; $15 &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;and advance &gt; $5000 &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;and type = "popular_comp" &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Note that it is not only "resolving" the 'where' clause but also the selected column list.&lt;br /&gt;&lt;br /&gt;This shows that performance wise it should work as good as any other SQL statement, and should not have any considerable extra overhead.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8325677720139466792-2310580948088784196?l=www.techfruits.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.techfruits.com/feeds/2310580948088784196/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=8325677720139466792&amp;postID=2310580948088784196" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/2310580948088784196?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/2310580948088784196?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Techfruits/~3/hXac4iKkwa8/how-does-view-works.html" title="How does a view works ?" /><author><name>Samir Badhe</name><uri>http://www.blogger.com/profile/03722292367204759886</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="06566258307108868142" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.techfruits.com/2009/04/how-does-view-works.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEQCQ3gzcSp7ImA9WxVVE0s.&quot;"><id>tag:blogger.com,1999:blog-8325677720139466792.post-1929957950368392860</id><published>2009-03-06T12:40:00.006-05:00</published><updated>2009-03-06T12:59:22.689-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-03-06T12:59:22.689-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Tips" /><title>How to estimate table size</title><content type="html">Once you create a table, you can estimate the table size using command sp_estspace.&lt;br /&gt;&lt;br /&gt;To estimate the amount of space required by a table and its indexes:&lt;br /&gt;1. Create the table.&lt;br /&gt;2. Create all indexes on the table.&lt;br /&gt;3. Run sp_estspace, giving the table name, the estimated number of rows for the table, and the optional arguments, as needed. &lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;br /&gt;You do not need to insert data into the tables. sp_estspace uses information in the system tables--not the size of the data in the tables--to calculate the size of tables and indexes.&lt;br /&gt;&lt;br /&gt;Example : &lt;br /&gt;sp_estspace TableA, 50000&lt;br /&gt;&lt;br /&gt;where TableA is table name and 50000 is estimated rows in the table.&lt;br /&gt;&lt;br /&gt;Further details can be found in &lt;a href="http://manuals.sybase.com/onlinebooks/group-as/asg1250e/refman/@Generic__BookTextView/100804;pt=90486"&gt;Sybase Manuals&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8325677720139466792-1929957950368392860?l=www.techfruits.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.techfruits.com/feeds/1929957950368392860/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=8325677720139466792&amp;postID=1929957950368392860" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/1929957950368392860?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/1929957950368392860?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Techfruits/~3/gmmQHxHHOpc/how-to-estimate-table-size.html" title="How to estimate table size" /><author><name>Samir Badhe</name><uri>http://www.blogger.com/profile/03722292367204759886</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="06566258307108868142" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.techfruits.com/2009/03/how-to-estimate-table-size.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEACR3gyeSp7ImA9WxdWEE8.&quot;"><id>tag:blogger.com,1999:blog-8325677720139466792.post-8905259739432348408</id><published>2008-07-01T23:54:00.005-04:00</published><updated>2008-07-02T15:26:06.691-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-07-02T15:26:06.691-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="UNIX ksh tips" /><title>How to copy whole directory tree</title><content type="html">To copy a whole directory structure you can use &lt;span style="font-style: italic;"&gt;-r&lt;/span&gt; option of &lt;span style="font-style: italic;"&gt;cp&lt;/span&gt;&lt;br /&gt;&lt;span id="intelliTxt"&gt;It copies all the files in a directory and its subdirectories.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;#-- Copy every thing from /homeDir/yourDir  to /homeDir/tempDir/&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;cp -r /homeDir/yourDir/*    /homeDir/tempDir/&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;br /&gt;Note:&lt;br /&gt;You can use other supported wild cards ( instead of * ) to be more "selective" while copying.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;#-- Copy every file/directory, which starts from 'S', from /homeDir/yourDir  to &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;#-- /homeDir/tempDir/&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;cp -r /homeDir/yourDir/[S]*    /homeDir/tempDir/&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8325677720139466792-8905259739432348408?l=www.techfruits.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.techfruits.com/feeds/8905259739432348408/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=8325677720139466792&amp;postID=8905259739432348408" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/8905259739432348408?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/8905259739432348408?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Techfruits/~3/66m1iet10T4/how-to-copy-whole-directory-trees.html" title="How to copy whole directory tree" /><author><name>Samir Badhe</name><uri>http://www.blogger.com/profile/03722292367204759886</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="06566258307108868142" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.techfruits.com/2008/07/how-to-copy-whole-directory-trees.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUMARX4ycCp7ImA9WxdXE08.&quot;"><id>tag:blogger.com,1999:blog-8325677720139466792.post-4457175049558266127</id><published>2008-06-24T01:27:00.006-04:00</published><updated>2008-06-24T13:10:44.098-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-06-24T13:10:44.098-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Tips" /><title>rollback SQL changes on database</title><content type="html">&lt;span style="font-style: italic;"&gt;How to rollback SQL changes done on a database?&lt;/span&gt;&lt;br /&gt;Well... it's a tip to be used in all your future SQL adventures with sensitive database.&lt;br /&gt;&lt;br /&gt;Sometimes, you run a query which does some thing undesired and you want to 'rollback' your changes. But Sybase does allow to 'rollback' only when there is a transaction.&lt;br /&gt;The tip is very simple, but very much neglected  by developers.&lt;br /&gt;&lt;br /&gt;Whenever you execute delete/update/insert SQLs, use transaction.&lt;br /&gt;This gives you a chance to control the changes done to database.&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;e.g.&lt;br /&gt;&lt;br /&gt;Suppose you want to delete data from yourTable where col_1 = 100&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;--#Execute a wrong SQL.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;delete from yourTable where col_1 = 10 &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You can not rollback this, as there is no transaction.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;--#Now, try this... &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;begin tran &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;delete from yourTable where col_1 = 10 &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now, if you check the table, all the data where col_1 = 10, is deleted.&lt;br /&gt;But, this will not be a permanent change, unless you execute 'commit tran'&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;--#Do a rollback&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;rollback tran&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The changes will be 'rollback'.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;--#Now run the correct query&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;delete from yourTable where col_1 = 100&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now, if you check the table, all the data where col_1 = 100, is deleted,&lt;br /&gt;this is what we want.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;--#At this time you can execute ...&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;commit tran&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This will make the changes permanent.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8325677720139466792-4457175049558266127?l=www.techfruits.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.techfruits.com/feeds/4457175049558266127/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=8325677720139466792&amp;postID=4457175049558266127" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/4457175049558266127?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/4457175049558266127?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Techfruits/~3/TCryCt4pZPs/rollback-sql-changes-on-database.html" title="rollback SQL changes on database" /><author><name>Samir Badhe</name><uri>http://www.blogger.com/profile/03722292367204759886</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="06566258307108868142" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.techfruits.com/2008/06/rollback-sql-changes-on-database.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUcCRXg_fSp7ImA9WxdQF0s.&quot;"><id>tag:blogger.com,1999:blog-8325677720139466792.post-6387077164397876109</id><published>2008-06-18T01:07:00.005-04:00</published><updated>2008-06-18T01:31:04.645-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-06-18T01:31:04.645-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Tricks" /><title>How to get list of 'identity' columns in a database</title><content type="html">&lt;span style="font-style: italic;"&gt;How to list identity columns available in a database, along with table names. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;There are many ways to list identity columns .. but the simplest one I ever came up with is&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;--# Respective table name is also included.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;select object_name(id) tableName, name columnName from syscolumns where status = 128&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;Related Posts :&lt;br /&gt;&lt;a href="http://www.techfruits.com/2008/06/list-of-tables-having-identity-column.html"&gt;1. Another way to get List of tables having 'identity' column&lt;br /&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8325677720139466792-6387077164397876109?l=www.techfruits.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.techfruits.com/feeds/6387077164397876109/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=8325677720139466792&amp;postID=6387077164397876109" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/6387077164397876109?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/6387077164397876109?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Techfruits/~3/bQ1lPA2d8k0/get-list-of-identity-columns-in.html" title="How to get list of 'identity' columns in a database" /><author><name>Samir Badhe</name><uri>http://www.blogger.com/profile/03722292367204759886</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="06566258307108868142" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.techfruits.com/2008/06/get-list-of-identity-columns-in.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0cARXo6fSp7ImA9WxdRGUU.&quot;"><id>tag:blogger.com,1999:blog-8325677720139466792.post-6849119494664415774</id><published>2008-06-09T00:56:00.005-04:00</published><updated>2008-06-09T01:24:04.415-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-06-09T01:24:04.415-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Tricks" /><title>How to get physical size of a row ?</title><content type="html">&lt;span style="font-style: italic;"&gt;What is the physical row size of my table ?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If you observe, the output of the &lt;span style="font-style: italic;"&gt;sp_help myTable&lt;/span&gt;,  the third column ( Length )  indicates the physical length for each of the columns. That means, to get the physical length of a row, we need the sum of these values.&lt;br /&gt;&lt;br /&gt;We can query syscolumns table, to get the physical size of a row, as below.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;--#Get the physical row size for a table 'myTable'&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;select sum(length) from syscolumns where id = object_id('myTable')&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8325677720139466792-6849119494664415774?l=www.techfruits.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.techfruits.com/feeds/6849119494664415774/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=8325677720139466792&amp;postID=6849119494664415774" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/6849119494664415774?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/6849119494664415774?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Techfruits/~3/75PlW7IwZCs/how-to-get-physical-size-of-row.html" title="How to get physical size of a row ?" /><author><name>Samir Badhe</name><uri>http://www.blogger.com/profile/03722292367204759886</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="06566258307108868142" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.techfruits.com/2008/06/how-to-get-physical-size-of-row.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0UCSH86eip7ImA9WxdRFko.&quot;"><id>tag:blogger.com,1999:blog-8325677720139466792.post-4432526484012391248</id><published>2008-06-04T23:40:00.003-04:00</published><updated>2008-06-05T11:21:09.112-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-06-05T11:21:09.112-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Tips" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Performance" /><title>what is 'update statistics'</title><content type="html">&lt;span style="FONT-STYLE: italic"&gt;How update statistics works to improve the query performance ?&lt;/span&gt;&lt;br /&gt;&lt;span style="FONT-STYLE: italic"&gt;When to use update statistics ?&lt;/span&gt;&lt;br /&gt;&lt;em&gt;Difference between update statistics and update index statistics.&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;Indexes are of great help in SQL performance. The keys involved in this index are spread all over the table's memory, database server keeps a "statistics" of these key's distribution. This statistics is then used by query optimizer while making the decision about, which index to be used in query or if at all index should be used.&lt;br /&gt;&lt;br /&gt;&lt;span style="FONT-STYLE: italic"&gt;update statistics&lt;/span&gt;, updates this "statistics data" and makes sure the database optimizer gets updated information.&lt;br /&gt;&lt;br /&gt;Use &lt;span style="FONT-STYLE: italic"&gt;update statistics&lt;/span&gt;, If there is significant change in the key values in your index, or if a great deal of data in an indexed column has been added, changed, or removed.&lt;br /&gt;&lt;br /&gt;You can update statistics for all the indexes in a table or specifically only for one index.&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;span style="COLOR: rgb(0,153,0)"&gt;--#update statistics for the &lt;/span&gt;&lt;span style="COLOR: rgb(0,153,0); FONT-STYLE: italic"&gt;leading columns of all indexes&lt;/span&gt;&lt;span style="COLOR: rgb(0,153,0)"&gt; on the table.&lt;/span&gt;&lt;br /&gt;&lt;span style="COLOR: rgb(0,0,153)"&gt;update statistics tableName&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="COLOR: rgb(0,153,0)"&gt;--#updates statistics for the &lt;/span&gt;&lt;span style="COLOR: rgb(0,153,0); FONT-STYLE: italic"&gt;leading column of an index&lt;/span&gt;&lt;span style="COLOR: rgb(0,153,0)"&gt;.&lt;/span&gt;&lt;br /&gt;&lt;span style="COLOR: rgb(0,0,153)"&gt;update statistics tableName indexName&lt;/span&gt;&lt;br /&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;Note that, in above examples only 'leading' columns of the index are considered while updating statistics. To update statistics for all of the index columns use following.&lt;br /&gt;&lt;br /&gt;&lt;span style="COLOR: rgb(0,153,0)"&gt;--#update statistics for &lt;/span&gt;&lt;span style="COLOR: rgb(0,153,0); FONT-STYLE: italic"&gt;all the &lt;/span&gt;&lt;span style="COLOR: rgb(0,153,0); FONT-STYLE: italic"&gt;columns of all indexes&lt;/span&gt;&lt;span style="COLOR: rgb(0,153,0)"&gt; on the table.&lt;/span&gt;&lt;br /&gt;&lt;span style="COLOR: rgb(0,0,153)"&gt;update index statistics tableName&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="COLOR: rgb(0,153,0)"&gt;--#updates statistics for &lt;/span&gt;&lt;span style="COLOR: rgb(0,153,0); FONT-STYLE: italic"&gt;all the &lt;/span&gt;&lt;span style="COLOR: rgb(0,153,0); FONT-STYLE: italic"&gt;columns of an index&lt;/span&gt;&lt;span style="COLOR: rgb(0,153,0)"&gt;.&lt;/span&gt;&lt;br /&gt;&lt;span style="COLOR: rgb(0,0,153)"&gt;update statistics tableName indexName&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="COLOR: rgb(0,0,0); FONT-STYLE: italic"&gt;update statistics note :&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;When you create a nonclustered index on a table that contains data, &lt;span style="FONT-STYLE: italic"&gt;update statistics&lt;/span&gt; is automatically run for &lt;span style="FONT-WEIGHT: bold"&gt;the new index&lt;/span&gt;.&lt;br /&gt;When you create a clustered index on a table that contains data, &lt;span style="FONT-STYLE: italic"&gt;update statistics&lt;/span&gt; is automatically run for &lt;span style="FONT-WEIGHT: bold"&gt;all indexes&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="COLOR: rgb(255,102,0)"&gt;Related Posts :&lt;/span&gt;&lt;br /&gt;&lt;a href="http://www.techfruits.com/2008/05/get-last-update-statistics-run-date.html"&gt;How to get last 'update statistics' run date&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="fullpost"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8325677720139466792-4432526484012391248?l=www.techfruits.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.techfruits.com/feeds/4432526484012391248/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=8325677720139466792&amp;postID=4432526484012391248" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/4432526484012391248?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/4432526484012391248?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Techfruits/~3/lM3RwyNDXZY/what-is-update-statistics.html" title="what is 'update statistics'" /><author><name>Samir Badhe</name><uri>http://www.blogger.com/profile/03722292367204759886</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="06566258307108868142" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.techfruits.com/2008/05/what-is-update-statistics.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUcFQHw9fip7ImA9WxdQF0s.&quot;"><id>tag:blogger.com,1999:blog-8325677720139466792.post-6439563001791372580</id><published>2008-06-03T23:31:00.008-04:00</published><updated>2008-06-18T01:30:11.266-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-06-18T01:30:11.266-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Tricks" /><title>List of tables having 'identity' column</title><content type="html">How to get the list of tables with &lt;span style="font-style: italic;"&gt;identity column?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;ASE 12.5.x, provides a function next_identity(), you can use this function to list the tables&lt;br /&gt;having identity column.&lt;br /&gt;Actually, this function returns, the next possible value for the &lt;span style="font-style: italic;"&gt;identity&lt;/span&gt; column in a table.&lt;br /&gt;&lt;br /&gt;So, to get the list of tables which contains a identity column, our logic is simple,&lt;br /&gt;check the next identity value for each of the tables in database, and if NULL, that means&lt;br /&gt;table does not contain any identity column, else it does.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;--#List the table names, which has identity column.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;select name from sysobjects where type = 'U' and next_identity(name) != NULL&lt;/span&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;--#List the table names, which has identity column, along with the next possible identity value.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;select name,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 153);"&gt; next_identity(name) &lt;/span&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;&lt;br /&gt;from sysobjects&lt;br /&gt;where type = 'U' and next_identity(name) != NULL&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;Related Posts :&lt;/span&gt;&lt;br /&gt;1. &lt;a href="http://www.techfruits.com/2008/06/get-list-of-identity-columns-in.html"&gt;How to get list of identity columns along with table names.&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8325677720139466792-6439563001791372580?l=www.techfruits.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.techfruits.com/feeds/6439563001791372580/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=8325677720139466792&amp;postID=6439563001791372580" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/6439563001791372580?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/6439563001791372580?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Techfruits/~3/EZ5wx2PvFX8/list-of-tables-having-identity-column.html" title="List of tables having 'identity' column" /><author><name>Samir Badhe</name><uri>http://www.blogger.com/profile/03722292367204759886</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="06566258307108868142" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.techfruits.com/2008/06/list-of-tables-having-identity-column.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0QARH8_eip7ImA9WxdRFUg.&quot;"><id>tag:blogger.com,1999:blog-8325677720139466792.post-2061719512237634679</id><published>2008-05-30T00:45:00.005-04:00</published><updated>2008-06-03T23:49:05.142-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-06-03T23:49:05.142-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Tricks" /><title>select n rows per group from a table</title><content type="html">Suppose, after doing &lt;span style="font-style: italic;"&gt;group by&lt;/span&gt;, you want to select a specific number of rows from each group.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;&lt;span style="font-weight: bold;"&gt;1.&lt;/span&gt; How to select one row per group from a table ?&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;There are many ways to achieve this. But the simplest I feel, is as below.&lt;br /&gt;Use min/max on one of the available columns and then implement &lt;span style="font-style: italic;"&gt;group by&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;--# &lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;Get first/lowest row from each group. &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;select col_1, min(col_2) from yourTable group by col_1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;"&gt;--# &lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;Get last/highest row from each group. &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;select col_1, max(col_2) from yourTable group by col_1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;&lt;span style="font-weight: bold;"&gt;2.&lt;/span&gt; How to select n rows per group, from a table ?&lt;/span&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;Make sure you have unique combination of &lt;span style="font-style: italic;"&gt;col_1, col_2 &lt;/span&gt;in you table. If not you can&lt;br /&gt;&lt;a href="http://www.techfruits.com/2008/05/sql-to-delete-duplicate-rows-records.html"&gt;delete duplicates from the table&lt;/a&gt;&lt;br /&gt;or you can move the data to a temp. table and execute below on the temp table.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;--#Get first n rows per group from a table &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;select distinct * from yourTable A where &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;( select count(*) from yourTable B where A.col_1 = B.col_1 and A.col_2 &gt; B.col_2 ) &lt; &lt;span style="color: rgb(204, 0, 0);"&gt;n&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;--#Get first 3 rows per group from a table &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;select distinct * from yourTable A where &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;( select count(*) from yourTable B where A.col_1 = B.col_1 and A.col_2 &gt; B.col_2 ) &lt;&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;--#Get last 3 rows per group from a table &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;select distinct * from yourTable A where &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;( select count(*) from yourTable B where A.col_1 = B.col_1 and A.col_2 &lt;&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Ref. Table :&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;create table yourTable ( col_1 varchar(10) , col_2 int )&lt;br /&gt;go&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;insert into yourTable values ( 'red', 1)&lt;br /&gt;insert into yourTable values ( 'red', 10)&lt;br /&gt;insert into yourTable values ( 'blue', 11)&lt;br /&gt;insert into yourTable values ( 'blue', 12)&lt;br /&gt;insert into yourTable values ( 'blue', 13)&lt;br /&gt;insert into yourTable values ( 'yellow', 100)&lt;br /&gt;insert into yourTable values ( 'yellow', 211)&lt;br /&gt;go&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="fullpost"&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8325677720139466792-2061719512237634679?l=www.techfruits.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.techfruits.com/feeds/2061719512237634679/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=8325677720139466792&amp;postID=2061719512237634679" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/2061719512237634679?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/2061719512237634679?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Techfruits/~3/Mzo56BS6pP4/select-n-rows-per-group-from-table.html" title="select n rows per group from a table" /><author><name>Samir Badhe</name><uri>http://www.blogger.com/profile/03722292367204759886</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="06566258307108868142" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.techfruits.com/2008/05/select-n-rows-per-group-from-table.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A04ERHo_cSp7ImA9WxdREE4.&quot;"><id>tag:blogger.com,1999:blog-8325677720139466792.post-4849312620382011457</id><published>2008-05-29T01:28:00.000-04:00</published><updated>2008-05-29T01:45:05.449-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-05-29T01:45:05.449-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Tricks" /><title>How to select random rows from a table</title><content type="html">&lt;span style="font-style: italic;"&gt;How to get a random row or multiple random rows from a table ?&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;--#SQL to get a single random row from a table.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;select top 1 column1, column2, column3  from tableName order by newid()&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To get multiple random rows from a table, you need to just change the 'top' count.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;--#SQL to get 10 random rows from a table.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt; select top 10 column1, column2, column3  from tableName order by newid()&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8325677720139466792-4849312620382011457?l=www.techfruits.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.techfruits.com/feeds/4849312620382011457/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=8325677720139466792&amp;postID=4849312620382011457" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/4849312620382011457?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/4849312620382011457?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Techfruits/~3/v_KA42HSWiM/how-to-select-random-rows-from-table.html" title="How to select random rows from a table" /><author><name>Samir Badhe</name><uri>http://www.blogger.com/profile/03722292367204759886</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="06566258307108868142" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.techfruits.com/2008/05/how-to-select-random-rows-from-table.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0YBRnszeip7ImA9WxdRFkk.&quot;"><id>tag:blogger.com,1999:blog-8325677720139466792.post-9037986915440406957</id><published>2008-05-28T01:12:00.003-04:00</published><updated>2008-06-05T00:45:57.582-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-06-05T00:45:57.582-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Tips" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Performance" /><title>How to get last 'update statistics' run date</title><content type="html">&lt;span style="font-style: italic;"&gt;What was last time, when 'update statistics' ran on a table ?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Whenever a query or SP does not perform as before, among all other investigation steps, checking &lt;span style="font-style: italic;"&gt;update statistics &lt;/span&gt;on the underlying tables, is one of the very first steps.&lt;br /&gt;&lt;br /&gt;You can use the following SQL to get the 'last run date', of &lt;span style="font-style: italic;"&gt;update statistics&lt;/span&gt; on a table.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;--#sysstatistics table contains the table statistics data. &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;select moddate from sysstatistics where id = object_id("your_table_name")&lt;/span&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;Note that, this may produce a list of dates. This is because, sysstatistics table maintains one or more entries for each of the index columns of the table. It may contain entries for non-indexed columns as well.&lt;br /&gt;&lt;br /&gt;Make sure, you run &lt;span style="font-style: italic;"&gt;update statistics&lt;/span&gt; on tables regularly, specially the tables whose volume changes considerably, over the time.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;Related Posts:&lt;/span&gt;&lt;a href="http://www.techfruits.com/2008/05/what-is-update-statistics.html"&gt;&lt;br /&gt;what is 'update statistics'&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8325677720139466792-9037986915440406957?l=www.techfruits.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.techfruits.com/feeds/9037986915440406957/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=8325677720139466792&amp;postID=9037986915440406957" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/9037986915440406957?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/9037986915440406957?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Techfruits/~3/Y54XDLLLGZ0/get-last-update-statistics-run-date.html" title="How to get last 'update statistics' run date" /><author><name>Samir Badhe</name><uri>http://www.blogger.com/profile/03722292367204759886</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="06566258307108868142" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.techfruits.com/2008/05/get-last-update-statistics-run-date.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A08NQXw7eSp7ImA9WxRbGEs.&quot;"><id>tag:blogger.com,1999:blog-8325677720139466792.post-4186720797032242532</id><published>2008-05-27T22:55:00.011-04:00</published><updated>2008-12-09T19:44:50.201-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-12-09T19:44:50.201-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Office Humor" /><title>Office Humor - 4</title><content type="html">&lt;span style="COLOR: rgb(255,102,0)"&gt;&lt;span style="COLOR: rgb(153,51,0);font-size:85%;" &gt;&lt;span style="font-family:verdana;"&gt;&lt;br /&gt;Please click on image to view it clear ... thanks.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_Sl4OUmOwwv0/SDzOnCy_HRI/AAAAAAAAAQw/pjte1lUYzVs/s1600-h/office_humor_4.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5205262439494393106" style="CURSOR: pointer" alt="" src="http://2.bp.blogspot.com/_Sl4OUmOwwv0/SDzOnCy_HRI/AAAAAAAAAQw/pjte1lUYzVs/s400/office_humor_4.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-size:78%;"&gt;&lt;span style="COLOR: rgb(255,102,102)"&gt;&lt;span style="COLOR: rgb(51,51,51)"&gt;© Samir Badhe , may not be reproduced without permission.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="COLOR: rgb(255,102,0)"&gt;&lt;span style="COLOR: rgb(153,51,0);font-size:85%;" &gt;&lt;span style="font-family:verdana;"&gt;&lt;a href="http://www.techfruits.com/search/label/Office%20Humor"&gt;See all office humors...&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:78%;"&gt;&lt;span style="COLOR: rgb(255,102,102)"&gt;&lt;a style="COLOR: rgb(0,0,153)" href="http://www.techfruits.com/search/label/Office%20Humor"&gt;&lt;span style="COLOR: rgb(0,0,0);font-size:85%;" &gt;&lt;span style="font-family:arial;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8325677720139466792-4186720797032242532?l=www.techfruits.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.techfruits.com/feeds/4186720797032242532/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=8325677720139466792&amp;postID=4186720797032242532" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/4186720797032242532?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/4186720797032242532?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Techfruits/~3/mJVjmwEy4sA/office-humor-4.html" title="Office Humor - 4" /><author><name>Samir Badhe</name><uri>http://www.blogger.com/profile/03722292367204759886</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="06566258307108868142" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/_Sl4OUmOwwv0/SDzOnCy_HRI/AAAAAAAAAQw/pjte1lUYzVs/s72-c/office_humor_4.png" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.techfruits.com/2008/05/office-humor-4.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0YNQn8yfCp7ImA9WxdSGE4.&quot;"><id>tag:blogger.com,1999:blog-8325677720139466792.post-7061046649297676664</id><published>2008-05-26T16:14:00.009-04:00</published><updated>2008-05-26T16:53:13.194-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-05-26T16:53:13.194-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Tricks" /><title>ORDER BY issue, with numeric values stored in char.</title><content type="html">&lt;span style="FONT-STYLE: italic"&gt;How to use order by on integer values stored in a char. field ?&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;This is a SQL problem observed many times, when we need to &lt;em&gt;order by&lt;/em&gt; ( sort ) numeric values which are stored in char field. Being stored as char, some numeric values are placed before others which should not be the case, if treated as numeric.&lt;br /&gt;e. g. if stored as char, 2 &gt; 12.&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;&lt;span style="color:#000099;"&gt;create table orderTable ( col_1 varchar(10) ) &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000099;"&gt;insert into orderTable values ( '1' )&lt;br /&gt;insert into orderTable values ( '2' )&lt;br /&gt;insert into orderTable values ( '11' )&lt;br /&gt;insert into orderTable values ( '12' )&lt;br /&gt;insert into orderTable values ( '21' )&lt;br /&gt;insert into orderTable values ( '111' )&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#009900;"&gt;--order without converting char to interger.&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#000099;"&gt;select col_1 from orderTable order by col_1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000099;"&gt;col_1&lt;br /&gt;-----&lt;br /&gt;1&lt;br /&gt;11&lt;br /&gt;111&lt;br /&gt;12&lt;br /&gt;2&lt;br /&gt;21&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Observe the output, it does'n look in order, if you considered numeric values.&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;The solution is pretty straight forward, you need to convert char value into a numeric, before you do &lt;em&gt;order by.&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000099;"&gt;select col_1 from orderTable order by convert(int, col_1)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000099;"&gt;col_1&lt;br /&gt;-----&lt;br /&gt;1&lt;br /&gt;2&lt;br /&gt;11&lt;br /&gt;12&lt;br /&gt;21&lt;br /&gt;111 &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If your numeric data is a part of a string, you can use &lt;em&gt;substring&lt;/em&gt; or other string functions, to get numeric data out, and then convert it to numeric.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="fullpost"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8325677720139466792-7061046649297676664?l=www.techfruits.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.techfruits.com/feeds/7061046649297676664/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=8325677720139466792&amp;postID=7061046649297676664" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/7061046649297676664?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/7061046649297676664?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Techfruits/~3/DpXG4EgKfro/order-by-issue-with-numeric-values.html" title="ORDER BY issue, with numeric values stored in char." /><author><name>Samir Badhe</name><uri>http://www.blogger.com/profile/03722292367204759886</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="06566258307108868142" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://www.techfruits.com/2008/05/order-by-issue-with-numeric-values.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Ck4HRH8_fSp7ImA9WxdSFkw.&quot;"><id>tag:blogger.com,1999:blog-8325677720139466792.post-1162268986256883114</id><published>2008-05-24T01:55:00.006-04:00</published><updated>2008-05-24T02:35:35.145-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-05-24T02:35:35.145-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Tricks" /><title>SQL to delete duplicate rows / records</title><content type="html">&lt;span style="font-style: italic;"&gt;How to display duplicate rows / records ?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;How to delete duplicate rows / records ? &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Consider a table ( table_a )  as below,&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;create table table_a &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;( &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;col_1 int                                                                                    &lt;span style="color: rgb(0, 153, 0);"&gt;--unique key &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;duplicateColumn1 varchar(10),     &lt;span style="color: rgb(0, 153, 0);"&gt;--column for which we want to check duplicates&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;duplciateColumn1 varchar(20)     &lt;span style="color: rgb(0, 153, 0);"&gt;--another column for which we want to check duplicates&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;) &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;--# How to select duplicate rows.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;select A.* from table_a   A &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;group by duplicateColumn1, duplicateColumn2 &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;having count(*) &gt; 1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;--# How to delete duplicate rows, keeping only one copy of the row.&lt;/span&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;delete table_a &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;from table_a A, table_a B&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;where &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;A.duplicateColumn1               = B.duplicateColumn1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;AND A.duplicateColumn2     = B.duplicateColumn2&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;AND A.col_1                           &gt; B.col_1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;or you can use SQL below,&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;delete table_a &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;where col_1 not in &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;( select max( col_1 ) from table_a group by duplicateColumn1 , duplicateColumn2 ) &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;--# How to delete duplicate rows, when table does not have a primary / unique key.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You can add an identity column to the table and treat it as an unique key. And follow above SQL.&lt;br /&gt;Or select table data into a temp table with identity column, follow above SQL on temp table, then" refresh" table_a data with the temp table data.&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8325677720139466792-1162268986256883114?l=www.techfruits.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.techfruits.com/feeds/1162268986256883114/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=8325677720139466792&amp;postID=1162268986256883114" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/1162268986256883114?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/1162268986256883114?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Techfruits/~3/kdMQUPXNUuw/sql-to-delete-duplicate-rows-records.html" title="SQL to delete duplicate rows / records" /><author><name>Samir Badhe</name><uri>http://www.blogger.com/profile/03722292367204759886</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="06566258307108868142" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.techfruits.com/2008/05/sql-to-delete-duplicate-rows-records.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUUBQXo_cSp7ImA9WxdRFUg.&quot;"><id>tag:blogger.com,1999:blog-8325677720139466792.post-7087202417500586870</id><published>2008-05-21T23:28:00.005-04:00</published><updated>2008-06-04T00:20:50.449-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-06-04T00:20:50.449-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Tips" /><title>What is timestamp data type</title><content type="html">&lt;span style="font-style: italic;"&gt;What is the difference between datetime and timestamp data types ?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;First of all, let me tell you that, there no similarity between timestamp and datetime data types. timestamp has nothing to do with calender date or time.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Then what is timestamp data type ?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;timestamp is a custom data type defined as varbinary(8).&lt;br /&gt;The value of the timestamp is maintained on server level, and current value of the timestamp is stored in a global variable, @@DBTS.&lt;br /&gt;&lt;br /&gt;To see the current value of timestamp ..&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;select @DBTS&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;go&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Observe the value returned, and you will agree that it has nothing to do with date/time.&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;So where should I use the timestamp datatype ?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If defined in a table, it can be used as a flagging column for each row in a table. Whenever, any of the column in a row gets updated the value of the timestamp column gets automatically updated by the current value of @@DBTG.&lt;br /&gt;&lt;br /&gt;So in multi-client environment, say you are updating a row, then you can check the old and new timestamp value for the row in subject.&lt;br /&gt;If the old and new value matches that means there is no other updates to the row while you were accessing the row for manipulation, so you are fine to go and do update.&lt;br /&gt;Else, if the old and new value does not match, that means, there has been some kind of update on the row, when you were browsing it, so depending on the requirements, you can develop the further logic for this condition.&lt;br /&gt;&lt;br /&gt;In brief, it is used to prevent an update on a row that has been modified during the operation.&lt;br /&gt;&lt;br /&gt;You need to use &lt;a href="http://manuals.sybase.com/onlinebooks/group-as/asg1250e/refman/@Generic__BookTextView/21997;pt=5472/*#X"&gt;tsequal()&lt;/a&gt; function is used to compare these timestamp values.&lt;br /&gt;&lt;br /&gt;It's just name ( timestamp ) which is pretty easily confusing most of us ;-).&lt;br /&gt;&lt;br /&gt;P.S. - You can have only one column of datatype timestamp in a table.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8325677720139466792-7087202417500586870?l=www.techfruits.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.techfruits.com/feeds/7087202417500586870/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=8325677720139466792&amp;postID=7087202417500586870" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/7087202417500586870?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/7087202417500586870?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Techfruits/~3/-puE338YInw/what-is-timestamp-data-type_21.html" title="What is timestamp data type" /><author><name>Samir Badhe</name><uri>http://www.blogger.com/profile/03722292367204759886</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="06566258307108868142" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.techfruits.com/2008/05/what-is-timestamp-data-type_21.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0QARXc4eip7ImA9WxdRFkk.&quot;"><id>tag:blogger.com,1999:blog-8325677720139466792.post-8763614529016686238</id><published>2008-05-21T03:03:00.009-04:00</published><updated>2008-06-05T00:49:04.932-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-06-05T00:49:04.932-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Tips" /><title>Get number of rows without using count() function</title><content type="html">&lt;span style="font-style: italic;"&gt;Efficient way to count the number of rows in a table.&lt;br /&gt;How to get table row count without using count function?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;How to get index and data size of a table?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You can use &lt;span style="font-style: italic;"&gt;sp_spaceused&lt;/span&gt; to display total number of rows in a table, index size and data size.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;sp_spaceused tableName &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;go&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If you want, to display information for each of the indexes available on this table&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;sp_spaceused tableName , 1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;go&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;br /&gt;If there is any text/image field in this table, then above will also display size reserved and unused by this column.&lt;br /&gt;&lt;br /&gt;You can use this,&lt;br /&gt;when you think table is too big to even run count(*)&lt;br /&gt;when you want to check index size&lt;br /&gt;when you want see space utilized by a text/image column&lt;br /&gt;or just take it as an database interview question :)&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;Related Posts:&lt;/span&gt;&lt;br /&gt;&lt;a href="http://www.techfruits.com/2008/05/select-count-vs-select-1-sql.html"&gt;select count(*) vs. select count(1)&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8325677720139466792-8763614529016686238?l=www.techfruits.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.techfruits.com/feeds/8763614529016686238/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=8325677720139466792&amp;postID=8763614529016686238" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/8763614529016686238?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/8763614529016686238?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Techfruits/~3/49L6H7TmlKI/number-of-rows-without-using-count.html" title="Get number of rows without using count() function" /><author><name>Samir Badhe</name><uri>http://www.blogger.com/profile/03722292367204759886</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="06566258307108868142" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://www.techfruits.com/2008/05/number-of-rows-without-using-count.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkEDQXczeSp7ImA9WxdSE0k.&quot;"><id>tag:blogger.com,1999:blog-8325677720139466792.post-62354499126778</id><published>2008-05-20T01:03:00.005-04:00</published><updated>2008-05-21T01:44:30.981-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-05-21T01:44:30.981-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Tricks" /><title>SQL to display page wise data</title><content type="html">&lt;span style="font-weight: bold;"&gt;Data pagination on database using SQL&lt;/span&gt;.&lt;br /&gt;&lt;span style="font-style: italic;"&gt;SQL to display output records, page wise without using cursors.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I did device following simple SP, some time back to address this,  sharing here with you.&lt;br /&gt;&lt;br /&gt;How it works :&lt;br /&gt;You need to pass on the page number for which you want a result set to be displayed.&lt;br /&gt;The SP will return back a result set for each page, the page size needs to be predefined.&lt;br /&gt;&lt;br /&gt;So, basically if you pass this SP,&lt;br /&gt;1, you will get first 10 records,&lt;br /&gt;2, will fetch you next 10 records,&lt;br /&gt;3, will get next 10 records for you,&lt;br /&gt;and so on ...&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;span style="color:Blue;"&gt;&lt;span style="color: rgb(0, 153, 0); font-style: italic;"&gt;--# Description : SP to implement pagination using SQL &lt;/span&gt;&lt;br /&gt;create proc getPageWiseData&lt;br /&gt;(&lt;br /&gt;@pageNo int &lt;span style="color: rgb(0, 153, 0);"&gt;--# Pass the page number as an argument.&lt;/span&gt;&lt;br /&gt;)&lt;br /&gt;as&lt;br /&gt;BEGIN&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;--# Page size defines the number of rows you are planning to show per page.&lt;/span&gt;&lt;br /&gt;declare @pageSize int&lt;br /&gt;select @pageSize = 10&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;--# variable to hold the first row number of the page.&lt;/span&gt;&lt;br /&gt;declare @from int&lt;br /&gt;select @from = ( @pageNo * @pageSize ) - ( @pageSize - 1 )&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;--# variable to hold last row number of the page.&lt;/span&gt;&lt;br /&gt;declare @to int&lt;br /&gt;select @to = ( @pageNo * @pageSize )&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;--# get the data into a temp table, with simulated rownum.&lt;/span&gt;&lt;br /&gt;select rownum = identity(10) , * into #dataWithRownum from yourTable&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;--# select the data with the calculated range for first and last row on page.&lt;/span&gt;&lt;br /&gt;select * from #dataWithRownum where rownum &gt;= @from and rownum &lt;= @to  END  &lt;span style="color: rgb(0, 0, 0);"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;If the data which needs to be retrieved in the &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="fullpost"&gt;&lt;span style="color:Blue;"&gt;#dataWithRownum &lt;span style="color: rgb(0, 0, 0);"&gt;is too big, consider retrieving it in batches.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="fullpost"&gt;&lt;span style="color:Blue;"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;You may need few modifications to match your exact requirements or if, you are working with any &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;other database, but the concept remains the same.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="fullpost"&gt;&lt;span style="color:Blue;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8325677720139466792-62354499126778?l=www.techfruits.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.techfruits.com/feeds/62354499126778/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=8325677720139466792&amp;postID=62354499126778" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/62354499126778?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/62354499126778?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Techfruits/~3/ZIezknxvbo0/sql-to-display-page-wise-data.html" title="SQL to display page wise data" /><author><name>Samir Badhe</name><uri>http://www.blogger.com/profile/03722292367204759886</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="06566258307108868142" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">3</thr:total><feedburner:origLink>http://www.techfruits.com/2008/05/sql-to-display-page-wise-data.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0AMQH8zcSp7ImA9WxdSEkg.&quot;"><id>tag:blogger.com,1999:blog-8325677720139466792.post-5906337519065757406</id><published>2008-05-19T23:57:00.011-04:00</published><updated>2008-05-19T23:56:21.189-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-05-19T23:56:21.189-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Tips" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Performance" /><title>What is clustered index and nonclustered index</title><content type="html">&lt;span style="font-weight: bold;"&gt;What is a table index ?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;What are Non-clustered and clustered indexes ?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Lets try to understand it with a analogy, a library.&lt;br /&gt;&lt;br /&gt;Consider a library, where books are arranged in sequence of Author names in the shelves. So, if you need a book written by 'Arundhati Roy' , you can go directly to the shelf which has the books written by she, instead of going sequentially through all the books.&lt;br /&gt;This is like &lt;span style="font-style: italic;"&gt;clustered index&lt;/span&gt; in database.&lt;br /&gt;&lt;br /&gt;Now suppose, you realized that some books are rather requested by titles. But as we have already arranged books in sequence of their authors, we can not rearrange it with titles in sequence, so you created a list of title and it's shelf number, so you ask me a book title, and i can get it for you from the shelf noted with it.&lt;br /&gt;This is some thing like, &lt;span style="font-style: italic;"&gt;non-clustered index&lt;/span&gt;.&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;br /&gt;Now, consider that, we frequently need a report to show books availability. So, we created a list of titles and whenever somebody takes it we mark it as 'Not Available'. This means, if we need the report, we don't even have to go to the shelf to check the availability of the book, all required information is in the list, call it a&lt;span style="font-style: italic;"&gt; covered index&lt;/span&gt; in database terms.&lt;br /&gt;&lt;br /&gt;Continuing this analogy, table indexes can be viewed as follows,&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;1.&lt;/span&gt; In case of clustered indexes, table data is physically stored in order of keys.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;2.&lt;/span&gt; There can be only one clustered index per table and multiple non-clustered indexes.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;3.&lt;/span&gt; Clustered indexes are good for range searches.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;4.&lt;/span&gt; Non-clustered indexes are good for random searches.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;5.&lt;/span&gt; Inserts and deletes can become an expensive affair in case of clustered index, as data needs to be shuffled to stored physically sorted.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;6.&lt;/span&gt; When, all the required columns in 'select' clause and 'where' clause of a SQL are available in a index key, the data page is not get accessed, resulting a good performance. This kind of indexing is called as 'covered index'.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Indexes&lt;/span&gt; is a huge subject in on it's own. This post is to give a basic understanding of the indexes.&lt;br /&gt;Improving your 'library operations' will help you improving your index selections :).  For more information check out following links.&lt;br /&gt;&lt;br /&gt;Related posts :&lt;span style="text-decoration: underline;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;a href="http://www.techfruits.com/2008/04/table-index-best-practices.html"&gt;How to use indexes for better performance.&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Further Readings :&lt;br /&gt;&lt;a href="http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.dc33621_33620_33619_1250/html/ptallbk/X59082.htm"&gt;How table index works &lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8325677720139466792-5906337519065757406?l=www.techfruits.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.techfruits.com/feeds/5906337519065757406/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=8325677720139466792&amp;postID=5906337519065757406" title="4 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/5906337519065757406?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/5906337519065757406?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Techfruits/~3/3GuuHq7mtK4/clustered-index-and-nonclustered-index.html" title="What is clustered index and nonclustered index" /><author><name>Samir Badhe</name><uri>http://www.blogger.com/profile/03722292367204759886</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="06566258307108868142" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">4</thr:total><feedburner:origLink>http://www.techfruits.com/2008/05/clustered-index-and-nonclustered-index.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A08NQXo4fCp7ImA9WxRbGEs.&quot;"><id>tag:blogger.com,1999:blog-8325677720139466792.post-5779827430437486042</id><published>2008-05-16T00:30:00.011-04:00</published><updated>2008-12-09T19:44:50.434-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-12-09T19:44:50.434-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Office Humor" /><title>Office Humor - 3</title><content type="html">&lt;span style="COLOR: rgb(255,102,0)"&gt;&lt;br /&gt;&lt;span style="COLOR: rgb(153,51,0);font-size:85%;" &gt;&lt;span style="font-family:verdana;"&gt;Please click on image to view it clear ... thanks.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_Sl4OUmOwwv0/SC0RtDyH5qI/AAAAAAAAAQU/gAUz48SkJFs/s1600-h/office_humor_3.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5200832610490115746" style="CURSOR: pointer" alt="" src="http://3.bp.blogspot.com/_Sl4OUmOwwv0/SC0RtDyH5qI/AAAAAAAAAQU/gAUz48SkJFs/s400/office_humor_3.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="COLOR: rgb(0,0,0);font-size:78%;" &gt;&lt;span style="COLOR: rgb(255,102,102)"&gt;© Samir Badhe , may not be reproduced without permission.&lt;/span&gt;&lt;/span&gt;&lt;span style="TEXT-DECORATION: underline"&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.techfruits.com/search/label/Office%20Humor"&gt;See all office humors...&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8325677720139466792-5779827430437486042?l=www.techfruits.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.techfruits.com/feeds/5779827430437486042/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=8325677720139466792&amp;postID=5779827430437486042" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/5779827430437486042?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/5779827430437486042?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Techfruits/~3/PnCndMG5ePs/office-humor-3.html" title="Office Humor - 3" /><author><name>Samir Badhe</name><uri>http://www.blogger.com/profile/03722292367204759886</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="06566258307108868142" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/_Sl4OUmOwwv0/SC0RtDyH5qI/AAAAAAAAAQU/gAUz48SkJFs/s72-c/office_humor_3.png" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.techfruits.com/2008/05/office-humor-3.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0IBQn45eyp7ImA9WxdRFkk.&quot;"><id>tag:blogger.com,1999:blog-8325677720139466792.post-8404559188540702243</id><published>2008-05-13T00:08:00.022-04:00</published><updated>2008-06-05T00:52:33.023-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-06-05T00:52:33.023-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Tips" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Performance" /><title>select count(*) vs. select count(1)</title><content type="html">&lt;span style="font-weight: bold;"&gt;What is the difference between &lt;span style="font-style: italic;"&gt;select count(*) &lt;/span&gt;and &lt;span style="font-style: italic;"&gt;select count(1)&lt;/span&gt; ?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This was a long pending question in my mind so, I did a little bit of search and study to convince myself that ... there is a difference, may be because SQL Query Optimizer would expand '*' into the column list.&lt;br /&gt;&lt;br /&gt;But if we compare, SQL query plans and performance is same for both of them.&lt;br /&gt;&lt;br /&gt;Then, I thought of finding the answer using the way Sybase ASE tends to think.&lt;br /&gt;Depending on that, it seems there is no difference in 'select count(1)' and 'select count(*)'&lt;br /&gt;Even, 'select count(100)' would give the same performance.&lt;br /&gt;&lt;br /&gt;Here are my findings ...&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;br /&gt;Consider a table&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;create table TAB_A&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;(&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;col_1 int null,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;col_2 varchar(20) null,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;col_3 char(1) null&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;)&lt;/span&gt;&lt;br /&gt;Data:&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;insert into TAB_A values ( 1, 'Seabiscuit' , 'H')&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;insert into TAB_A values ( 2, 'Schindlers List' , 'H')&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;insert into TAB_A values ( 3, 'Trueman Show' , 'H')&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;insert into TAB_A values ( NULL, 'Office Space' , 'H')&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;insert into TAB_A values ( NULL, NULL, NULL)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Here is how 'count' function works.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;1. count ( column_name ) :&lt;/span&gt; finds the total number of 'non null' rows in the table.&lt;br /&gt;Exa.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;select count(col_1) from TAB_A&lt;/span&gt;&lt;br /&gt;---------&lt;br /&gt;3&lt;br /&gt;&lt;br /&gt;and&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;select count(col_2) from TAB_A&lt;/span&gt;&lt;br /&gt;---------&lt;br /&gt;4&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;2. count(*) :&lt;/span&gt; finds the total number of rows in the table, irrespective of null values.&lt;br /&gt;&lt;br /&gt;Exa.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;select count(*) from TAB_A&lt;/span&gt;&lt;br /&gt;---------&lt;br /&gt;5&lt;br /&gt;&lt;br /&gt;Now, if we consider that Sybase expands '*' into the column list, then above two definitions of 'count' function does not allow this.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;A. &lt;/span&gt;Suppose, sybase has expanded the '*' into column list, then the SQL will become&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;select count( col_1, col_2, col_3 ) from TAB_A&lt;/span&gt;&lt;br /&gt;---------&lt;br /&gt;Server Message : Number 102, Severity 15&lt;br /&gt;Incorrect syntax near ',' .&lt;br /&gt;&lt;br /&gt;This is not allowed, you can not pass comma separated column names to 'count' function.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;B. &lt;/span&gt;Even if, we argue that point A is internal matter to optimizer and any how, it might have been worked around internally, in that case according to first definition, null values will be ignored while counting number. This is not correct, as we know 'count(*) ' always returns total number of rows, even if there are nulls.&lt;br /&gt;&lt;br /&gt;So, from A and B we can say '*' can not get expanded internally.&lt;br /&gt;&lt;br /&gt;Then, why is '*' here ?&lt;br /&gt;I think, as opposed to "all columns" in general 'select query', here '*' indicates "all rows" of the table, including NULL values.&lt;br /&gt;&lt;br /&gt;Also, after this analysis, I feel comfortable to say that, any number or string other than the column name might be getting converted to '*' , before executing the SQL to count the total number rows available in table.&lt;br /&gt;&lt;br /&gt;Example :&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;select count( 1947) from TAB_A&lt;/span&gt;&lt;br /&gt;---------&lt;br /&gt;5&lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;select count('someString') from TAB_A&lt;/span&gt;&lt;br /&gt;---------&lt;br /&gt;5&lt;br /&gt;&lt;br /&gt;So, the only overhead, I can think of is to convert 1947 or 'someString' to '*' ,&lt;br /&gt;which should be far less than negligible .&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;Related Posts:&lt;/span&gt;&lt;br /&gt;&lt;a href="http://www.techfruits.com/2008/05/number-of-rows-without-using-count.html"&gt;Get number of rows without using count() function&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8325677720139466792-8404559188540702243?l=www.techfruits.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.techfruits.com/feeds/8404559188540702243/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=8325677720139466792&amp;postID=8404559188540702243" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/8404559188540702243?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/8404559188540702243?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Techfruits/~3/_z0nYLUlX4U/select-count-vs-select-1-sql.html" title="select count(*) vs. select count(1)" /><author><name>Samir Badhe</name><uri>http://www.blogger.com/profile/03722292367204759886</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="06566258307108868142" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.techfruits.com/2008/05/select-count-vs-select-1-sql.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEENQXc-fSp7ImA9WxdSFEU.&quot;"><id>tag:blogger.com,1999:blog-8325677720139466792.post-7959834898784139041</id><published>2008-05-10T01:50:00.017-04:00</published><updated>2008-05-22T16:04:50.955-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-05-22T16:04:50.955-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Tips" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Tricks" /><title>How to get output of one Stored Procedure into another</title><content type="html">&lt;span style="font-weight: bold;"&gt;Sharing data between two stored procedures&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;em&gt;How to return a status code from stored procedure&lt;/em&gt;&lt;br /&gt;&lt;em&gt;Using Output parameters in stored procedure&lt;/em&gt;&lt;br /&gt;&lt;em&gt;Use temporary table populated by inner stored procedure&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;1. How to return a status code from SP&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;In this case, we can simply 'return' some value, which can be some system defined status flags or you can return your own value.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;--# SP, which returns 100 on some error condition otherwise 0&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;create proc sp_returnCode&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;as&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;... some processing ....&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;If ( ...some error condition... )&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;return 100 &lt;span style="color: rgb(0, 102, 0);"&gt;--#Your custom return code&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;else&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;return 0 &lt;span style="color: rgb(0, 102, 0);"&gt;--#Success code&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This SP can be called by another SP or query, to collect this return status as below&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;declare @status int&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;execute @status = sp_returnCode&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;select @status&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Note that, only one value can be "returned"&lt;br /&gt;&lt;br /&gt;Sybase ASE does reserve 0 to indicate 'success' and -1 to -99 return codes to indicate different errors . For your custom return codes use other than this range.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;2. Using Output parameters in SP&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;This is another way to return values from one SP to another SP or query .&lt;br /&gt;Output parameters are defined like input parameters.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;--#SP to multiply &lt;/span&gt;&lt;/span&gt;&lt;span class="fullpost" style="color: rgb(0, 102, 0);"&gt;two INPUT parameters &lt;/span&gt;&lt;span class="fullpost"&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;and return the result in OUTPUT parameter.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;create proc sp_multiply&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;( &lt;/span&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;@para_1 int, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;@para_2 int, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;@result int OUTPUT &lt;/span&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;as&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;select @result = @para1 * @para2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;--#Collect the output result&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;declare @result int exec sp_multiply 7, 3, @result OUTPUT&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Unlike 'return code', you can return multiple OUTPUT parameters&lt;br /&gt;Lets update above SP, to have a additional OUTPUT parameter, say addition of two numbers.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;create proc sp_multiplyAdd&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;( &lt;/span&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;@para_1 int, @para_2 int, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;@result_1 int OUTPUT, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;@result_2 int OUTPUT &lt;/span&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;as&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;select @result_1 = @para1 * @para2&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;select @result_2 = @para1 + @para2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You can access the two OUTPUT variables of the stored procedure as below,&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;declare @result_1 int &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;declare @result_2 int &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;exec sp_multiplyAdd 7, 3, @result_1 OUTPUT , @result_2 OUTPUT&lt;br /&gt;select &lt;/span&gt;&lt;/span&gt;&lt;span class="fullpost"&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;@result_1 , &lt;/span&gt;&lt;/span&gt;&lt;span class="fullpost"&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;@result_2 &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;3. Sharing temp table between two Stored Procedures &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If you want to use a result set from one stored procedure into another, temporary tables can be a good option.&lt;br /&gt;&lt;br /&gt;Basically, we create a temp. table which is populated by first SP, and the same temp. table is then used by another stored procedure.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;--#Create a temp. table, with same definition as that of the result set. &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;create table #shareMe &lt;/span&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;( col_1 int, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;col_2 char(9), &lt;/span&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;...... &lt;/span&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;--#Create a SP to populate this table with the SP result set as below&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;create proc sp_populateResult&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;as&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;insert into #shareMe&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;select * from TAB_A where col_1 = @someValue&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Note : Once this SP is compiled you can drop the temp table, as we will be creating it in calling SP.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Now you can access this temp table in another stored procedure.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;create proc sp_consumeResult&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;as&lt;br /&gt;BEGIN&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;--#Define the temp. table&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;select * into #shareMe from TAB_A where 1 = 2&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;--#Execute the SP which populates the result set. &lt;/span&gt;&lt;br /&gt;exec sp_populateResult&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;--#Access temp table&lt;/span&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;&lt;br /&gt;select * from #shareMe&lt;br /&gt;&lt;br /&gt;END&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="fullpost"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8325677720139466792-7959834898784139041?l=www.techfruits.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.techfruits.com/feeds/7959834898784139041/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=8325677720139466792&amp;postID=7959834898784139041" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/7959834898784139041?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/7959834898784139041?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Techfruits/~3/QzWqo9_RIOs/output-of-one-stored-procedure-into_10.html" title="How to get output of one Stored Procedure into another" /><author><name>Samir Badhe</name><uri>http://www.blogger.com/profile/03722292367204759886</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="06566258307108868142" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.techfruits.com/2008/05/output-of-one-stored-procedure-into_10.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A08NQXszeSp7ImA9WxRbGEs.&quot;"><id>tag:blogger.com,1999:blog-8325677720139466792.post-8463035377358211306</id><published>2008-05-06T02:10:00.021-04:00</published><updated>2008-12-09T19:44:50.581-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-12-09T19:44:50.581-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Office Humor" /><title>Office Humor - 2</title><content type="html">Please click on image to view full size and clear image... thanks.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_Sl4OUmOwwv0/SCTfe5--lqI/AAAAAAAAAOw/Z0VCQfYx2BE/s1600-h/office_2.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5198525591946434210" style="CURSOR: pointer" alt="" src="http://4.bp.blogspot.com/_Sl4OUmOwwv0/SCTfe5--lqI/AAAAAAAAAOw/Z0VCQfYx2BE/s400/office_2.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="COLOR: rgb(255,102,102);font-size:78%;" &gt;© Samir Badhe , may not be reproduced without permission. &lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#000000;"&gt;&lt;a href="http://www.techfruits.com/2008/05/office-time-humor-1.html"&gt;Office Humor - 1&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8325677720139466792-8463035377358211306?l=www.techfruits.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.techfruits.com/feeds/8463035377358211306/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=8325677720139466792&amp;postID=8463035377358211306" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/8463035377358211306?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/8463035377358211306?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Techfruits/~3/bSdP7RbUg8k/office-humor-2.html" title="Office Humor - 2" /><author><name>Samir Badhe</name><uri>http://www.blogger.com/profile/03722292367204759886</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="06566258307108868142" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/_Sl4OUmOwwv0/SCTfe5--lqI/AAAAAAAAAOw/Z0VCQfYx2BE/s72-c/office_2.png" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.techfruits.com/2008/05/office-humor-2.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkYGSXo5eyp7ImA9WxdSE0g.&quot;"><id>tag:blogger.com,1999:blog-8325677720139466792.post-994065700262223951</id><published>2008-05-05T22:03:00.006-04:00</published><updated>2008-05-21T02:08:48.423-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-05-21T02:08:48.423-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Tricks" /><title>Get column details of a table using syscolumns</title><content type="html">&lt;span style="font-style: italic;"&gt;How to get table's column list ?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Various information along with column list can be retrieved using syscolumns table.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;1.&lt;/span&gt;&lt;br /&gt;--Get the list of columns and their data types, available in a table&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;SELECT  A.name columnName,  B.name dataType&lt;br /&gt;FROM syscolumns  A, systypes B&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;WHERE id = object_id( '&lt;span style="color: rgb(255, 102, 102);"&gt;anyTableName&lt;/span&gt;')  and A.type = B.type&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;ORDER BY colid&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;2.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;--Get the list of tables which has a particular column name.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;SELECT object_name(id) tableName, name columnName FROM syscolumns&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;WHERE name = '&lt;span style="color: rgb(255, 102, 102);"&gt;someColumnName&lt;/span&gt;'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;3.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;--Get the list of tables which is like a particular column name.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;SELECT object_name(id) tableName, name columnName&lt;br /&gt;FROM syscolumns&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;WHERE name like '&lt;span style="color: rgb(255, 102, 102);"&gt;someColumnName&lt;/span&gt;%'&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8325677720139466792-994065700262223951?l=www.techfruits.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.techfruits.com/feeds/994065700262223951/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=8325677720139466792&amp;postID=994065700262223951" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/994065700262223951?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8325677720139466792/posts/default/994065700262223951?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Techfruits/~3/RLBlNmYJFQk/get-column-details-of-table-using.html" title="Get column details of a table using syscolumns" /><author><name>Samir Badhe</name><uri>http://www.blogger.com/profile/03722292367204759886</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="06566258307108868142" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://www.techfruits.com/2008/05/get-column-details-of-table-using.html</feedburner:origLink></entry></feed>
