SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


What is # in first letter of table names?


What is # in first letter of table names?

Author
Message
masoudk1990
masoudk1990
SSC Veteran
SSC Veteran (234 reputation)SSC Veteran (234 reputation)SSC Veteran (234 reputation)SSC Veteran (234 reputation)SSC Veteran (234 reputation)SSC Veteran (234 reputation)SSC Veteran (234 reputation)SSC Veteran (234 reputation)

Group: General Forum Members
Points: 234 Visits: 299
Ive noticed dudes in this forum uses # for the first letter of their table names.
Does it have any special meaning?
Does SQL Server have different behavior with them?
Or its just a letter like a,b,c... etc?

___________________________________
Computer Enterprise Masoud Keshavarz
I don't care about hell.
If I go there I've played enough Diablo to know how to fight my way out.
Koen Verbeeck
Koen Verbeeck
SSC Guru
SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)

Group: General Forum Members
Points: 62131 Visits: 13297
These are temporary tables.
Basically it means they are stored in tempdb (one of the system databases) and are dropped when the connection is terminated or when SQL Server is restarted.

They behave like any other table, so you can create them with CREATE TABLE #myTempTable or with SELECT ... INTO #myTempTable.
You can use ALTER TABLE and add indexes if you want.


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
Lowell
Lowell
SSC Guru
SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)

Group: General Forum Members
Points: 71280 Visits: 40930
masoudk1990 (7/5/2013)
Ive noticed dudes in this forum uses # for the first letter of their table names.
Does it have any special meaning?
Does SQL Server have different behavior with them?
Or its just a letter like a,b,c... etc?


#table is a temporary table...it's one that you can create on the fly, and it gets destroyed automatically when your connection is closed.


SELECT name
INTO #temp
from sys.tables




they are real tables, and are unique to the processes/scope that created them...so a procedure which creates a temp table can be called thousands of times per second, and each instance of the procedure creates it's own temp table, called #temp or whatever, but that do not collide with any other process creating temp tables by the same name.

technically, a table gets created with a unique name in tempdb, and it might actually be called the same name, but with a unique number appended to the end of it;
see for yourself:

select POWER(convert(bigint,2),31) as val into #temp

select name from tempdb.sys.tables where name LIKE '#temp%'
--#temp__{snip}__000000000006



Lowell
--help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
HanShi
HanShi
SSCrazy Eights
SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)

Group: General Forum Members
Points: 8574 Visits: 3718
When you put a # sign in front of the table name, the table will be created in [tempdb] database. This table will be only available within your current session and is called a local temporary table. When your session is ended, the temporary table will be automaticly removed.
If you put a double # sign in front of the table name, the table will also be created in [tempdb] database and is called a global temporary table. This table will be available from within other sessions.

From MSDN:
Temporary Tables
--------------------------------------------------------------------------------
There are two types of temporary tables: local and global. Local temporary tables are visible only to their creators during the same connection to an instance of SQL Server as when the tables were first created or referenced. Local temporary tables are deleted after the user disconnects from the instance of SQL Server. Global temporary tables are visible to any user and any connection after they are created, and are deleted when all users that are referencing the table disconnect from the instance of SQL Server.

** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
Koen Verbeeck
Koen Verbeeck
SSC Guru
SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)

Group: General Forum Members
Points: 62131 Visits: 13297
select POWER(convert(bigint,2),31)  as val into #temp



I see what you did there ;-)
Recycling is good for the environment :-D


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
Lowell
Lowell
SSC Guru
SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)

Group: General Forum Members
Points: 71280 Visits: 40930
Koen Verbeeck (7/5/2013)
select POWER(convert(bigint,2),31)  as val into #temp



I see what you did there ;-)
Recycling is good for the environment :-D


haha! cannot put anything past you! at least i didn't plagiarize!

Lowell
--help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
masoudk1990
masoudk1990
SSC Veteran
SSC Veteran (234 reputation)SSC Veteran (234 reputation)SSC Veteran (234 reputation)SSC Veteran (234 reputation)SSC Veteran (234 reputation)SSC Veteran (234 reputation)SSC Veteran (234 reputation)SSC Veteran (234 reputation)

Group: General Forum Members
Points: 234 Visits: 299
Thank you every one.


@HanShi
If you put a double # sign in front of the table name, the table will also be created in [tempdb] database and is called a global temporary table. This table will be available from within other sessions


Thank you for extra information.

@Koen Verbeeck

I see what you did there [Wink]
Recycling is good for the environment [BigGrin]


What did Lowell do?
You made me afraid to test his query.

___________________________________
Computer Enterprise Masoud Keshavarz
I don't care about hell.
If I go there I've played enough Diablo to know how to fight my way out.
Lowell
Lowell
SSC Guru
SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)

Group: General Forum Members
Points: 71280 Visits: 40930

select POWER(convert(bigint,2),31) as val into #temp



he was referencing another thread, where someone asked for the max size of a varchar(max);
that thread is here:
http://www.sqlservercentral.com/Forums/Topic1470699-391-1.aspx

i reused my same code example from that thread, but inserted it into a #temp table to show you how to use a temp table;

he was referring to the fact that he noticed the same code in the other thread.

it was just a for-fun notification that he sees everything.

Lowell
--help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
Koen Verbeeck
Koen Verbeeck
SSC Guru
SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)

Group: General Forum Members
Points: 62131 Visits: 13297
Lowell (7/5/2013)

it was just a for-fun notification that he sees everything.


That's true. So you better watch out!

(maybe I'll add an off-topic warning next time, to not confuse anyone else)


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
Alan.B
Alan.B
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13320 Visits: 8001
HanShi mentioned local and global temp tables. You don't see this as often but a global temp table has two numbers signs in front of it like so: ##temptable.

To get some understanding about the difference between the two, open a new query window in SSMS and run these SELECT statements:


CREATE TABLE #LocalTempTable (xId int); --(1) Local Temp Table
CREATE TABLE ##GlobalTempTable (xId int); --(2) Global Temp Table

INSERT INTO #LocalTempTable VALUES(1);
INSERT INTO ##GlobalTempTable VALUES(1);



Then, in the same query window, you could successfully run these queries:


SELECT * FROM ##GlobalTempTable
SELECT * FROM #LocalTempTable



If you open a new query window, however, and run the two SELECT statements above, the first will be successful but the second one will fail.

-- Alan Burstein



Best practices for getting help on SQLServerCentral
Need to split a string? Try DelimitedSplit8K or DelimitedSplit8K_LEAD (SQL 2012+)
Need a pattern-based splitter? Try PatternSplitCM
Need to remove or replace those unwanted characters? Try PatExclude8K and PatReplace8K.

"I can't stress enough the importance of switching from a 'sequential files' mindset to 'set-based' thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code. " -- Itzek Ben-Gan 2001
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search