Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 why we place "@" in queries and y no physical tabl

Author  Topic 

learning_grsql
Posting Yak Master

230 Posts

Posted - 2012-06-25 : 13:58:22
I just started learning sql.


I see "@" in many examples from different websites including in my previous posts. I wonder why we place "@" in queries.

example - example :
DECLARE @T TABLE (ColA INT, ColB INT)...........................


I read in different sources that we place "@" for something called parameter.

I don't want to go deep into it for now but I would like to know why we use that in queries which start with "Declare".

And when we create table starting with Declare statement. Will it create physical table?

I pasted codes from my previous post, but I don't see any physical table but only output (sql server 2005).

my previous post link : http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=176067

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-06-25 : 14:06:08
Yes it's for parameters or also called variables. Your example is a table variable. No it's not a physical table, think of it as an in-memory only table. Once the session goes away, the table variable goes away too.


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

xhostx
Constraint Violating Yak Guru

277 Posts

Posted - 2012-06-25 : 14:10:57
Hi,

Whenever you see '@' think of having a VARIABLE which can be any type; INT, CHAR,VARCHAR, TABLE...etc.

declared variable of type table will be only valid inside and temporary in your program. IT IS NOT A PHYSICAL or TEMPORARY TABLE. (temp tables are found under tempdb databases under SQL Server).

overall they can only be used temporary during the run time of your script.

Luck,

kml
Go to Top of Page

learning_grsql
Posting Yak Master

230 Posts

Posted - 2012-06-30 : 05:28:34
Thank you
quote:
IT IS NOT A PHYSICAL or TEMPORARY TABLE. (temp tables are found under tempdb databases under SQL Server).


Do you mean it is not a temporary table? I thought if it's not a physical table, it should be a temporary table.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-06-30 : 16:59:44
quote:
Originally posted by learning_grsql

Thank you
quote:
IT IS NOT A PHYSICAL or TEMPORARY TABLE. (temp tables are found under tempdb databases under SQL Server).


Do you mean it is not a temporary table? I thought if it's not a physical table, it should be a temporary table.



It's just not termed a temporary table as those start with # instead of @. But it is indeed temporary in that it goes away when the session does.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -