gpt4 book ai didi

sql - sql server 中的临时表

转载 作者:行者123 更新时间:2023-12-02 10:00:22 26 4
gpt4 key购买 nike

我正在努力在 SQL Server 中创建临时表。我成功创建了临时表,但是当我尝试查看数据时,它显示无效的对象名称。谁能告诉敌人临时表存在多长时间?如果我以 userid - devloper 和 pwd = 0999 身份登录到 sql server,并且其他人也使用相同的凭据登录到 sql server,这个临时表将被删除吗?我的sql如下:

SELECT net_node_model.SYS_ID, net_node_model.NODE, mst_temp_equation.TEMP_ID,
mst_temp_equation.EQ_ID
INTO ##NT_MASTER_TEMP_EQUATION
FROM mst_temp_equation INNER JOIN
net_node_model ON mst_temp_equation.TEMP_ID = net_node_model.TEMP_ID
GROUP BY net_node_model.SYS_ID, net_node_model.NODE, mst_temp_equation.TEMP_ID,
mst_temp_equation.EQ_ID, mst_temp_equation.EQ_NAME,
mst_temp_equation.EQ_TYPE, mst_temp_equation.[OBJECT],
mst_temp_equation.VAR_TYPE, mst_temp_equation.VAR_NAME,
mst_temp_equation.VAR_SUBSET, mst_temp_equation.VAR_SET,
mst_temp_equation.RHS_RELN, mst_temp_equation.RHS_OBJECT,
mst_temp_equation.RHS_VAR_SET, mst_temp_equation.RHS_VAR_SUBSET,
mst_temp_equation.RHS_VAR_TYPE, mst_temp_equation.RHS_VAR_NAME,
mst_temp_equation.EQ_TP_OFFSET, mst_temp_equation.RHS_TP_OFFSET,
mst_temp_equation.RETAIN, mst_temp_equation.TIME_PRD,
mst_temp_equation.EQ_VAR_SUBTYPE, mst_temp_equation.RHS_VAR_SUBTYE;

最佳答案

如果您使用的是常规临时表#table,则除了创建它的 session 之外,任何其他 session 都看不到它。该 session 结束后,该表将被删除。

如果您使用全局临时表##table,它将对其他 session 可见。

来自 MSDN - CREATE TABLE ,在临时表下:

Global temporary tables are automatically dropped when the session that created the table ends and all other tasks have stopped referencing them.

关于sql - sql server 中的临时表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7258651/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com