2010-04-30 11 views
5

मुझे संदेह है कि अस्थायी तालिका का उपयोग क्यों करना चाहिए अस्थायी तालिका में कोई विशेष चीज़ है और हमें अस्थायी तालिकाओं का उपयोग कहां करना चाहिए। क्या आप कृपया मुझे बता सकते हैं या कोई संदर्भ आपको धन्यवाद।एसक्यूएल सर्वर में अस्थायी टेबल?

उत्तर

4

अस्थायी तालिकाओं के लिए कई उपयोग हैं। वे जटिल प्रश्नों में डेटा को संभालने में बहुत उपयोगी हो सकते हैं। आपका प्रश्न अस्पष्ट है, और वास्तव में इसका कोई जवाब नहीं है, लेकिन मैं कुछ अस्थायी तालिका दस्तावेज से जुड़ रहा हूं।

उनके पास बाधाओं और अनुक्रमण सहित तालिका की समान क्षमताएं हैं। वे वैश्विक या मौजूदा दायरे तक ही सीमित हो सकते हैं। वे भी अक्षम हो सकते हैं, इसलिए हमेशा के रूप में सतर्क रहें।

http://www.sqlservercentral.com/articles/T-SQL/temptablesinsqlserver/1279/
http://msdn.microsoft.com/en-us/library/aa258255%28SQL.80%29.aspx

11

जब T-SQL कोड लिखने, आप अक्सर जिसमें अस्थायी रूप से जब यह है कि कोड को निष्पादित करने के समय आता है डेटा स्टोर करने के लिए एक मेज की जरूरत है। आपके पास चार टेबल विकल्प हैं: सामान्य सारणी, स्थानीय अस्थायी तालिकाओं, वैश्विक अस्थायी तालिकाओं और तालिका चर। चार तालिका विकल्पों में से प्रत्येक का अपना उद्देश्य और उपयोग, और प्रत्येक के अपने फायदे और मुद्दे हैं:

* Normal tables are exactly that, physical tables defined in your database. 

* Local temporary tables are temporary tables that are available only to the session that created them. These tables are automatically destroyed at the termination of the procedure or session that created them. 

* Global temporary tables are temporary tables that are available to all sessions and all users. They are dropped automatically when the last session using the temporary table has completed. Both local temporary tables and global temporary tables are physical tables created within the tempdb database. 

* Table variables are stored within memory but are laid out like a table. Table variables are partially stored on disk and partially stored in memory. It's a common misconception that table variables are stored only in memory. Because they are partially stored in memory, the access time for a table variable can be faster than the time it takes to access a temporary table. 

कौन सा उपयोग करने के लिए:

* If you have less than 100 rows generally use a table variable. Otherwise use a temporary table. This is because SQL Server won't create statistics on table variables. 
* If you need to create indexes on it then you must use a temporary table. 
* When using temporary tables always create them and create any indexes and then use them. This will help reduce recompilations. The impact of this is reduced starting in SQL Server 2005 but it's still a good idea. 

Please refer this page http://www.sqlteam.com/article/temporary-tables

2

अस्थायी तालिकाओं रनटाइम पर बनाया जा सकता है और सभी प्रकार के संचालन कर सकता है जो एक सामान्य तालिका कर सकती है। लेकिन, टेबल प्रकारों के आधार पर, दायरा सीमित है। ये टेबल tempdb डेटाबेस के अंदर बनाए गए हैं।

SQL सर्वर तालिका के व्यवहार और दायरे के आधार पर दो प्रकार की अस्थायी सारणी प्रदान करता है। ये हैं:

स्थानीय अस्थायी तालिका

वैश्विक अस्थायी तालिका

स्थानीय अस्थायी तालिका स्थानीय अस्थायी तालिकाओं केवल उपयोगकर्ता के लिए वर्तमान कनेक्शन के लिए उपलब्ध हैं; और जब उपयोगकर्ता उदाहरणों से डिस्कनेक्ट होते हैं तो वे स्वचालित रूप से हटा दिए जाते हैं। स्थानीय अस्थायी तालिका का नाम हैश ("#") के साथ देखा गया है। वैश्विक ताप तालिका वैश्विक अस्थायी सारणी का नाम डबल हैश ("##") से शुरू होता है। एक बार यह तालिका कनेक्शन द्वारा बनाई गई है, एक स्थायी तालिका की तरह यह किसी भी कनेक्शन से किसी भी उपयोगकर्ता के लिए उपलब्ध है। एक बार सभी कनेक्शन बंद होने के बाद ही इसे हटाया जा सकता है।

अस्थायी सारणी का उपयोग कब करें?

• जब हम संग्रहीत प्रक्रियाओं में बड़ी संख्या में पंक्ति कुशलता कर रहे हैं। • यह कर्सर को प्रतिस्थापित करने के लिए उपयोगी है। हम परिणाम सेट डेटा को एक अस्थायी तालिका में संग्रहीत कर सकते हैं, फिर हम वहां से डेटा का उपयोग कर सकते हैं। • जब हम जटिल परिचालन में शामिल होते हैं।

अंक अस्थायी तालिकाओं का उपयोग करने से पहले याद करने के लिए -

SQL सर्वर के लिए tempdb पर बनाया अस्थायी तालिका •। यह एक अलग डेटाबेस है। तो, यह एक अतिरिक्त ओवरहेड है और प्रदर्शन के मुद्दों का कारण बन सकता है। • पंक्तियों और स्तंभों की संख्या आवश्यकतानुसार न्यूनतम होने की आवश्यकता है। • जब वे अपने काम के साथ किए जाते हैं तो टेबल्स को हटाने की आवश्यकता होती है।

वैकल्पिक दृष्टिकोण: टेबल Variable- अस्थायी तालिका के

वैकल्पिक तालिका का जो कार्य है कि हम अस्थायी तालिका में प्रदर्शन कर सकते हैं के सभी प्रकार कर सकते हैं। तालिका चर का उपयोग करने के लिए नीचे वाक्यविन्यास है।

जब से अधिक अस्थायी तालिका तालिका का उपयोग करना -

Tablevariable हमेशा कम डेटा के लिए उपयोगी है। यदि परिणाम सेट बड़ी संख्या में रिकॉर्ड देता है, तो हमें अस्थायी तालिका के लिए जाना होगा।

संबंधित मुद्दे