November 13, 2004 at 10:04 am
Hello everybody,
I'm having a strange situation with a query.
Can anyone explain this behaviour?
I have two tables : A and B
CREATE TABLE A (
col1 int IDENTITY (1, 1) NOT NULL ,
col2 char (10) NOT NULL
)
GO
CREATE TABLE B (
a char(10) NOT NULL ,
b int NOT NULL
)
GO
When I do the next query:
select A.col1, B.b
into AUX
from A, B
where A.col2 = B.a
The target table AUX doesn't have an identity column, as you see:
select objectproperty(object_id('AUX'),'TableHasIdentity')
--> 0
But if I do:
select A.col1, 111
into AUX2
from A
where A.col2 = 'Hola'
The target table has an identity, as you see below:
select objectproperty(object_id('AUX2'),'TableHasIdentity')
--> 1
I see that the diference is that there is a join in the from.
I want that my target table doesn't have and identity, but without doing the join. How can I do this???
Thanks in advance, and sorry for my english
November 13, 2004 at 6:00 pm
Since you've explicity created the target table, you should not be using "SELECT/INTO"... use INSERT INTO/SELECT instead.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 14, 2004 at 1:28 pm
Jeff, I might miss something, but I don't the table AUX explicitely created in Julia's script.
Anyway, I get an error when I try to run
select A.col1, 111
into AUX
from A
where A.col2 = 'Hola'
Server: Nachr.-Nr. 8155, Schweregrad 16, Status 1, Zeile 1
Keine Spalte wurde für die Spalte 2 von 'AUX' angegeben.
But like Jeff already said, I would first create the table and then do INSERT INTO, that way you also avoid problems with recompiles
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
November 14, 2004 at 6:51 pm
Yeah, you're right Frank... Not enough coffee
--Jeff Moden
Change is inevitable... Change for the better is not.
November 15, 2004 at 6:54 am
Hello again,
And thanks a lot, but I know that I can create the table first, and then do the 'select .. into' , but i wonder if it would have other solution.
Thanks!
November 15, 2004 at 7:09 am
Any specific reasons for it?
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
November 16, 2004 at 7:09 am
No, not an specific reason...
Only to know if it's possible.
I wanted to know why this behaviour, but now that I know that this is the way SQL Server do that kind of things, I will do the things in other way.
Thanks a lot to everyone!!!
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy