Sql server 从“选择”菜单创建新表?

Sql server 从“选择”菜单创建新表?,sql-server,Sql Server,我正在尝试从select创建一个新表,但它不起作用。 这是我的语法 select * into newtable from oldtable where oldtable.number=2 然后,当我尝试使用它时 select * from newtable 它告诉我newtable是无效对象。您是否在正确的数据库中,而不是在主数据库中 试试这个: USE [your database name] GO SELECT * INTO newtable FROM oldtable WHERE

我正在尝试从select创建一个新表,但它不起作用。 这是我的语法

select *
into newtable
from oldtable
where oldtable.number=2
然后,当我尝试使用它时

select * from newtable

它告诉我newtable是无效对象。

您是否在正确的数据库中,而不是在主数据库中

试试这个:

USE [your database name]
GO

SELECT *
INTO newtable
FROM oldtable
WHERE [number] = 2
insert into newtable
select *
from oldtable
where oldtable.number=2
如果newtable有红色下划线,您仍然可以从中进行选择。下划线只是表示表名未缓存。按CTRL+SHIFT+R可以重建IntelliSense,下划线将消失

希望这有帮助。

试试这个:

USE [your database name]
GO

SELECT *
INTO newtable
FROM oldtable
WHERE [number] = 2
insert into newtable
select *
from oldtable
where oldtable.number=2

你是不是在这批货中的某个地方放错了?请参见此处,它应按原样工作:。你真的运行过吗?我看不出这段代码有什么问题,只是你需要在再次运行之前删除
newTable
,不要在任何地方设置FMTONLY。我给你的就是我在代码中的全部内容。你能在你的SQL服务器上运行@RichardTheKiwi提供的SQL吗?我不相信你的表被命名为newtable,oldtable。您是否100%确定没有在两段代码之间更改“newtable”的名称?