Sybase 删除临时表
当您在 Sybase ASE 12 中删除临时表时,有人会遇到问题吗?它仍然保留在当前会话中。因此,当尝试再次将数据选择到其中时,您会遇到“表已存在”
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,在编写代码之前,您需要阅读手册,至少阅读您期望使用的命令的语法。否则你每次都会遇到问题。这取决于您想要做什么。
SELECT ... INTO #MyTable
创建一个表并成功,因为它不存在。因此,第二个SELECT ... INTO #MyTable
将尝试创建#MyTable
,发现它存在,然后失败。如果您想对同一个表执行第二次
SELECT
,请TRUNCATE
该表,然后使用SELECT ... INTO EXISTING TABLE #MyTable。
或者
DROP TABLE
并跳过EXISTING TABLE
修饰符。如果您希望表包含多个
SELECTS
的总和,显然,请跳过TRUNCATE
。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.
SELECT ... INTO #MyTable
creates a table and succeeds because it does not exist. So a secondSELECT ... INTO #MyTable
will try to create#MyTable
, find that it exists, and fail.If you want to perform a second
SELECT
into the same table,TRUNCATE
the table, then useSELECT ... INTO EXISTING TABLE #MyTable
.Or
DROP TABLE
and skip theEXISTING TABLE
modifier.If you want the table to contain the sum of several
SELECTS
, obviously, skip theTRUNCATE
.我通常这样做:
1)创建表#temptable(
....
)
插入 #temptable
SELECT .....
这永远不会出错。
这解决了另一个可能的错误。如果“select INTO”附带的 WHERE 子句没有生成任何行,则临时表不会有零行,但根本不会创建临时表。这可能会使存储过程稍后崩溃。
I normally do this:
1) CREATE TABLE #temptable (
....
)
INSERT INTO #temptable
SELECT .....
This will never give error.
This solves another possible error . If the WHERE clause accompanying the "select INTO " yields no rows, the temporary table will not have zero rows but the temporary table won't be created at all. This could make the stored proc blow up later.