Search code examples
temp-tablessap-ase

Sybase Dropping Temporary Table


Does anybody face an issue when you drop a temporary table at the Sybase ASE 12 it still persists at a current session. So you encounter "Table already exists" when trying to select data into it again


Solution

  • Well, you need to read the manuals, at least the syntax for the commands you expect to use, before you write code. Otherwise you will face issues at every turn. It depends on what you are trying to do.

    1. SELECT ... INTO #MyTable creates a table and succeeds because it does not exist. So a second SELECT ... INTO #MyTable will try to create #MyTable, find that it exists, and fail.

    2. If you want to perform a second SELECT into the same table, TRUNCATE the table, then use SELECT ... INTO EXISTING TABLE #MyTable.

    3. Or DROP TABLE and skip the EXISTING TABLE modifier.

    4. If you want the table to contain the sum of several SELECTS, obviously, skip the TRUNCATE.