February 7, 2009 at 11:24 am
Comments posted to this topic are about the item TSQL
[font="Courier New"]Sankar Reddy | http://SankarReddy.com/[/url][/font]
February 7, 2009 at 11:26 am
I've been using INSERT INTO for so long that I forgot INTO was optional. Who knew?
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
February 9, 2009 at 1:01 am
Iggy (2/8/2009)
Whilst I totally understand it's a valid identifier, I just want to understand, does that query create a table with the name "#", or does it create a temporary table with no name?
Create a temporary table with name #.
February 9, 2009 at 4:31 am
It's a cool bit of trivia that it works, but not good programming practice- better to name the table something meaningful!
Reminds me of some code I inherited code that used a b and c etc as variable names.... tough to maintain and bad programming practice...
February 9, 2009 at 7:07 am
Of course, if you want to be really silly you can docreate table # (_ int)
go
insert # select 1
go
select * from #
Derek
February 9, 2009 at 8:19 am
Derek Dongray (2/9/2009)
Of course, if you want to be really silly you can docreate table # (_ int)
go
insert # select 1
go
select * from #
I'll use that next time I need to interview someone :w00t:
February 9, 2009 at 8:23 am
It's definitely a trivia question and I wouldn't recommend coding like this as all, unless you're in some type of contest for obfuscating code.
I also wouldn't let someone use this as an identifier, but it's good to know this is an issue.
February 9, 2009 at 9:45 am
and yet another "but why" ...
create table
([int] int)
go
insert
select 1
go
select [int] from
go
RegardsRudy KomacsarSenior Database Administrator"Ave Caesar! - Morituri te salutamus."
February 9, 2009 at 9:58 am
So it adds a temp table into memory or on the permamnent media or both? How long does the temp table last?
There have been times when I want to use a temp table to hold some data for the length of a webpage, but I generally have a table called tempSomethingMeaningful and clear the table when I am done. This way I don't have to worry about setting up the columns every time.
February 9, 2009 at 10:22 am
A valid identifier is the #
Thanks for the info Yoda... er... Sankar. Something new I learned.:)
February 10, 2009 at 3:31 am
james (2/9/2009)
So it adds a temp table into memory or on the permamnent media or both? How long does the temp table last?There have been times when I want to use a temp table to hold some data for the length of a webpage, but I generally have a table called tempSomethingMeaningful and clear the table when I am done. This way I don't have to worry about setting up the columns every time.
Temporary tables last as long as the connection that created them. They may be in memory or stored in the database tempdb. See http://msdn.microsoft.com/en-us/library/aa933114(SQL.80).aspx.
Using temp tables from web pages will depend on how much control you have over the connection. I beleive that a connection is automatically closed at the end of each page rendition (haven't checked) so if you need data to persist from one page to another you need to use permanent tables. Temp tables are mainly used for intermediate results, usually for perfromance reasons; i.e. select some data to a temp table, then do further transformations on the subset of data in the temp table.
Derek
February 10, 2009 at 11:53 am
This is written as a trivia question and to raise awareness that certain questionable features will not be supported in future versions of SQL Server. Follow the link to learn about functionalities that might be going away in near future.
Features Not Supported in a Future Version of SQL Server
I do NOT recommend using this method and once again it is written to raise awareness.
[font="Courier New"]Sankar Reddy | http://SankarReddy.com/[/url][/font]
February 11, 2009 at 4:50 am
Sankar Reddy (2/10/2009)
This is written as a trivia question and to raise awareness that certain questionable features will not be supported in future versions of SQL Server. Follow the link to learn about functionalities that might be going away in near future.Features Not Supported in a Future Version of SQL Server
I do NOT recommend using this method and once again it is written to raise awareness.
But, for now, this is legal T-SQL! 🙂
declare @ int, @@ int create table
# (_ int, _@ int, _@@ int) insert
# values(1,1 - + + - -
- - + - 1, 1 - + - + - +
- - + - + - 1) select @=_,@@=_@ from
# select * into
## from
# drop table
# drop table
##
Derek
Viewing 14 posts - 1 through 13 (of 13 total)
You must be logged in to reply to this topic. Login to reply