Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 下降温度表问题_Sql Server_Tsql - Fatal编程技术网

Sql server 下降温度表问题

Sql server 下降温度表问题,sql-server,tsql,Sql Server,Tsql,我在放置临时表时遇到问题。如果在查询下运行1次,则显示错误 数据库中已存在名为“#a”的对象 请在1次内运行查询 if(OBJECT_ID('tempdb..#a','U')Is not null) Begin drop table #a End Create table #a ( id int ) insert into #a select 1 select * from #a if(OBJECT_ID('tempdb..#a','U')Is not null) Begin drop

我在放置临时表时遇到问题。如果在查询下运行1次,则显示错误

数据库中已存在名为“#a”的对象

请在1次内运行查询

if(OBJECT_ID('tempdb..#a','U')Is not null)
Begin
drop table #a
End

Create table #a
(
id int
)

insert into #a
select 1

select * from #a


if(OBJECT_ID('tempdb..#a','U')Is not null)
Begin
drop table #A
End

Create table #a
(
id int
,name varchar(10)
)

insert into #a
select 2,'name'

select * from #A

试试这个:您必须使用
GO
进行批处理并分别执行,因为您要再次创建同一个临时表,并且它会立即执行:

if(OBJECT_ID('tempdb..#a','U')Is not null)
Begin
    drop table #a
End
GO
Create table #a (id int)

insert into #a
select 1

select * from #a

if(OBJECT_ID('tempdb..#a','U')Is not null)
Begin
    drop table #a
End
GO
Create table #a(id int,name varchar(10))
insert into #a
select 2,'name'

select * from #a

注意:请尝试对表名使用类似的
大小写

如果您错过了“GO”语句

如果中间没有“GO”,整个过程将被视为一个脚本,当select语句查找该列时,将找不到它

使用“go”,它将脚本的一部分视为“一行”,并在“go”进入查询之前执行。

if(OBJECT_ID('tempdb..#a','U')Is not null)
Begin
drop table #a
End
go
Create table #a
(
 id int
 )

insert into #a
select 1

select * from #a


if(OBJECT_ID('tempdb..#a','U')Is not null)
Begin
drop table #a
End

go

Create table #a
(
 id int
 ,name varchar(10)
)

insert into #a
select 2,'name'

select * from #a

如果有用,请将其标记为答案。

这是什么?SQL Server?你可能在第二个
之前错过了一个
GO
,如果
@PawełTajs,那么给重复的答案添加一个?@PawełTajs“协会奖金”也许?我可以看到页面末尾的“你的答案”框。似乎是MSO的问题。
GO
分离批次,而不是事务。更正,谢谢伙计。非常感谢您的快速回复。