August 27, 2013 at 12:28 pm
This short piece of SQL gives "Invalid object name 'test2'. I can create table test but creating table test2 fails. What am I doing wrong? Thanks as always.
use dz
go
create table test (ColumnA int)
insert into test values (1)
select * from test
go
insert into test2 select * from test
go
August 27, 2013 at 12:30 pm
You insert into Test2, but you never create it, hence the table does not exist.
Add a CREATE TABLE statement for Test2
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
August 27, 2013 at 12:38 pm
Geez, I should have known that!
It's the difference between
select * into test2 from test -- inserts into a new table
insert into test2 select * from test -- inserts into an existing table
Thanks GilaMonster.
August 28, 2013 at 7:41 am
aiki4ever-796329 (8/27/2013)
Geez, I should have known that!It's the difference between
select * into test2 from test -- inserts into a new table
insert into test2 select * from test -- inserts into an existing table
Thanks GilaMonster.
yes, when you write statment -
SELECT * INTO Test2 FROM test
It will create the table.
WHile, when you write INSERT INTO Test2 SELECT * FROM test
It will insert the data into test2 if test2 is already created
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply