September 16, 2010 at 7:12 am
Hi,
I can't remember the exact syntax on creating a table that doesn't exists using SQL. Can someone help out.
SELECT firstname,lastname [NEWTABLENAME] FROM Employees
Not sure if that's the right syntax.
Thanks,
September 16, 2010 at 7:15 am
SELECT firstname,lastname into [NEWTABLENAME] FROM Employees
September 16, 2010 at 7:19 am
Joe Contreras-290946 (9/16/2010)
Hi,I can't remember the exact syntax on creating a table that doesn't exists using SQL. Can someone help out.
SELECT firstname,lastname [NEWTABLENAME] FROM Employees
Not sure if that's the right syntax.
Thanks,
BOL, the on-line manual installed with SQL Server, has some notes.
SELECT Examples (Transact-SQL)
D. Creating tables with SELECT INTO
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
September 16, 2010 at 7:58 am
Thank You All
September 17, 2010 at 3:00 am
Hi
Joe
If U find the things in Ur Pocket, why ask to another? First check Ur pocket (SQL BOL) please, the forum's expert not free for answer a silly question.
Ali
MCTS SQL Server2k8
September 17, 2010 at 4:35 am
Duly noted. I did my homework before posting and couldn't find it. There's alway one in the crowd.
September 18, 2010 at 4:36 pm
I have to admit that unless you know what you're looking for, this one is hard to find in BOL. GOOGLE? That might be a different story...
http://www.google.com/search?btnG=1&pws=0&q=how+to+create+a+table+using+select+%2B%22SQL+SERVER%22
--Jeff Moden
Change is inevitable... Change for the better is not.
September 18, 2010 at 5:04 pm
I Google first looking for
dynamically building tables in SQL
Create table based on SQL
SELECT Into
I couldn't remember the exact syntax and it was driving me nuts. It was one of those where did I leave my car keys situation.
I must admit it was a total brain fart.
Again Thank You all for helping an old man out.
September 18, 2010 at 5:42 pm
Joe Contreras-290946 (9/18/2010)
I Google first looking fordynamically building tables in SQL
Create table based on SQL
SELECT Into
I couldn't remember the exact syntax and it was driving me nuts. It was one of those where did I leave my car keys situation.
I must admit it was a total brain fart.
Again Thank You all for helping an old man out.
Heh... absolutely understood. Sometimes ya just don't know enough about what you're looking for to even Google it. Us old dude's have gotta stick together on stuff like this. The term "It Depends" has a whole lot different meaning for us. ๐
--Jeff Moden
Change is inevitable... Change for the better is not.
September 18, 2010 at 5:54 pm
Joe,
Here's a bit more information...
First, open up BOL in the INDEX mode and do a search for "SELECT clause" (without the quotes on any of these lookups), and then make sure you select "SELECT Clause (Transact-SQL)" from the index results tab at the bottom of the screen, you'll find a lot more about SELECT INTO. One of the more important aspects is the following right straight out of that entry...
[font="Arial Black"]Selecting Identity Columns[/font]
When an existing identity column is selected into a new table, the new column inherits the IDENTITY property, unless one of the following conditions is true:
The SELECT statement contains a join, GROUP BY clause, or aggregate function.
Multiple SELECT statements are joined by using UNION.
The identity column is listed more than one time in the select list.
The identity column is part of an expression.
If any one of these conditions is true, the column is created NOT NULL instead of inheriting the IDENTITY property. All rules and restrictions for the identity columns apply to the new table.
--Jeff Moden
Change is inevitable... Change for the better is not.
September 19, 2010 at 2:18 am
Ali Tailor (9/17/2010)
HiJoe
If U find the things in Ur Pocket, why ask to another? First check Ur pocket (SQL BOL) please, the forum's expert not free for answer a silly question.
I don't think it was such a silly question after all. I was asked the same question in an interview and I replied that I don't know the answer. Then the interviewer asked if i knew about SELECT * INTO Clause. I said YES. I do. But won't that copy the data as well. He asked Can't you write a WHERE Clause to filter the data?. I thought for a few seconds and again said YES. We can use WHERE 1 = 2 condition. The interviewer started smiling and he asked me not to get nervous.
If you want to see a silly question, have a look at the link below where the OP asked about the BIT datatype and see how the experts patiently answered the OP.
http://www.sqlservercentral.com/Forums/Topic984249-9-1.aspx
How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
September 20, 2010 at 12:08 am
Kingston Dhasian (9/19/2010)
Ali Tailor (9/17/2010)
HiJoe
If U find the things in Ur Pocket, why ask to another? First check Ur pocket (SQL BOL) please, the forum's expert not free for answer a silly question.
I don't think it was such a silly question after all. I was asked the same question in an interview and I replied that I don't know the answer. Then the interviewer asked if i knew about SELECT * INTO Clause. I said YES. I do. But won't that copy the data as well. He asked Can't you write a WHERE Clause to filter the data?. I thought for a few seconds and again said YES. We can use WHERE 1 = 2 condition. The interviewer started smiling and he asked me not to get nervous.
If you want to see a silly question, have a look at the link below where the OP asked about the BIT datatype and see how the experts patiently answered the OP.
Hi
Kingston Dhasian
It's was a try to just say , ....
Ali
MCTS SQL Server2k8
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply