<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-963036445075953465</id><updated>2026-10-14T12:19:57.764-07:00</updated><category term="Sybase ASE"/><title type='text'>Sybase ASE</title><subtitle type='html'>Sybase ASE or Sybase Adaptive Server Enterprise is an enterprise flagship product from Sybase Corporation. &#xa;&#xa;Sybase ASE is widely used RDBMS in large number of financial and insurance institutions for handling their data.&#xa;&#xa;Sybase ASE is a blog related to various articles and tutorials on Sybase ASE database.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://sybase-ase.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://sybase-ase.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Neo</name><uri>http://www.blogger.com/profile/14411612301710790630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih5eFHd3lIHV1CYT5PPrEZgjHIVHUiD-8tfIbAefa1dzIsRz12qFqKxr9c1fc05q0yROrcIR_RpspnqUF24fTuEnwtjXlS5DUglz95eE9W6iitEczavDBjAKf6TK6mfj8/s220/23022008758.jpg'/></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><entry><id>tag:blogger.com,1999:blog-963036445075953465.post-1075216195750373138</id><published>2013-07-07T11:11:00.000-07:00</published><updated>2013-07-07T11:11:02.653-07:00</updated><title type='text'>What is Deadlock and how to simulate deadlock in Sybase ASE?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
In multitasking system and multiple processes running at the same time over number of resources sometimes we end up into a situation where each process starts waiting for a resource currently held by other resource and none of them in a position to let go off the resources held by them until the claimed resource is allocated to them. Pretty confusing? Yes, it is to some extent so we will first explain why a deadlock occurs. Lets say we have two processes P1 and P2 running parallely and there are two resources R1 and R2. Now both P1 and P2 start a transaction of their own and claim the two resouces in the following manner -&lt;br /&gt;
&lt;br /&gt;
For Session 1 running P1 -&lt;br /&gt;
&lt;br /&gt;
Step 1 - P1 claims R1 in shared mode&lt;br /&gt;
Step 2 - P1 wants to claim R2 in Exclusive mode&lt;br /&gt;
&lt;br /&gt;
For Session 2 running P2 -&lt;br /&gt;
&lt;br /&gt;
Step 1 - P2 claims R2 in shared mode&lt;br /&gt;
Step 2 - P2 wants to claim R1 in Exclusive mode&lt;br /&gt;
&lt;br /&gt;
Now in the above situation if P1 or P2 runs both of their steps before the other process gets the CPU cycle then there wont be a deadlock however if in case when P1 completes step 1 and P2 starts executing Step 1 then both of the processes will each have a shared lock on separate resources. Now if again process P1 executes Step 2 then P1 will end up waiting for the resource R2 as exclusive mode is incompatible with the shared mode and same will happen with process P2. However, when process P2 will try to have exclusive mode right on the resource R1, system will enter into a deadlock situation and hence one of them will be detected by the system as deadlock victim and will be rolled back with the appropriate message.&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sybase-ase.blogspot.com/feeds/1075216195750373138/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sybase-ase.blogspot.com/2013/07/what-is-deadlock-and-how-to-simulate.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/1075216195750373138'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/1075216195750373138'/><link rel='alternate' type='text/html' href='http://sybase-ase.blogspot.com/2013/07/what-is-deadlock-and-how-to-simulate.html' title='What is Deadlock and how to simulate deadlock in Sybase ASE?'/><author><name>Neo</name><uri>http://www.blogger.com/profile/14411612301710790630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih5eFHd3lIHV1CYT5PPrEZgjHIVHUiD-8tfIbAefa1dzIsRz12qFqKxr9c1fc05q0yROrcIR_RpspnqUF24fTuEnwtjXlS5DUglz95eE9W6iitEczavDBjAKf6TK6mfj8/s220/23022008758.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-963036445075953465.post-1109496672384659993</id><published>2011-09-14T10:25:00.000-07:00</published><updated>2011-09-14T10:25:22.709-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sybase ASE"/><title type='text'>How to Insert dummy data in a table to increase the size of the table in Sybase ASE?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Sometimes it is required to do performance testing of stored procedures and scripts over tables with large volume of data no matter of the exact data and the problem is we dont have data in the table. Then how to create dummy data in a table just to increase the size of the data. Well, one solution that we can use is to write insert statements&amp;nbsp;in a while loop and insert same data again and again until we have sufficient data in the table or we can do something else? Yes, we can. How? Lets find it out..&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
To insert dummy data&amp;nbsp; into a table just to increase the size of the table in one shot can be done in the following way; however there is a high probability that u may end up filling up ur transaction log in this way if u choose very high input data in one shot. So, here is the example to show how we can do that -&lt;br /&gt;
&lt;br /&gt;
First lets create a table from &lt;strong&gt;&lt;em&gt;ASEISQL (a free&amp;nbsp;Sybase editor available on the internet but you can use anything of your choice)&lt;/em&gt;&lt;/strong&gt;&amp;nbsp;like this -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;create table TAB1&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;(&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;&amp;nbsp;&amp;nbsp; EmpId int IDENTITY,&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;&amp;nbsp;&amp;nbsp; EmpName varchar(100),&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;&amp;nbsp;&amp;nbsp; EmpSalary float&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;)&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;go&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
Now open &lt;strong&gt;&lt;em&gt;ISQL&lt;/em&gt;&lt;/strong&gt; from &lt;strong&gt;&lt;em&gt;cmd&lt;/em&gt;&lt;/strong&gt; prompt as -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;goto Run -&amp;gt; cmd.&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
In the command window type the following -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;Isql -S&amp;lt;servername&amp;gt; -U&amp;lt;UserName&amp;gt; -P&amp;lt;password&amp;gt; &lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
Now type the following in the isql prompt -&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #9fc5e8;&quot;&gt;&lt;strong&gt;&lt;em&gt;&amp;gt; use &amp;lt;database name&amp;gt;&lt;/em&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #9fc5e8;&quot;&gt;&lt;strong&gt;&lt;em&gt;&amp;gt; go&lt;/em&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #9fc5e8;&quot;&gt;&lt;strong&gt;&lt;em&gt;&amp;gt; insert into TAB1 (EmpName, EmpSalary) values(&#39;Tom&#39;, 10000.00)&lt;/em&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #9fc5e8;&quot;&gt;&lt;strong&gt;&lt;em&gt;&amp;gt; go 10000&lt;/em&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
As we can see the above statement will insert the above value &lt;strong&gt;&lt;em&gt;10000&lt;/em&gt;&lt;/strong&gt; times in the table &lt;strong&gt;&lt;em&gt;TAB1&lt;/em&gt;&lt;/strong&gt; but this will be a logged event so take care as this will try to fill up your transaction log and you may end up yourself with a hung session. So, be careful!&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sybase-ase.blogspot.com/feeds/1109496672384659993/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/how-to-insert-dummy-data-in-table-to.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/1109496672384659993'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/1109496672384659993'/><link rel='alternate' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/how-to-insert-dummy-data-in-table-to.html' title='How to Insert dummy data in a table to increase the size of the table in Sybase ASE?'/><author><name>Neo</name><uri>http://www.blogger.com/profile/14411612301710790630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih5eFHd3lIHV1CYT5PPrEZgjHIVHUiD-8tfIbAefa1dzIsRz12qFqKxr9c1fc05q0yROrcIR_RpspnqUF24fTuEnwtjXlS5DUglz95eE9W6iitEczavDBjAKf6TK6mfj8/s220/23022008758.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-963036445075953465.post-8510822326826651158</id><published>2011-09-13T10:37:00.000-07:00</published><updated>2011-09-14T10:05:52.486-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sybase ASE"/><title type='text'>How to quit from a Sybase ASE session?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;When connected to a Sybase ASE server we can use the following sybase function to quit the existing session -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;syb_quit()&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
The syntax to quit the session is -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;select syb_quit()&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
On executing the statement we will receive the following information messages -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: red;&quot;&gt;ct_results(): network packet layer: internal net libraryerror: Net-Library operation terminated due to disconnect&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
which suggests that the connection has been terminated.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sybase-ase.blogspot.com/feeds/8510822326826651158/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/how-to-quit-from-sybase-ase-session.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/8510822326826651158'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/8510822326826651158'/><link rel='alternate' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/how-to-quit-from-sybase-ase-session.html' title='How to quit from a Sybase ASE session?'/><author><name>Neo</name><uri>http://www.blogger.com/profile/14411612301710790630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih5eFHd3lIHV1CYT5PPrEZgjHIVHUiD-8tfIbAefa1dzIsRz12qFqKxr9c1fc05q0yROrcIR_RpspnqUF24fTuEnwtjXlS5DUglz95eE9W6iitEczavDBjAKf6TK6mfj8/s220/23022008758.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-963036445075953465.post-4665152332382148409</id><published>2011-09-13T10:26:00.000-07:00</published><updated>2011-09-23T10:39:29.089-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sybase ASE"/><title type='text'>How to find Index List in a Sybase database?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;strong&gt;Index List&lt;/strong&gt; - Yes you heard it right, we want to find the index list to find all the indexes in a database. But how to do that? Someone might say that we can query the sysindexes table and we will be able to get the complete list using a simple query -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;select si.* from sysobjects so, sysindexes si where so.id = si.id&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;go&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
Well, yes that&#39;s right but in this case we will also get table names along with the index names in case we have non-clustered indexes on the table as Sybase makes table names entry in the sysindexes table. So, how about just getting the index names? Well to do that we need to modify the above query slightly and we will be able to get the index list in the database. The modified query is -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;select &lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;&amp;nbsp; si.* &lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;from &lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;&amp;nbsp; sysobjects so, sysindexes si &lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;where &lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;&amp;nbsp; so.id = si.id and&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;&amp;nbsp; si.indid &amp;gt; 0&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;go&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
Wondering why we modified the original query like this?&lt;br /&gt;
&lt;br /&gt;
To&amp;nbsp;answer this lets check the above query again. In the above query we are trying to select only those entries from &lt;strong&gt;sysindexes&lt;/strong&gt; table whose &lt;strong&gt;indid&lt;/strong&gt; i.e. the index id is greater than 0 and for information purpose - &lt;strong&gt;Sybase ASE&lt;/strong&gt; makes a table entry with &lt;strong&gt;indid&lt;/strong&gt; as 0 (Table Scan) in the &lt;strong&gt;sysindexes&lt;/strong&gt; table with &lt;strong&gt;clustered index&lt;/strong&gt; acquiring the position 1 and the rest are the &lt;strong&gt;non-clustered&lt;/strong&gt; indexes. So with this information in mind we can now&amp;nbsp;re-validate that the above query returns only the index list in a Sybase database and that was what was required by us.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sybase-ase.blogspot.com/feeds/4665152332382148409/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/how-to-find-index-list-in-sybase.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/4665152332382148409'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/4665152332382148409'/><link rel='alternate' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/how-to-find-index-list-in-sybase.html' title='How to find Index List in a Sybase database?'/><author><name>Neo</name><uri>http://www.blogger.com/profile/14411612301710790630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih5eFHd3lIHV1CYT5PPrEZgjHIVHUiD-8tfIbAefa1dzIsRz12qFqKxr9c1fc05q0yROrcIR_RpspnqUF24fTuEnwtjXlS5DUglz95eE9W6iitEczavDBjAKf6TK6mfj8/s220/23022008758.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-963036445075953465.post-440928972613116347</id><published>2011-09-13T09:51:00.000-07:00</published><updated>2011-09-14T10:10:13.738-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sybase ASE"/><title type='text'>How to find the names of columns in an Index on a table in Sybase ASE?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Ever wondered how &lt;strong&gt;sp_helpindex&lt;/strong&gt; can get the column names&amp;nbsp;in an index created on a Sybase table when the same information is not available handy via the system tables. Well, looking into the system stored procedure &lt;strong&gt;sp_helptext&lt;/strong&gt; throws some light on how this can be achieved and what is the master key to find the column names of an index.&lt;br /&gt;
&lt;br /&gt;
To look at the system stored procedure we will get the procedures text via another stored procedure &lt;strong&gt;sp_helptext&lt;/strong&gt;. The syntax to get a stored procedures text is as follows -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;sp_helptext &amp;lt;&amp;lt;procedure name&amp;gt;&amp;gt;&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
So, for our case it will be -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;sp_helptext sp_helpindex&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
Now if we look at the system stored procedure &lt;strong&gt;sp_helpindex&lt;/strong&gt; we will find that there is a special Sybase function &lt;strong&gt;index_col&lt;/strong&gt; which is being used within a while loop to extract column names for each index&amp;nbsp;existing on the table. Therefore to find the column names of an index in a script we can use &lt;strong&gt;index_col&lt;/strong&gt; function. To demonstrate this we will create an example where we will try to find out column names in an index on a table in Sybase ASE and see if &lt;strong&gt;index_col&lt;/strong&gt; function will really help us.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
To begin with the example, first we will create a table &lt;strong&gt;MyTab&lt;/strong&gt; with the following &lt;strong&gt;create table&lt;/strong&gt;&amp;nbsp;command -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;create table MyTab&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;(&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;&amp;nbsp;&amp;nbsp; Id int,&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;&amp;nbsp;&amp;nbsp; Name varchar(100),&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dsc varchar(100),&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;&amp;nbsp; StartDate datetime,&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;&amp;nbsp; EndDate datetime&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;)&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;go&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
and then we will create a &lt;strong&gt;clustered index&lt;/strong&gt; on this table using the &lt;strong&gt;create index&lt;/strong&gt; command -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;create clustered index MyTabC on MyTab(Id, StartDate)&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;go&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
As we can see in the above statement we have created a clustered index on &lt;strong&gt;MyTab&lt;/strong&gt; table over the columns - &lt;strong&gt;Id&lt;/strong&gt; and &lt;strong&gt;StartDate&lt;/strong&gt;.&lt;br /&gt;
Just to counter check we will execute a query on sysindexes table to see if we have actually created a &lt;strong&gt;clustered index&lt;/strong&gt; on the table -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;select * from sysindexes where id = (select id from sysobjects where name = &#39;MyTab&#39;)&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;go&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
On executing the above statement we find that yes we have actually created a clustered index on our table with the index id (refer column indid in sysindexes table) of 1.&lt;br /&gt;
Now, just before creating the script to find index column names we will first have a look at the syntax of Sybase function &lt;strong&gt;index_col&lt;/strong&gt;. The syntax for &lt;strong&gt;index_col&lt;/strong&gt; function is -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;index_col(Table_Name, Index_Id, key_index, user_id)&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
As we can see in the above statement -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Table_Name&lt;/strong&gt; - is the table&amp;nbsp;for whose index we are trying to find the column names,&lt;br /&gt;
&lt;strong&gt;Index_Id&lt;/strong&gt; - is the id of the index as per &lt;strong&gt;sysindexes&lt;/strong&gt; system table,&lt;br /&gt;
&lt;strong&gt;Key_Index&lt;/strong&gt; - is the index of the field or column which consitituted the index and can vary upto keycnt column value in the &lt;strong&gt;sysindexes&lt;/strong&gt; table,&lt;br /&gt;
&lt;strong&gt;User_Id&lt;/strong&gt; - is the owner of the object. In case we do not specify the same then it will default to the current user.&lt;br /&gt;
&lt;br /&gt;
Now, once everything is done and the syntax for &lt;strong&gt;index_col&lt;/strong&gt; understood well, we will try to find out the names of columns in the index using&amp;nbsp;a simple script shown below-&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;declare @keys integer&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;select @keys = keycnt from sysindexes where id = object_id(&quot;MyTab&quot;) and indid = 1&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;while @keys &amp;gt; 0&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;begin&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;select index_col(&quot;MyTab&quot;, 1, @keys)&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;select @keys = @keys - 1&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;end&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;go&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
As we can see in the above script we first tried to find out the total key count for the index whose index id is 1; what it actually means is that we will find the key count for the clustered index we have created already which will give us the value 2. We get the key count from the &lt;strong&gt;keycnt&lt;/strong&gt;&amp;nbsp;column in &lt;strong&gt;sysindexes&lt;/strong&gt; table. Once we have the key count with us we simply looped through to find column names one at a time. The command -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: #9fc5e8;&quot;&gt;select index_col(&quot;MyTab&quot;, 1, @keys)&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
on first iteration will give the column name - &lt;strong&gt;StartDate&lt;/strong&gt; and on the next it will give the &lt;strong&gt;Id&lt;/strong&gt; column name.&lt;br /&gt;
&lt;br /&gt;
And finally that&#39;s all we required to find the column names in an index. Now as a next step we can refine the above script to form a string and return the result to us but thats an experimental program left for you all... Will be back with some more good stuff later. Till then have a great day ahead..&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sybase-ase.blogspot.com/feeds/440928972613116347/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/how-to-find-names-of-columns-in-index.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/440928972613116347'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/440928972613116347'/><link rel='alternate' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/how-to-find-names-of-columns-in-index.html' title='How to find the names of columns in an Index on a table in Sybase ASE?'/><author><name>Neo</name><uri>http://www.blogger.com/profile/14411612301710790630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih5eFHd3lIHV1CYT5PPrEZgjHIVHUiD-8tfIbAefa1dzIsRz12qFqKxr9c1fc05q0yROrcIR_RpspnqUF24fTuEnwtjXlS5DUglz95eE9W6iitEczavDBjAKf6TK6mfj8/s220/23022008758.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-963036445075953465.post-7016991800451846516</id><published>2011-09-10T09:35:00.000-07:00</published><updated>2011-09-23T10:40:20.106-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sybase ASE"/><title type='text'>DefnCopy Utility! How to get Views, Stored Procedures, Trigger structure in a text file?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Views, Stored procedures and triggers - sometimes we require to extract the structure or definition of these database objects in a text file, so what to do if somone asks us to do the same?&lt;br /&gt;
&lt;strong&gt;Don&#39;t worry! Defncopy to the rescue!!&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
Now what is &lt;strong&gt;Defncopy&lt;/strong&gt;? Never heard about it. No worries! Today we will explain you and give you a glimpse about this excellent utility.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Defncopy&lt;/strong&gt; is a command line utility program provided by &lt;strong&gt;Sybase Inc (now SAP company)&lt;/strong&gt; with the &lt;strong&gt;Sybase&amp;nbsp;Adaptive Server Enterprise&amp;nbsp;RDBMS&lt;/strong&gt;&amp;nbsp;to achieve this for us. &lt;strong&gt;For Example -&lt;/strong&gt; If we have a stored procedure – MyProcedure1 which has the following definition –&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;create proc MyProcedure1&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; @MyVar varchar(100)&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;as&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;begin&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp;&amp;nbsp; select * from MyTable whereName = @MyVar&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;end&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;go&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
and if we want to get this definition of compiled stored procedure MyProcedure1 in a text file then we can use the Sybase Inc provided &lt;strong&gt;DefnCopy&lt;/strong&gt; utility. This utility is also available when we have only&amp;nbsp;the client program installed on&amp;nbsp;our machine.&lt;br /&gt;
&lt;br /&gt;
The syntax for &lt;strong&gt;DefnCopy&lt;/strong&gt; utility via the command prompt is as follows –&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;defncopy -S &amp;lt;&amp;lt;SERVER NAME&amp;gt;&amp;gt; -U&amp;lt;&amp;lt;USER NAME&amp;gt;&amp;gt; -P &amp;lt;&amp;lt;PASSWORD&amp;gt;&amp;gt; out &amp;lt;&amp;lt;FILE WITHCOMPLETE PATH&amp;gt;&amp;gt; &amp;lt;&amp;lt;DATABASE&amp;gt;&amp;gt; &amp;lt;&amp;lt;OBJECT NAME&amp;gt;&amp;gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;In the above syntax&amp;nbsp;&lt;strong&gt;&amp;lt;&amp;lt;OBJECT NAME&amp;gt;&amp;gt;&lt;/strong&gt; can be either a stored procedure, trigger, view etc whose definition exists in the syscomments table&lt;/em&gt;. &lt;br /&gt;
&lt;br /&gt;
The only catch is that we cannot extract tables definition via this utility as for a table definition we need to query sysobject and syscolumns tables and this definition does not exist in the syscomments table. &lt;br /&gt;
&lt;br /&gt;
Please keep in mind that there is a space between each of the options (switches)specified above and the option value which means –&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;There is a space between –S and&amp;lt;&amp;lt;SERVER NAME&amp;gt;&amp;gt; in above syntax.&lt;/em&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;&lt;strong&gt;Please note -&lt;/strong&gt; This utility can be run through the command prompt only or via using the extended stored procedure for cmd.&lt;/em&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sybase-ase.blogspot.com/feeds/7016991800451846516/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/defncopy-utility-how-to-get-views.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/7016991800451846516'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/7016991800451846516'/><link rel='alternate' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/defncopy-utility-how-to-get-views.html' title='DefnCopy Utility! How to get Views, Stored Procedures, Trigger structure in a text file?'/><author><name>Neo</name><uri>http://www.blogger.com/profile/14411612301710790630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih5eFHd3lIHV1CYT5PPrEZgjHIVHUiD-8tfIbAefa1dzIsRz12qFqKxr9c1fc05q0yROrcIR_RpspnqUF24fTuEnwtjXlS5DUglz95eE9W6iitEczavDBjAKf6TK6mfj8/s220/23022008758.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-963036445075953465.post-440359197003178926</id><published>2011-09-08T12:46:00.000-07:00</published><updated>2011-09-22T10:31:05.713-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sybase ASE"/><title type='text'>How to force a Table Scan in Sybase?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Are indexes always useful and mandatory on a table or Is Table scan on a table always a bad news for us? To understand what is good for us we need to know the exact purpose of indexes and what is meant by a Table scan? When a user executes a query and the Sybase server has to iterate over each row of each page in a Sybase table then the scan that Sybase server is currently performing is called a Table scan.&lt;br /&gt;
&lt;br /&gt;
In case we have created indexes and used proper SARGs then the Sybase server will pick up an appropriate index and fetch our results more quickly than any Table scan. However, this is just one part of the story and is applicable only when tables are of very large size. So, always create indexes on a table which is of very large size otherwise there are lots of overheads to maintain and keep the indexes up to date in Sybase. In case of smaller tables it is better to be without Indexes than using an Index. So, what to do in case we have some data in the table and have some indexes created on the table and still want to force Sybase to perform a table scan? This is usually required when the data in a table is serialized or sequential and we are sure that first few records is all that we need to iterate on.&lt;br /&gt;
&lt;br /&gt;
So, now knowing that we need a Table scan in Sybase we need to make sure that Sybase server does not use any index while executing the query. This is called forcing a table scan. To force a table scan in Sybase we can use a simple statement like this -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;select * from my_table (index 0) where col1 = @col1&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
As we can see here that we have suggested (index 0) to be used in the above mentioned query? Wondering why and what does (index 0) specify? Well, 0 here refers to the 0th entry in sysindexes table which is actually representing a table scan. Hence by suggesting the index we can force a table scan in Sybase.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sybase-ase.blogspot.com/feeds/440359197003178926/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/how-to-force-table-scan-in-sybase.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/440359197003178926'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/440359197003178926'/><link rel='alternate' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/how-to-force-table-scan-in-sybase.html' title='How to force a Table Scan in Sybase?'/><author><name>Neo</name><uri>http://www.blogger.com/profile/14411612301710790630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih5eFHd3lIHV1CYT5PPrEZgjHIVHUiD-8tfIbAefa1dzIsRz12qFqKxr9c1fc05q0yROrcIR_RpspnqUF24fTuEnwtjXlS5DUglz95eE9W6iitEczavDBjAKf6TK6mfj8/s220/23022008758.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-963036445075953465.post-916233006715206125</id><published>2011-09-08T12:34:00.000-07:00</published><updated>2011-09-23T10:45:04.435-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sybase ASE"/><title type='text'>How to find tables or database objects created in a database on a particular day in Sybase?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;While working in database it is sometimes required to get a list of tables or database objects created on a particular day and it is not too hard to find the same. However we just need to keep in mind where to look for this particular set of information and we are done with the problem. As we all know that all the database objects when created in a database are maintained in the sysobjects system table on the Sybase SQL Server or Sybase Adaptive Server Enterprise RDBMS hence the best candidate to tell us the creation date/day of the database object should be the sysobjects system tables.&lt;br /&gt;
&lt;br /&gt;
On looking at the sysobjects table we find that there is infact a crdate column which suggests the date on which date and time of the day a particular database object was created and using this information we can find the correct information that we require. A simple sql statement to find all the datasbase objects created on 1st Jan 2010 would be -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;select * from sysobjects where crdate&amp;nbsp;= convert(date, &#39;01/01/2010&#39;, 0)&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
The above sql will list all the database objects created on 1st Jan 2010.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Note: As the above query involves coversion os string to date using convert function hence the syntax may vary based on your date settings.&lt;/em&gt;&lt;/strong&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sybase-ase.blogspot.com/feeds/916233006715206125/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/how-to-find-tables-or-database-objects.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/916233006715206125'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/916233006715206125'/><link rel='alternate' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/how-to-find-tables-or-database-objects.html' title='How to find tables or database objects created in a database on a particular day in Sybase?'/><author><name>Neo</name><uri>http://www.blogger.com/profile/14411612301710790630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih5eFHd3lIHV1CYT5PPrEZgjHIVHUiD-8tfIbAefa1dzIsRz12qFqKxr9c1fc05q0yROrcIR_RpspnqUF24fTuEnwtjXlS5DUglz95eE9W6iitEczavDBjAKf6TK6mfj8/s220/23022008758.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-963036445075953465.post-2010201256348385758</id><published>2011-09-08T12:23:00.000-07:00</published><updated>2011-09-23T10:46:43.112-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sybase ASE"/><title type='text'>What is the difference between Login and User in Sybase ASE?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Login and User - two terminologies which are often confused by the new database developers. What is that credential called which is used to connect to a Sybase server? Is it a Login or a User?&lt;br /&gt;
&lt;br /&gt;
To settledown this confusion and give a clear picture to the reader we must first clarify that logins and users - these terms are very vaguely used in computer science every now and then and as far as Sybase is concerned here also we find many people using different terms to specify something else. For example we will often find developers saying - what is the user id and password for logging into the server. As you can see that the above statement is completly incorrect as user is the person who wants log in to the sybase server however that person uses appropriate credentials to login to the system which is actually a pair of login name aka login and password.&lt;br /&gt;
&lt;br /&gt;
To clarify it further we must know that login&#39;s basic purpose is to allow a security check on which ever person&amp;nbsp;or application tries to enter into our Server. hence it tries to authenticate and validate the user which could be either a person or an application.&lt;br /&gt;
&lt;br /&gt;
Once the correct user has logged in we must try to provide an identity to the login which has connected to our server and hence have a User attached to this Login. The purpose of User is to restrict or allows access to various parts of databases and also for attaching the ownership to the database objects. Therefore if we do not want to allow certain login to access certain database we can restrict this user by not associating it with an appropriate user id in that particular database.&lt;br /&gt;
&lt;br /&gt;
Now enough of the theory and coming to practical aspect. A login as allows access to the server hence has an appropriate entry in the syslogins table on the master database of the Sybase server while a User attached to a particular login has entries in the sysalternates or sysusers tables in each database. In case, there is no entry for a login in sysusers or sysalternates tables of a particular database then the user is not allowed access to that particular database provided there is no guest user in the database otherwise the required login will be able to connect to the database using guest user.&lt;br /&gt;
&lt;br /&gt;
That explained we can now understand that well there is a Login and there is a User and neither Login is a User nor User is a Login. Happy coding until next article.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sybase-ase.blogspot.com/feeds/2010201256348385758/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/login-and-user-in-sybase-ase.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/2010201256348385758'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/2010201256348385758'/><link rel='alternate' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/login-and-user-in-sybase-ase.html' title='What is the difference between Login and User in Sybase ASE?'/><author><name>Neo</name><uri>http://www.blogger.com/profile/14411612301710790630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih5eFHd3lIHV1CYT5PPrEZgjHIVHUiD-8tfIbAefa1dzIsRz12qFqKxr9c1fc05q0yROrcIR_RpspnqUF24fTuEnwtjXlS5DUglz95eE9W6iitEczavDBjAKf6TK6mfj8/s220/23022008758.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-963036445075953465.post-346952150293586224</id><published>2011-09-08T12:08:00.000-07:00</published><updated>2011-09-23T10:47:26.719-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sybase ASE"/><title type='text'>Where is Query Plan stored in Sybase?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Adaptive Server Enterprise or Sybase ASE before processing and executing a query prepares a query plan for each of the user submitted query and then actually executes the query based on the query plan. This is a pretty simple concept, however what is interesting to know here is - Where is the Query Plan stored in Sybase?&lt;br /&gt;
&lt;br /&gt;
Some people might say that the query plan is saved in system tables however that is not completely true. The reason is that the query is the final blue print over which the Sybase server tries to execute the query based on a parse tree. Now, someone might ask out of curiosity that what is a parsed tree then? When a user submits a query in Sybase, the query is first checked syntactically and then&amp;nbsp;a parse tree is prepared for the query execution and the object id&#39;s are mapped to the parse tree. While executing the query after preparing the parse tree Sybase server prepares many sets of query plans and estimates its costs. Once the query plan with minimum cost is created the Sybase server selects this query plan and uses it. This query plan exists in the procedure cache of the Sybase server which is recreated and flushed on each server restart. So, if our Sybase server shuts down and restarted again a new query plan will be created on the next execution of the stored procedure from the stored parse tree.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sybase-ase.blogspot.com/feeds/346952150293586224/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/where-is-query-plan-stored-in-sybase.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/346952150293586224'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/346952150293586224'/><link rel='alternate' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/where-is-query-plan-stored-in-sybase.html' title='Where is Query Plan stored in Sybase?'/><author><name>Neo</name><uri>http://www.blogger.com/profile/14411612301710790630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih5eFHd3lIHV1CYT5PPrEZgjHIVHUiD-8tfIbAefa1dzIsRz12qFqKxr9c1fc05q0yROrcIR_RpspnqUF24fTuEnwtjXlS5DUglz95eE9W6iitEczavDBjAKf6TK6mfj8/s220/23022008758.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-963036445075953465.post-2065200432008723609</id><published>2011-09-08T11:53:00.000-07:00</published><updated>2011-09-23T10:48:42.973-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sybase ASE"/><title type='text'>What should be the size of tempdb in Sybase?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;tempdb database or the temporary database in Sybase ASE is the place where Sybase Server while trying to execute the user queries creates all sort of worktables and temporary tables etc. The tempdb database hence is one of the most important databases on a Sybase server. But have you ever asked as what should be the tempdb size which I should keep to keep my Sybase server running happily ever after?&lt;br /&gt;
&lt;br /&gt;
But before that one may ask as why is the size really our concern? To answer this we need to check the exact purpose of tempdb database. As already said the tempdb database is used to do all the intermediary things required by our Sybase server like creating worktables, sorting results and temporary table creation etc, so if all these operations are done in the tempdb database then we must be very sure that the tempdb database doesn&#39;t run out of space as there might be lots of users accessing the tempdb database.&lt;br /&gt;
&lt;br /&gt;
So, with reason justified should we start calculating the tempdb size which will serve our purpose? Well, the major problem with this question is that there is no hard and fast rule to determine the tempdb size in Sybase to be very sure that it serves our purpose. Tempdb size is usually determined based on the size and the purpose of the applications using the Sybase databases. If we have very short queries for our applications then we need not require a very large tempdb space, however if we have very complex and lengthy queries that gets fired every now and than, then we need to have a large tempdb size to avoid running out of space. Usually it is recommended that the tempdb size should be approximately &lt;strong&gt;20% - 25%&lt;/strong&gt; of the largest database supported on a Sybase server. But as already said this figure will not hold true in every case. So, the next time you think of creating a tempdb you know that you need to experiment a lot to choose the optimistic approach.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sybase-ase.blogspot.com/feeds/2065200432008723609/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/what-should-be-size-of-tempdb-in-sybase.html#comment-form' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/2065200432008723609'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/2065200432008723609'/><link rel='alternate' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/what-should-be-size-of-tempdb-in-sybase.html' title='What should be the size of tempdb in Sybase?'/><author><name>Neo</name><uri>http://www.blogger.com/profile/14411612301710790630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih5eFHd3lIHV1CYT5PPrEZgjHIVHUiD-8tfIbAefa1dzIsRz12qFqKxr9c1fc05q0yROrcIR_RpspnqUF24fTuEnwtjXlS5DUglz95eE9W6iitEczavDBjAKf6TK6mfj8/s220/23022008758.jpg'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-963036445075953465.post-6436248028582785793</id><published>2011-09-08T11:25:00.000-07:00</published><updated>2011-09-22T10:31:55.282-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sybase ASE"/><title type='text'>How to force an Index in Sybase?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Forcing an index in a query though might be a risky operation however is sometimes useful too as if there are very similar indexes created on a table and we specfically want to use one of them then we can specify the same in the query. How? Well, pretty simple. Simply use the following syntax if you need to force an index while framing the query and Sybase Adaptiver Server will try picking up the specified index. The sql query is as follows -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;select * from table_name (index index_name) where col1 = @col1 and col2 = @col2&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
As we can see in the above statement simply suggesting the index name will help us force an index on a table. The only catch here is that we need to be very sure that what we are doing is what is required and in case of any doubts it is better to leave the rest to Sybase server and simple design the correct query.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sybase-ase.blogspot.com/feeds/6436248028582785793/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/how-to-force-index-in-sybase.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/6436248028582785793'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/6436248028582785793'/><link rel='alternate' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/how-to-force-index-in-sybase.html' title='How to force an Index in Sybase?'/><author><name>Neo</name><uri>http://www.blogger.com/profile/14411612301710790630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih5eFHd3lIHV1CYT5PPrEZgjHIVHUiD-8tfIbAefa1dzIsRz12qFqKxr9c1fc05q0yROrcIR_RpspnqUF24fTuEnwtjXlS5DUglz95eE9W6iitEczavDBjAKf6TK6mfj8/s220/23022008758.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-963036445075953465.post-7887222828608937149</id><published>2011-09-06T12:48:00.000-07:00</published><updated>2011-09-23T10:56:19.359-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sybase ASE"/><title type='text'>Can we use DDL statements in a transaction in Sybase ASE?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Sybase ASE allows the use of Data Definition Language statements within a transaction and so we can have create table, create view etc statements with the transaction block i.e. between begin and commit or rollback tran.&lt;br /&gt;
&lt;br /&gt;
However, this feature is a configurable option named - &lt;strong&gt;&quot;ddl in tran&quot;&lt;/strong&gt; and is available at database level, which means that the configurable parameter &lt;strong&gt;&quot;ddl in tran&quot;&lt;/strong&gt; needs to be switched on whenever we think we need to use this option. But have you ever thought - &quot;why is it so that &lt;strong&gt;ddl in tran&lt;/strong&gt; is actually a configurable option?&quot; or it would be much better to rephrase as - &quot;Why does Sybase won&#39;t recommend using DDL statements within a transaction for normal case?&quot;.&lt;br /&gt;
&lt;br /&gt;
Well, the answer to both these questions which infact are same and differ only in the way they express the thought is that whenever a DDL command or Data Definition language commands are executed by Sybase ASE then Adaptive Server needs to acquire locks on system tables and as we all know acquring locks on system tables for a longer transaction might actually degrade database performance. Hence this option is usually not recommended by Sybase, however if we are in dire need of using this option - for example - we need to execute queries using Oracle Hetrogeneous Services (Oracle - Sybase Gateway) which wraps each sql statement run from Oracle end into an implicit transaction before sending the query to Sybase end, we can enable &lt;strong&gt;ddl in tran&lt;/strong&gt; database option but try to keep our transactions as short and specific as possible.&lt;br /&gt;
&lt;br /&gt;
The only place where Sybase strictly disallow us in using &lt;strong&gt;ddl in tran&lt;/strong&gt; option is in the temporary database or the tempdb which is supposed to behave unexpectedly on enabling this option. If we enable this option in temporary database tempdb then the databases may stop responding and behave unexpectedly. Therefore tempdb should never be enabled with &lt;strong&gt;ddl in tran&lt;/strong&gt; option.&lt;br /&gt;
&lt;br /&gt;
Now coming to the basic question as how to enable this option in a Sybase database. The answer to this is - &quot;Use &lt;strong&gt;sp_configure&lt;/strong&gt; system stored procedures&quot;. The syntax for enabling this option is -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;sp_configure &amp;lt;&amp;lt;Database name&amp;gt;&amp;gt;, &#39;ddl in tran&#39;, true&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
and to switch off this option simply use -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;sp_configure &amp;lt;&amp;lt;Database Name&amp;gt;&amp;gt;, &#39;ddl in tran&#39;, false&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Please note - sp_configure is a system stored procedure and while trying to enable/disable this option the user needs to be in the master database.&lt;/em&gt;&lt;/strong&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sybase-ase.blogspot.com/feeds/7887222828608937149/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/can-we-use-ddl-statements-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/7887222828608937149'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/7887222828608937149'/><link rel='alternate' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/can-we-use-ddl-statements-in.html' title='Can we use DDL statements in a transaction in Sybase ASE?'/><author><name>Neo</name><uri>http://www.blogger.com/profile/14411612301710790630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih5eFHd3lIHV1CYT5PPrEZgjHIVHUiD-8tfIbAefa1dzIsRz12qFqKxr9c1fc05q0yROrcIR_RpspnqUF24fTuEnwtjXlS5DUglz95eE9W6iitEczavDBjAKf6TK6mfj8/s220/23022008758.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-963036445075953465.post-2688727092680412952</id><published>2011-09-06T12:20:00.000-07:00</published><updated>2011-09-06T12:20:50.977-07:00</updated><title type='text'>How many types of control statements are present in Sybase ASE?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Adaptiver Server Enterprise provides four different types of control statements for performing various tasks in database. These different types of control statements in Sybase are -&lt;br /&gt;
&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;strong&gt;DDL or Data Definition Language statements&lt;/strong&gt; - These are the statements that are being used to define various database objects or alter them. Some of such statements are - create table, create view, alter table etc.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;DML or Data Manipulation Language statements&lt;/strong&gt; - These are the control statements which are used to do various manipulations on the data stored in various database objects. Some such statements are - insert into, update, delete etc.T&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;TCL or Transaction Control Language statements&lt;/strong&gt; - These are statements which are being used to control transactions in Sybase database. Example - begin tran, commit tran, savepoint etc.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;DCL or Data Control Language statements&lt;/strong&gt; - These are statements which are used to provide security access to various database objects. Example - grant and revoke.&lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sybase-ase.blogspot.com/feeds/2688727092680412952/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/how-many-types-of-control-statements.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/2688727092680412952'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/2688727092680412952'/><link rel='alternate' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/how-many-types-of-control-statements.html' title='How many types of control statements are present in Sybase ASE?'/><author><name>Neo</name><uri>http://www.blogger.com/profile/14411612301710790630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih5eFHd3lIHV1CYT5PPrEZgjHIVHUiD-8tfIbAefa1dzIsRz12qFqKxr9c1fc05q0yROrcIR_RpspnqUF24fTuEnwtjXlS5DUglz95eE9W6iitEczavDBjAKf6TK6mfj8/s220/23022008758.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-963036445075953465.post-3604929482096510910</id><published>2011-09-06T12:04:00.000-07:00</published><updated>2011-09-23T10:56:50.237-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sybase ASE"/><title type='text'>Sybase Infocenter - One place to know it all.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Newbies would ask - &quot;Where is the best Sybase (any product including Sybase ASE or Sybase Adaptive Server Enterprise RDBMS) related material on the internet or which is the best Sybase learning material?&quot;. Well there isn&#39;t anywhere that you have to go to get the required information about relevant products and learning material in Sybase products, just go to -&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://infocenter.sybase.com/help/index.jsp&quot;&gt;&lt;strong&gt;http://infocenter.sybase.com/help/index.jsp&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
and you can browse through a collection of learning materials both online and in Adobe Acrobat Reader (pdf) format for learning and mastering the product.&lt;br /&gt;
&lt;br /&gt;
For Example - If I want to know detailed syntax of create table or create database commands in Sybase ASE version 12.5.x or 15.x then simple go to the above link expand the appropriate product link and you can refer developer and administrator learning material in the site which will guide you through every step as you master and excel in the product.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sybase-ase.blogspot.com/feeds/3604929482096510910/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/sybase-infocenter-one-place-to-know-it.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/3604929482096510910'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/3604929482096510910'/><link rel='alternate' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/sybase-infocenter-one-place-to-know-it.html' title='Sybase Infocenter - One place to know it all.'/><author><name>Neo</name><uri>http://www.blogger.com/profile/14411612301710790630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih5eFHd3lIHV1CYT5PPrEZgjHIVHUiD-8tfIbAefa1dzIsRz12qFqKxr9c1fc05q0yROrcIR_RpspnqUF24fTuEnwtjXlS5DUglz95eE9W6iitEczavDBjAKf6TK6mfj8/s220/23022008758.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-963036445075953465.post-8780531276107298483</id><published>2011-09-03T13:17:00.000-07:00</published><updated>2011-09-03T13:17:00.041-07:00</updated><title type='text'>How to create column names with blank space as a separator in Sybase ASE?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Usually when we try to create a table with some given set of column names we are not able to use blank in between the column name so if we have to create a column say - Employee Name then we create it like EmpName or EmployeeName with no space. What if we require to have the same column name as - &quot;Employee Name&quot; or &quot;Emp Name&quot;? What to do in such a case?&lt;br /&gt;
&lt;br /&gt;
Well, if we will try to create the column name using the simple method then we will hit on the column name error very early as soon as we try to create the table structure or add one using alter table command. So we will try to use similar approach with a slight tweak so as to tell the Adaptiver Server that we want to name the column specifically as what we are suggesting in the command so please let us do the same. A normal create table command to create an Employee table will be as follows -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;create table Employee&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;(&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; EmpId int,&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; EmployeeName varchar(100),&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; EmpAge int,&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; EmpSalary float,&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; DeptId int&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;)&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;go&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
However, to get create the table with a blank space in between we will write the same syntax as -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;create table Employee&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;(&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt; &amp;nbsp;&amp;nbsp; [Emp Id] int,&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp;&amp;nbsp; [Employee Name] varchar(100),&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt; &amp;nbsp;&amp;nbsp; [Emp Age] int,&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt; &amp;nbsp;&amp;nbsp; [Emp Salary] float,&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp;&amp;nbsp; [Dept Id] int&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;)&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;go&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
and we are done with it.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sybase-ase.blogspot.com/feeds/8780531276107298483/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/how-to-create-column-names-with-blank.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/8780531276107298483'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/8780531276107298483'/><link rel='alternate' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/how-to-create-column-names-with-blank.html' title='How to create column names with blank space as a separator in Sybase ASE?'/><author><name>Neo</name><uri>http://www.blogger.com/profile/14411612301710790630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih5eFHd3lIHV1CYT5PPrEZgjHIVHUiD-8tfIbAefa1dzIsRz12qFqKxr9c1fc05q0yROrcIR_RpspnqUF24fTuEnwtjXlS5DUglz95eE9W6iitEczavDBjAKf6TK6mfj8/s220/23022008758.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-963036445075953465.post-4898193058816839478</id><published>2011-09-03T12:53:00.000-07:00</published><updated>2011-09-03T12:58:20.541-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sybase ASE"/><title type='text'>Lock Table command in Sybase ASE?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;There are basically two types of &lt;strong&gt;locks &lt;/strong&gt;which we can have on a &lt;strong&gt;Sybase ASE&lt;/strong&gt; table namely the -&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;strong&gt;Shared Lock and&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Exclusive Lock&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;The &lt;strong&gt;shared lock &lt;/strong&gt;is a lock which when taken on a table then the other processes can also aquire a share lock on the same table for reading the data. Basically this type of lock is taken when performing a select and is done automatically by the Sybase ASE server just before reading the data. Once a shared lock has been taken on a table no other process can have an exclusive lock on the table as the shared and exclusive locks are incompatible so the process wanting to take an exclusive lock will need to wait until the read operations have been performed.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Exclusive lock&lt;/strong&gt; as the name suggests require a single access to the table with no other process able to read or modify the data present in the table at the same time. This is done because when a process requires an exclusive lock on a table then the process wants to update the data on the table which will take sometime and until then if some other process tries to read the data from the table then it might view inconsistent data which wont be preferrable.&lt;br /&gt;
&lt;br /&gt;
Usually, exclusive lock is taken by a process on data modifications automatically and shared lock is taken automatically by the Sybase ASE server for&amp;nbsp;a process just before reading the data from the table, however if we want we can specifically suggest to Sybase ASE server that we want to have an exlusive lock on the table in a transaction. The &lt;strong&gt;lock table command &lt;/strong&gt;syntax to do so is as follows -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;lock table &amp;lt;&amp;lt;Table Name&amp;gt;&amp;gt; in &amp;lt;&amp;lt;share|exclusive&amp;gt;&amp;gt; mode &lt;span style=&quot;color: #e06666;&quot;&gt;{optional}&lt;/span&gt; with &amp;lt;&amp;lt;nowait| wait &lt;span style=&quot;color: #0b5394;&quot;&gt;time in sec&lt;/span&gt;&amp;gt;&amp;gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
The above syntax will help us have a shared (share) or exclusive (exclusive) lock on the table.&lt;br /&gt;
&lt;br /&gt;
The above syntax comes with an optional with clause to specify the time the process needs to wait in case the lock cannot be acquired immediately. In case we do not want to wait we can use the nowait option.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Remember, we can acquire locks on tables only within the transactions so we need to have lock statements between begin and commit/rollback transaction blocks.&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Also, a lock gets removed once the transaction either gets rollbacked or committed and hence there is no seperate command to remove lock on a table.&lt;/em&gt;&lt;/strong&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sybase-ase.blogspot.com/feeds/4898193058816839478/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/lock-table-command-in-sybase-ase.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/4898193058816839478'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/4898193058816839478'/><link rel='alternate' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/lock-table-command-in-sybase-ase.html' title='Lock Table command in Sybase ASE?'/><author><name>Neo</name><uri>http://www.blogger.com/profile/14411612301710790630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih5eFHd3lIHV1CYT5PPrEZgjHIVHUiD-8tfIbAefa1dzIsRz12qFqKxr9c1fc05q0yROrcIR_RpspnqUF24fTuEnwtjXlS5DUglz95eE9W6iitEczavDBjAKf6TK6mfj8/s220/23022008758.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-963036445075953465.post-2229543288386839607</id><published>2011-09-03T12:36:00.000-07:00</published><updated>2011-09-03T12:36:06.888-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sybase ASE"/><title type='text'>How to find the locking scheme of a table in Sybase ASE?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;When a table is already existing in a system and we are asked to find out the locking scheme for a table to figure out the best possible tuning steps then we can use the sp_help stored procedure to find the appropriate locking scheme for the existing table. &lt;br /&gt;
The Sybase ASE stored procedure sp_help when run on a table will list the table structure and other relevant information, also it will show us the locking scheme for the table in the message window. So in case your current locking scheme is All Page Locks then the same will be displayed on the screen. To find the appropriate information use the following syntax -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;sp_help &amp;lt;&amp;lt;Table Name&amp;gt;&amp;gt;&lt;/em&gt;&lt;/strong&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sybase-ase.blogspot.com/feeds/2229543288386839607/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/how-to-find-locking-scheme-of-table-in.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/2229543288386839607'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/2229543288386839607'/><link rel='alternate' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/how-to-find-locking-scheme-of-table-in.html' title='How to find the locking scheme of a table in Sybase ASE?'/><author><name>Neo</name><uri>http://www.blogger.com/profile/14411612301710790630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih5eFHd3lIHV1CYT5PPrEZgjHIVHUiD-8tfIbAefa1dzIsRz12qFqKxr9c1fc05q0yROrcIR_RpspnqUF24fTuEnwtjXlS5DUglz95eE9W6iitEczavDBjAKf6TK6mfj8/s220/23022008758.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-963036445075953465.post-4464495384538438456</id><published>2011-09-01T11:08:00.000-07:00</published><updated>2011-09-01T11:08:09.965-07:00</updated><title type='text'>What is Dynamic SQL or what is the use of Dynamic SQL in Sybase ASE?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Many times database developers are required to write queries based on data which is not present at the time of creation of scripts/stored procedures etc and Dynamic SQL is a way by which the Adaptiver Server Enterprise allows us to write such queries.&lt;br /&gt;
&lt;br /&gt;
Well you might be thinking whether such situation&amp;nbsp;may actually occur&amp;nbsp;or is it just another R&amp;amp;D work we are trying to do here? So, now we will try to explain when you might be hit on with such a condition. Lets say, we are asked to find which database a particular table name or stored procedure exists and lets say we have around 10 databases to work on including default Sybase databases, so what will you do in such a simple case. Will you try to run a query on sysobjects table for one and for all databases one at a time, or you will try to specifically create 10 different queries to prefix database name in front of each database&#39;s sysobject table to find the required information?&lt;br /&gt;
&lt;br /&gt;
The key to database programming is to work effeciently so that the required information is at hand there and then... Never too late, never too early but just in time... So to get this information we will use Dynamic SQL statments to hit on our system tables at runtime with appropriate amendments and we are done with this job.&lt;br /&gt;
&lt;br /&gt;
In case we would have been required to extract this information from a single database then the required sql would have been -&lt;br /&gt;
&lt;br /&gt;
select * from sysobjects where name like &#39;%ObjectName%&#39; and type in (&#39;U&#39;, &#39;P&#39;)&lt;br /&gt;
go&lt;br /&gt;
&lt;br /&gt;
Here ObjectName is the database object which we want to find using this sql. We have used like in the statement to just insure that we find all the database objects which also match the required name (just to make sure that our user is not forgetting the exact database object name).&lt;br /&gt;
&lt;br /&gt;
Now as we have to use this query for all the different databases hence we will write the following dynamic sql within a stored procedure to get the required result -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;create procedure rsp_ObjectFinder&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; @ObjectName varchar(35)&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;as&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;begin&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;declare &lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; @DBName varchar(35),&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; @MySQL varchar(255),&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; @Counter int,&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; @CountLimit int&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;create table #MyTable&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;(&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp;&amp;nbsp; Id numeric(10,0) Identity,&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp;&amp;nbsp; DBName varchar(35)&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;)&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;insert into #MyTable (DBName)&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;select Name from master..sysdatabases&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;select&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; @CountLimit = @@rowcount,&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; @Counter = 1&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;while (@Counter &amp;lt;= @CountLimit)&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;begin&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; &lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; select @DBName = DBName from #MyTable where Id = @Counter&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; &lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; select @MySQL = &#39;select &#39;&#39;&#39; + @DBName + &#39;&#39;&#39; DatabaseName,* from &#39; + @DBName + &#39;..&#39;+&#39;sysobjects where name like &#39;&#39;%&#39; + @ObjectName + &#39;%&#39;&#39;and type in (&#39;&#39;P&#39;&#39;, &#39;&#39;U&#39;&#39;)&#39;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp;&amp;nbsp;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; exec(@MySQL)&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; &lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; select @Counter = @Counter + 1&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; &lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;end&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;end&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;go&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
As we can see from the above example we have been able to query all the databases for certain database object. This example stored procedure can be further refined to incorporate many more features. Well, thats all for now will be back with more cool facts and topics sometime later...&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sybase-ase.blogspot.com/feeds/4464495384538438456/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/what-is-dynamic-sql-or-what-is-use-of.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/4464495384538438456'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/4464495384538438456'/><link rel='alternate' type='text/html' href='http://sybase-ase.blogspot.com/2011/09/what-is-dynamic-sql-or-what-is-use-of.html' title='What is Dynamic SQL or what is the use of Dynamic SQL in Sybase ASE?'/><author><name>Neo</name><uri>http://www.blogger.com/profile/14411612301710790630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih5eFHd3lIHV1CYT5PPrEZgjHIVHUiD-8tfIbAefa1dzIsRz12qFqKxr9c1fc05q0yROrcIR_RpspnqUF24fTuEnwtjXlS5DUglz95eE9W6iitEczavDBjAKf6TK6mfj8/s220/23022008758.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-963036445075953465.post-6736502946442549785</id><published>2011-08-30T11:36:00.000-07:00</published><updated>2011-08-30T11:36:02.274-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sybase ASE"/><title type='text'>How to get column names of a table using the bcp utility in Sybase?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;BCP program or the bulk copy program utility is used to extract data from a table into a flat file but can we have the column names of a table along with the table&#39;s data in the file?&lt;br /&gt;
&lt;br /&gt;
The bcp utility does not offer a switch to extract column name so we need to have a workaround to achieve the same and what could that be? So, to tackle this situation here is Views to the rescue. To explain this concept we will be creating a table Employee with the following definition -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;create table Employee&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;(&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp;&amp;nbsp; EmpId int,&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp;&amp;nbsp; EmpName varchar(100),&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp;&amp;nbsp; Age int,&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp;&amp;nbsp; Salary float&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;)&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;go&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
Now, we will create the following view -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;create view V as&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;select&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; &quot;EmpId&quot;,&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; &quot;EmpName&quot;,&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; &quot;Age&quot;,&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; &quot;Salary&quot;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;from&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; Employee&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;where 1=1&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;union&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;select&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; convert(varchar, EmpId),&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; EmpName,&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; convert(varchar, Age),&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; convert(varchar, Salary)&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;from&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; Employee&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;go&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
As we can see here that we have created a view &lt;strong&gt;&lt;em&gt;V&lt;/em&gt;&lt;/strong&gt; which will do a union of column names and columns data. On executing this view we get the column name and the data both in a single resultset.&lt;br /&gt;
&lt;br /&gt;
Now what remains is running the bcp command to extract the data to a flat file and the command to accomplish this is as follows -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;bcp Database.Owner.ViewName out FilePath -SSERVERNAME -UUSERNAME -PPASSWORD -c -t,&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
and thats it.. We will get the column name and the data in a flat file simply by creating a view. Isn&#39;t it simple?&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sybase-ase.blogspot.com/feeds/6736502946442549785/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sybase-ase.blogspot.com/2011/08/how-to-get-column-names-of-table-using.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/6736502946442549785'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/6736502946442549785'/><link rel='alternate' type='text/html' href='http://sybase-ase.blogspot.com/2011/08/how-to-get-column-names-of-table-using.html' title='How to get column names of a table using the bcp utility in Sybase?'/><author><name>Neo</name><uri>http://www.blogger.com/profile/14411612301710790630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih5eFHd3lIHV1CYT5PPrEZgjHIVHUiD-8tfIbAefa1dzIsRz12qFqKxr9c1fc05q0yROrcIR_RpspnqUF24fTuEnwtjXlS5DUglz95eE9W6iitEczavDBjAKf6TK6mfj8/s220/23022008758.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-963036445075953465.post-4019454932099418472</id><published>2011-08-30T10:38:00.000-07:00</published><updated>2011-08-30T10:38:32.443-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sybase ASE"/><title type='text'>Types of Temporary tables in Sybase and what is the difference between them?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;How many types of temporary tables are there in Sybase? How often have you encountered this question? Pretty much... Right? Yup! And here is the answer to much liked question related to Sybase ASE.&lt;br /&gt;
&lt;br /&gt;
Sybase Adaptive Server Enterprise allows developers to create two different types of temporary tables namely -&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Session Temporary Table&lt;/li&gt;
&lt;li&gt;Tempdb temporary table&lt;/li&gt;
&lt;/ol&gt;In general both of these table are created in tempdb database however there are few differences between the two. &lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;The major difference that appears is that session specific temp tables represented by a &lt;strong&gt;&lt;em&gt;#&lt;/em&gt;&lt;/strong&gt; &lt;strong&gt;&lt;em&gt;(pound symbol)&lt;/em&gt;&lt;/strong&gt; in front of the table name works for the lifetime of a session, which means that once the session is closed the temp table is flushed and all the entries are removed from the system tables. In contrary a tempdb temp table specified by the long name like -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;tempdb.owner.temptable&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
persists even after the session is closed until the Sybase server itself is restarted which will then recreate the tempdb database completely hence removing all the entries from the&amp;nbsp; system catalogue. As session specific table is created and destroyed within a session hence it cannot be used by different users to share the data wherease the tempdb database can be used to share the data between users.&lt;br /&gt;
&lt;br /&gt;
One more difference that exists between these two tables is that session specific table will be suffixed with a 17 digit session number to keep it unique just in case two users in two different sessions create the same session specific temp table with the same name. As the maximum limit of a variable name is upto 30 characters hence we can name a session specific temp table only upto a length of 13 characters before the name will be automatically truncated by the Sybase ASE server. So if we try to name two session specific temp tables like -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;#thisis17char&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;#thisis17characterlong&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
then the Sybase server will truncate the remaining characters of &lt;strong&gt;&lt;em&gt;#thisis17characterlong&lt;/em&gt;&lt;/strong&gt; preceding 13 characters and hence we will be encountered with the error -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: red;&quot;&gt;Table name already exists in the system catalogue&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
because temp table &lt;strong&gt;&lt;em&gt;#thisis17char&lt;/em&gt;&lt;/strong&gt; already exists.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sybase-ase.blogspot.com/feeds/4019454932099418472/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sybase-ase.blogspot.com/2011/08/types-of-temporary-tables-in-sybase-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/4019454932099418472'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/4019454932099418472'/><link rel='alternate' type='text/html' href='http://sybase-ase.blogspot.com/2011/08/types-of-temporary-tables-in-sybase-and.html' title='Types of Temporary tables in Sybase and what is the difference between them?'/><author><name>Neo</name><uri>http://www.blogger.com/profile/14411612301710790630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih5eFHd3lIHV1CYT5PPrEZgjHIVHUiD-8tfIbAefa1dzIsRz12qFqKxr9c1fc05q0yROrcIR_RpspnqUF24fTuEnwtjXlS5DUglz95eE9W6iitEczavDBjAKf6TK6mfj8/s220/23022008758.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-963036445075953465.post-768568125521840209</id><published>2011-08-29T10:53:00.000-07:00</published><updated>2011-08-29T10:56:38.068-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sybase ASE"/><title type='text'>Will addition or removal of columns in a table effect the view created on the same table in Sybase ASE?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Wonder what will happen when a view is created on a table but later on the table column list gets altered using the Alter Table command. Will the view automatically get updated with the new/deleted columns in the table?&lt;br /&gt;
&lt;br /&gt;
Well the answer to this is &lt;strong&gt;&lt;em&gt;&quot;OfCourse No&quot;&lt;/em&gt;&lt;/strong&gt;. Why? The answer to this is much simple than what might appear. We all know that a view is a simple database object which has its definition stored in the syscomments system table and does not store any of the information anywhere in the database. This is opposite to what a table does. Now when a table gets altered and a column which was earlier present in the table has been dropped then on envoking the view the Sybase ASE server will try to check the view definition which will still be holding the column which had been deleted from the table and hence will give us an error that the required column does not exists.&lt;br /&gt;
&lt;br /&gt;
Lets demonstrate the above concept with a simple example - &lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
First we will create a simple table &lt;strong&gt;&lt;em&gt;Employee&lt;/em&gt;&lt;/strong&gt; as defined -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;create table Employee&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;(&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; EmpId int,&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; EmpName varchar(100),&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Age int&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;)&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;go&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
Now we will create a simple view &lt;strong&gt;&lt;em&gt;V&lt;/em&gt;&lt;/strong&gt; on this table as follows -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;create view V as select * from Employee&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;go&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
After creating this view we will try querying the syscomments system table to find out views definition as stored by Sybase ASE server and the query is -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;select * from syscomments where id = (select id from sysobjects where name = &#39;V&#39;)&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;go&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
On executing this query we&amp;nbsp;find that the Sybase ASE server has expanded the &lt;strong&gt;&lt;em&gt;&#39;*&#39;&lt;/em&gt;&lt;/strong&gt;&amp;nbsp;used in the view to the following -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;create view V as select Employee.EmpId, Employee.EmpName, Employee.Age from Employee&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;go&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
As we can see the Sybase ASE server has replaced &lt;strong&gt;&lt;em&gt;&#39;*&#39;&lt;/em&gt;&lt;/strong&gt; and expanded it with column names. Now when we fire an Alter Table command to add or remove a column like -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;alter table Employee&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;drop Age&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;go&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;OR&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;alter table employee&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;add Salary float NULL&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;go&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
then the alter table command does not rechecks that a view is already created on the table Employee and therefore the view is not corrected with the new or deleted column and hence when we try to execute the command -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;select * from V&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;go&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
after dropping the Age column from the table Employee then as the Sybase ASE server tries to locate the Age column in the table Employee but is not able to find the same hence the Sybase ASE server tries to throw the error -&lt;br /&gt;
&lt;br /&gt;
&lt;span lang=&quot;EN-GB&quot;&gt;&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;color: red;&quot;&gt;Invalid column name &#39;Age&#39;.&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span lang=&quot;EN-GB&quot;&gt;which confirms that the view does not gets updated with the Alter Table command.&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sybase-ase.blogspot.com/feeds/768568125521840209/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sybase-ase.blogspot.com/2011/08/will-addition-or-removal-of-columns-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/768568125521840209'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/768568125521840209'/><link rel='alternate' type='text/html' href='http://sybase-ase.blogspot.com/2011/08/will-addition-or-removal-of-columns-in.html' title='Will addition or removal of columns in a table effect the view created on the same table in Sybase ASE?'/><author><name>Neo</name><uri>http://www.blogger.com/profile/14411612301710790630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih5eFHd3lIHV1CYT5PPrEZgjHIVHUiD-8tfIbAefa1dzIsRz12qFqKxr9c1fc05q0yROrcIR_RpspnqUF24fTuEnwtjXlS5DUglz95eE9W6iitEczavDBjAKf6TK6mfj8/s220/23022008758.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-963036445075953465.post-2162418643298503924</id><published>2011-08-27T14:09:00.000-07:00</published><updated>2011-08-27T14:09:49.078-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sybase ASE"/><title type='text'>How to create a temporary table with variable name in Sybase ASE?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;If someone asks you if we can create a table with variable name or with a runtime generated name, then what would be your answer?&lt;br /&gt;
&lt;br /&gt;
Ofcourse as you are reading this article so the answer should be - &lt;strong&gt;&quot;Yes ofcourse&quot;&lt;/strong&gt;. The rest of the article will tell you how to do the same. First let me tell you that ofcourse this approach has a short coming of its own but its fun to learn how we will achieve this thing and the shortcoming is that in case we run same script or stored procedure from two different sessions at nearly the same time then one of the session might get error that the table already exists in the system catalogue. Okay, so lets get back to the approach and you will yourself be able to understand the short coming that I have listed here.&lt;br /&gt;
&lt;br /&gt;
So, coming back to work, the situation with us is as follows -&lt;br /&gt;
&lt;br /&gt;
Situation - We want to create a table which will created and dropped on each session but we do not want to use the session temp table.&lt;br /&gt;
&lt;br /&gt;
With the above problem statement we are sure about one thing and that is - We need to create table uniquely. &lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;So what to do in this case as the table will be generated at runtime and we will have no control over the name. Well, we need to think about some unique value which will be unique atleast for a specific session. So what could that be? Well, as we are everytime talking about session session and only session here so what could be better than a session id... Yes, right on track.. So we will use the session id for our job and use the Sybase ASE global variable @@spid to serve our purpose.&lt;br /&gt;
&lt;br /&gt;
Now as we have got&amp;nbsp;the unique id to help us create unique table names so we will write the following sp to serve our purpose -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;create procedure MyProc1&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;as&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;begin&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;declare&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp;&amp;nbsp; @MyTabName varchar(100)&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;create table MyTab&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;(&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Id int,&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FirstName varchar(100),&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; LastName varchar(100)&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;)&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;select @MyTabName = &#39;MyTab&#39; + convert(varchar, @@spid)&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;sp_rename MyTab, @MyTabName&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;print &#39;Renamed the table MyTab to a unique table name&#39;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;select * from sysobjects where name like @MyTabName&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;end&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;go&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
And thats it... As we can see in the above stored procedure we have been able to create a unique table in Sybase ASE without using session temp table or without using dynamic sql. As you can see here that the only place we find a problem with the above stored procedure is when we create the table &lt;strong&gt;&lt;em&gt;MyTab&lt;/em&gt;&lt;/strong&gt; and rename it to the new table name. The problem here is that as the two statements are not in the transaction so there might be a case that in case of parallel execution of the same stored procedure we get the error that the table name already exists in the system catalogue. But this can be avoided if we use &lt;strong&gt;&lt;em&gt;&#39;ddl in trans&#39;&lt;/em&gt;&lt;/strong&gt; db option for our Sybase ASE configuration.&lt;br /&gt;
&lt;br /&gt;
Well thats all for now.... will be back with more fun sometime later.. Have fun till then....&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sybase-ase.blogspot.com/feeds/2162418643298503924/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sybase-ase.blogspot.com/2011/08/how-to-create-temporary-table-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/2162418643298503924'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/2162418643298503924'/><link rel='alternate' type='text/html' href='http://sybase-ase.blogspot.com/2011/08/how-to-create-temporary-table-with.html' title='How to create a temporary table with variable name in Sybase ASE?'/><author><name>Neo</name><uri>http://www.blogger.com/profile/14411612301710790630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih5eFHd3lIHV1CYT5PPrEZgjHIVHUiD-8tfIbAefa1dzIsRz12qFqKxr9c1fc05q0yROrcIR_RpspnqUF24fTuEnwtjXlS5DUglz95eE9W6iitEczavDBjAKf6TK6mfj8/s220/23022008758.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-963036445075953465.post-4951188671929709995</id><published>2011-08-27T13:44:00.000-07:00</published><updated>2011-08-27T13:44:11.144-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sybase ASE"/><title type='text'>Using waitfor time command in Sybase ASE or How to run a stored procedures from different sessions simultaneously at the same time in Sybase ASE?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Sometimes while working with stored procedures it becomes important for us to test some scenario&#39;s where the same stored procedure needs to be run from two different sessions at the same time. But what to do in this case? We wont be able to open two different sessions and manually run the same stored procedure at the same time. So what to do in this case?&lt;br /&gt;
&lt;br /&gt;
Well, nothing to fear in this scenario as Sybase already provides a command to enable a wait or make the session sleep for sometime. The waiting command is very simple and can be used in two versions - &lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;1. waitfor time &amp;lt;&amp;lt;At what time should session run&amp;gt;&amp;gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;2. waitfor delay &amp;lt;&amp;lt;Till what time should the session wait&amp;gt;&amp;gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
As we can see the waitfor time command when encountered in the process flow the session is halted until the given time is reached. Example, Lets say we run a script like this at &lt;strong&gt;&lt;em&gt;&#39;10:20 am&#39;&lt;/em&gt;&lt;/strong&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;use MyDb&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;go&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;select * from MyTab&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;waitfor time &#39;10:25&#39;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;update MyTab set Id = 10 where Id = 5&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;select * from MyTab&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;go&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
Now when we ran the script at &lt;strong&gt;&lt;em&gt;&#39;10:20 am&#39;&lt;/em&gt;&lt;/strong&gt;&amp;nbsp;then the script runs through all the parts of the script until it reaches the command -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;waitfor time &#39;10:25&#39;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
When the control reaches this statement the session is put on hold till system time is equal to &lt;strong&gt;&lt;em&gt;&#39;10:25 am&#39;&lt;/em&gt;&lt;/strong&gt; and the rest of the session executes exactly (with minor delay) at the given time. So, if we open two sessions at the same time and write &lt;strong&gt;&lt;em&gt;waitfor time&lt;/em&gt;&lt;/strong&gt; as the first line of the script then we will be able to run same stored procedure from two sessions at the same time.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sybase-ase.blogspot.com/feeds/4951188671929709995/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sybase-ase.blogspot.com/2011/08/using-waitfor-time-command-in-sybase.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/4951188671929709995'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/4951188671929709995'/><link rel='alternate' type='text/html' href='http://sybase-ase.blogspot.com/2011/08/using-waitfor-time-command-in-sybase.html' title='Using waitfor time command in Sybase ASE or How to run a stored procedures from different sessions simultaneously at the same time in Sybase ASE?'/><author><name>Neo</name><uri>http://www.blogger.com/profile/14411612301710790630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih5eFHd3lIHV1CYT5PPrEZgjHIVHUiD-8tfIbAefa1dzIsRz12qFqKxr9c1fc05q0yROrcIR_RpspnqUF24fTuEnwtjXlS5DUglz95eE9W6iitEczavDBjAKf6TK6mfj8/s220/23022008758.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-963036445075953465.post-2428569631219544657</id><published>2011-08-08T12:53:00.000-07:00</published><updated>2011-08-08T12:53:09.154-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sybase ASE"/><title type='text'>Create table within if exists block in Sybase ASE?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;So, how is it that you try to check the existance of a sybase table. Well the answer is pretty simple. Fire the following query and you are right into what you want -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;if exists(select 1 from sysobjects where name = &amp;lt;&amp;lt;Table Name&amp;gt;&amp;gt; and type = &#39;U&#39;)&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;begin&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; &amp;lt;&amp;lt;SQL statements&amp;gt;&amp;gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;end&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;go&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
Okay, so we know how to check the existance of a table, but what if we say that we want to check if a table exists in system catalogue or not and if not then create the table. What to do in this case? Well the obvious syntax that comes o our mind as first thought is as follows -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;if not exists(select 1 from sysobjects where name = &#39;MyTab&#39; and type = &#39;U&#39;)&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;begin&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; create table MyTab&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; (&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Id int,&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Name varchar(100),&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Age int&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; )&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;end&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;else&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;begin&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; print &#39;Table already exists&#39;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;end&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;go&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
Well, is it correct? I dont think so. Why? Because if in case MyTab table was already existing in the sysobjects table and we run this query then we will get the error that table MyTab already exists in the system catalogue. So what is wrong with the statement?&lt;br /&gt;
&lt;br /&gt;
To understand this we need to look deeper into how Adaptive Server Enterprise tries to execute the above query. Well in above case when we fire the if exists clause and define the create table syntax after it, the server first tries to check the presence of the MyTab table in the system catalogue and once it is found the server further finds that the next statement tries to create a table with a name that is already present in the system catalogue and hence throws the error.&lt;br /&gt;
&lt;br /&gt;
In case if we would have defined a drop table command within the if exists block then the command would have run successfully as in that case the server checks if the required table is already in the system catalogue and if so tries to drop it which is prefectly valid. The drop command is as follows -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;if exists(select&amp;nbsp;1 from sysobjects where name = &#39;MyTab&#39; and type = &#39;U&#39;)&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;begin&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; drop table MyTab&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;end&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;else&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;begin&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; print &#39;MyTab does not exists.&#39;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;end&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;go&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
So, coming back to the question - &lt;strong&gt;&lt;em&gt;What to do in case we require to create table within the if exists block in Sybase ASE?&lt;/em&gt;&lt;/strong&gt; &lt;strong&gt;&lt;em&gt;Is there any way by which we can achieve this?&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
Well the answer is - Yes, ofcourse. How? Lets figure it out...&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
As we can see in the above example we encountered the error only while creating the table because the server first checked the existance of the table in sysobjects table before creating the same and evaluating the condition, so we need to trick our server to deffer this check to runtime and so we will use the execute immediate or exec command to execute the create table statement as a dynamic sql. So, now with dynamic sql to our rescue we can place the create table syntax in a string and execute the statement within the if exists block which will trick the server to evaluate the exec statement only at the runtime and not at the compile time and hence avoiding the error. The syntax with dynamic sql is as follows -&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;if not exists(select 1 from sysobjects where name = &#39;MyTab&#39; and type = &#39;U&#39;)&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;begin&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; exec(&#39;create table MyTab (Id int, Name varchar(100), Age int)&#39;)&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;end&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;else&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;begin&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&amp;nbsp; print &#39;MyTab table already exists in the system catalogue&#39;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;end&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;go&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
Simple... Isn&#39;t it?&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sybase-ase.blogspot.com/feeds/2428569631219544657/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sybase-ase.blogspot.com/2011/08/create-table-within-if-exists-block-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/2428569631219544657'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/963036445075953465/posts/default/2428569631219544657'/><link rel='alternate' type='text/html' href='http://sybase-ase.blogspot.com/2011/08/create-table-within-if-exists-block-in.html' title='Create table within if exists block in Sybase ASE?'/><author><name>Neo</name><uri>http://www.blogger.com/profile/14411612301710790630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih5eFHd3lIHV1CYT5PPrEZgjHIVHUiD-8tfIbAefa1dzIsRz12qFqKxr9c1fc05q0yROrcIR_RpspnqUF24fTuEnwtjXlS5DUglz95eE9W6iitEczavDBjAKf6TK6mfj8/s220/23022008758.jpg'/></author><thr:total>0</thr:total></entry></feed>