{"id":10201,"date":"2026-04-24T06:24:00","date_gmt":"2026-04-24T04:24:00","guid":{"rendered":"https:\/\/expert-only.com\/?p=10201"},"modified":"2026-04-27T19:24:46","modified_gmt":"2026-04-27T17:24:46","slug":"manage-sql-server-temporary-tables","status":"publish","type":"post","link":"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/","title":{"rendered":"Manage SQL Server temp tables using T-SQL code"},"content":{"rendered":"\n<script type=\"application\/ld+json\">\n{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"TechArticle\",\n  \"headline\": \"SQL Server Temp Tables: How to Create, Drop and Manage Them in T-SQL\",\n  \"description\": \"Complete guide to local (#) and global (##) temp tables in SQL Server with T-SQL syntax for SQL Server 2016+ and earlier versions, plus a real-world example with multiple temp tables.\",\n  \"image\": \"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/create-local-temporary-table-sql-server.jpg\",\n  \"datePublished\": \"2023-01-15T08:00:00+02:00\",\n  \"dateModified\": \"2026-04-24T08:00:00+02:00\",\n  \"author\": {\n    \"@type\": \"Person\",\n    \"name\": \"[Your Name]\",\n    \"url\": \"https:\/\/expert-only.com\/en\/who-are-we-data-engineers\/\",\n    \"jobTitle\": \"Senior Data Engineer\",\n    \"knowsAbout\": [\"SQL Server\", \"T-SQL\", \"SSIS\", \"Microsoft BI\", \"tempdb\"]\n  },\n  \"publisher\": {\n    \"@type\": \"Organization\",\n    \"name\": \"Expert-Only\",\n    \"url\": \"https:\/\/expert-only.com\/\",\n    \"logo\": {\n      \"@type\": \"ImageObject\",\n      \"url\": \"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/04\/cropped-cropped-logo.png\"\n    }\n  },\n  \"mainEntityOfPage\": \"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/\",\n  \"proficiencyLevel\": \"Beginner\",\n  \"dependencies\": \"SQL Server 2008 or later, SSMS\"\n}\n<\/script>\n<script type=\"application\/ld+json\">\n{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"BreadcrumbList\",\n  \"itemListElement\": [\n    {\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/expert-only.com\/en\/\"},\n    {\"@type\":\"ListItem\",\"position\":2,\"name\":\"T-SQL\",\"item\":\"https:\/\/expert-only.com\/en\/t-sql\/\"},\n    {\"@type\":\"ListItem\",\"position\":3,\"name\":\"SQL Server Temp Tables\",\"item\":\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/\"}\n  ]\n}\n<\/script>\n<script type=\"application\/ld+json\">\n{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"FAQPage\",\n  \"mainEntity\": [\n    {\n      \"@type\": \"Question\",\n      \"name\": \"What is the difference between # and ## in SQL Server?\",\n      \"acceptedAnswer\": {\n        \"@type\": \"Answer\",\n        \"text\": \"A single hash # creates a local temp table, visible only to the session that created it. A double hash ## creates a global temp table, visible to every session on the instance until the last referencing session disconnects.\"\n      }\n    },\n    {\n      \"@type\": \"Question\",\n      \"name\": \"Where are SQL Server temp tables stored?\",\n      \"acceptedAnswer\": {\n        \"@type\": \"Answer\",\n        \"text\": \"All temp tables, local and global, are stored in the tempdb system database, in the dbo schema. SQL Server appends a unique numeric suffix to local temp tables to avoid collisions between concurrent sessions.\"\n      }\n    },\n    {\n      \"@type\": \"Question\",\n      \"name\": \"Are temp tables faster than table variables?\",\n      \"acceptedAnswer\": {\n        \"@type\": \"Answer\",\n        \"text\": \"For small datasets under about 100 rows, table variables (@table) are usually faster due to lower overhead. For larger datasets, temp tables win because they support indexes, statistics, and parallel query plans.\"\n      }\n    },\n    {\n      \"@type\": \"Question\",\n      \"name\": \"Do temp tables need to be dropped manually?\",\n      \"acceptedAnswer\": {\n        \"@type\": \"Answer\",\n        \"text\": \"No. Local temp tables are dropped automatically when the session ends. Global temp tables are dropped when the last session referencing them disconnects. Manual DROP TABLE is only needed inside long-running scripts to free tempdb space.\"\n      }\n    },\n    {\n      \"@type\": \"Question\",\n      \"name\": \"Can a temp table have a primary key or index?\",\n      \"acceptedAnswer\": {\n        \"@type\": \"Answer\",\n        \"text\": \"Yes. You can define PRIMARY KEY, UNIQUE, and non-clustered indexes on temp tables exactly like permanent tables. However, foreign keys are silently ignored by the SQL Server engine.\"\n      }\n    },\n    {\n      \"@type\": \"Question\",\n      \"name\": \"What is the maximum size of a SQL Server temp table?\",\n      \"acceptedAnswer\": {\n        \"@type\": \"Answer\",\n        \"text\": \"Limited only by available tempdb space. There is no row or column limit beyond the standard SQL Server table limits of 1,024 columns and roughly 8 KB per row.\"\n      }\n    }\n  ]\n}\n<\/script>\n\n\n\n<p class=\"has-text-align-center\"><strong><em>How to create and manage <strong><em>SQL Server temp tables<\/em><\/strong> with T-SQL code? A complete guide to local (#) and global (##) temporary tables.<\/em><\/strong><\/p>\n\n\n\n<p><strong>SQL Server temp tables<\/strong> are temporary objects stored in <code>tempdb<\/code> that hold intermediate result sets for the duration of a session. They come in two types:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Local temp tables (<code>#TableName<\/code>)<\/strong> \u2014 visible only to the session that created them, dropped automatically when the session ends.<\/li>\n\n\n\n<li><strong>Global temp tables (<code>##TableName<\/code>)<\/strong> \u2014 visible to all sessions on the instance, dropped when the last referencing session ends.<\/li>\n<\/ul>\n\n\n\n<p>This tutorial covers how to <strong>create, populate, drop, and list temp tables<\/strong> using T-SQL, with a complete real-world example using multiple temp tables for a complex data transformation. SSMS and T-SQL provide all the options needed to manage these objects, which are a valuable tool for optimizing performance and simplifying complex code.<\/p>\n\n\n\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_83 ez-toc-wrap-center counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#t-sql-%e2%80%93-temp-table-quick-syntax-reference\" >T-SQL &#8211; Temp table quick syntax reference<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#1-what-exactly-is-a-sql-server-temporary-table\" >1. What exactly is a SQL Server temporary table?<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#11-differences-between-a-permanent-and-a-temporary-table\" >1.1 Differences between a permanent and a temporary table<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#12-main-characteristics-of-temp-tables-in-t-sql-projects\" >1.2 Main characteristics of temp tables in T-SQL projects<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#2-manage-local-temporary-tables-overview\" >2. Manage local temporary tables overview<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#3-create-a-local-temporary-table\" >3. Create a local temporary table<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#4-drop-a-local-temporary-table\" >4. Drop a local temporary table<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#41-drop-a-local-temp-table-with-sql-server-versions-before-2016\" >4.1 Drop a local temp table with SQL Server versions before 2016<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#5-global-temporary-tables-overview\" >5. Global temporary tables overview<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#6-create-a-global-temporary-table\" >6. Create a global temporary table<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#7-drop-a-global-temporary-table\" >7. Drop a global temporary table<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#71-drop-a-global-temp-table-with-sql-server-versions-before-2016\" >7.1 Drop a global temp table with SQL Server versions before 2016<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#8-list-all-temporary-tables-of-the-instance\" >8. List all temporary tables of the instance<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#9-real-world-example-using-4-temp-tables-for-a-complex-sales-transformation\" >9. Real-world example: using 4 temp tables for a complex sales transformation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#10-temp-tables-vs-table-variables-vs-cte-when-to-use-what\" >10. Temp tables vs table variables vs CTE: when to use what?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#11-adding-indexes-to-a-temp-table\" >11. Adding indexes to a temp table<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#12-pros-and-cons-of-using-sql-server-temporary-tables\" >12. Pros and cons of using SQL Server temporary tables<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#121-benefits-of-temporary-tables-in-t-sql-queries\" >12.1 Benefits of temporary tables in T-SQL queries<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#122-limitations-of-temporary-tables-in-sql-server\" >12.2 Limitations of temporary tables in SQL Server<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#13-faq-on-sql-server-temp-tables\" >13. FAQ on SQL Server temp tables<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#what-is-the-difference-between-and-in-sql-server\" >What is the difference between # and ## in SQL Server?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#where-are-sql-server-temp-tables-stored\" >Where are SQL Server temp tables stored?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-23\" href=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#are-temp-tables-faster-than-table-variables\" >Are temp tables faster than table variables?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-24\" href=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#do-temp-tables-need-to-be-dropped-manually\" >Do temp tables need to be dropped manually?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-25\" href=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#can-a-temp-table-have-a-primary-key-or-index\" >Can a temp table have a primary key or index?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-26\" href=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#what-is-the-maximum-size-of-a-sql-server-temp-table\" >What is the maximum size of a SQL Server temp table?<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-27\" href=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#14-conclusion-on-sql-server-temporary-tables\" >14. Conclusion on SQL Server temporary tables<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-t-sql-temp-table-quick-syntax-reference\"><span class=\"ez-toc-section\" id=\"t-sql-%e2%80%93-temp-table-quick-syntax-reference\"><\/span>T-SQL &#8211; Temp table quick syntax reference<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Here is a quick T-SQL cheat sheet to bookmark for your daily work with SQL Server temp tables:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Action<\/th><th>T-SQL syntax<\/th><\/tr><\/thead><tbody><tr><td>Create local temp table<\/td><td><code>CREATE TABLE #MyTemp (...);<\/code><\/td><\/tr><tr><td>Create global temp table<\/td><td><code>CREATE TABLE ##MyTemp (...);<\/code><\/td><\/tr><tr><td>Drop (SQL Server 2016+)<\/td><td><code>DROP TABLE IF EXISTS #MyTemp;<\/code><\/td><\/tr><tr><td>Drop (pre-2016)<\/td><td><code>IF OBJECT_ID('tempdb..#MyTemp') IS NOT NULL DROP TABLE #MyTemp;<\/code><\/td><\/tr><tr><td>List all temp tables from db<\/td><td><code>SELECT * FROM tempdb.sys.tables WHERE name LIKE '#%';<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-1-what-exactly-is-a-sql-server-temporary-table\"><span class=\"ez-toc-section\" id=\"1-what-exactly-is-a-sql-server-temporary-table\"><\/span>1. What exactly is a SQL Server temporary table?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>SQL Server temp tables are temporary objects used for storing data during the lifetime of a session. They are created with the <a href=\"https:\/\/expert-only.com\/en\/t-sql\/create-table-sql-server\/\">CREATE TABLE command in T-SQL<\/a>, exactly like permanent tables, but with a hash prefix in the name. In this MS SQL tutorial, we will learn what temp tables are used for, the two types available (local and global), how to create them, and how to insert data into them.<\/p>\n\n\n\n<p>SQL is a programming language designed for managing data in relational database management systems. SQL statements are used to create, read, update, and delete data, and the main object used is the table. A temporary table is a table created in SQL Server for the purpose of storing temporary data that will be used only during the duration of a single session or stored procedure execution.<\/p>\n\n\n\n<p>Local temp tables are dropped when the session that created them is closed (whether the client is <a href=\"https:\/\/expert-only.com\/en\/ssms\/download-ssms-18\/\">SQL Server Management Studio<\/a>, Azure Data Studio, an application using ADO.NET, or any other connection), or when you execute <a href=\"https:\/\/expert-only.com\/en\/t-sql\/drop-a-table-with-a-sql-server-script\/\">DROP TABLE<\/a> on them explicitly.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-1-1-differences-between-a-permanent-and-a-temporary-table\"><span class=\"ez-toc-section\" id=\"11-differences-between-a-permanent-and-a-temporary-table\"><\/span>1.1 Differences between a permanent and a temporary table<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><em>What is the difference between a permanent and a temporary table in SQL Server?<\/em><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A permanent table is created when a user first creates it and is only dropped explicitly. So, it remains in the database. It is stored on the disk in the user database, and it is backed up if backups are active on the SQL Server database.<\/li>\n\n\n\n<li>Temporary tables are also created with a simple SQL CREATE statement, but they live in <code>tempdb<\/code> and are dropped after the end of a stored procedure, after the session is closed, or after all tasks referencing the table are closed (for global temporary tables).<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-1-2-main-characteristics-of-temp-tables-in-t-sql-projects\"><span class=\"ez-toc-section\" id=\"12-main-characteristics-of-temp-tables-in-t-sql-projects\"><\/span>1.2 Main characteristics of temp tables in T-SQL projects<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The main goal and benefit of temporary tables is to store intermediate result sets of queries. These result sets live in <code>tempdb<\/code> \u2014 backed by disk, but heavily cached in memory by SQL Server \u2014 which is why they are fast to read and write. Temporary tables can be created to store data from a single or multiple queries. However, do not use temporary tables for long-term storage or for frequently accessed data, that is what permanent tables are for.<\/p>\n\n\n\n<p>A version of the MS SQL tutorial is available in video on the <a href=\"https:\/\/www.youtube.com\/channel\/UCMS5sR_FwAetB0FmciNvUaA\" target=\"_blank\" rel=\"noreferrer noopener\">Youtube Channel of the blog<\/a>:<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"How to create and manage SQL Server temporary tables?\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/gmh2clNMoB8?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-2-manage-local-temporary-tables-overview\"><span class=\"ez-toc-section\" id=\"2-manage-local-temporary-tables-overview\"><\/span>2. Manage local temporary tables overview<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>A local temporary table can be created and called inside a stored procedure. In this case, the same stored procedure can be called by many sessions at the same time without interference. The <a href=\"https:\/\/expert-only.com\/en\/dba\/create-sql-server-database-with-ssms\/\">MS SQL database<\/a> engine distinguishes the tables by adding a numeric suffix at the end of the table name. You can inspect this suffix in the modern <a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/relational-databases\/system-catalog-views\/sys-tables-transact-sql\" target=\"_blank\" rel=\"noreferrer noopener\">sys.tables catalog view<\/a> (the legacy <code>sys.sysobjects<\/code> still works but has been deprecated since SQL Server 2008). Local temporary tables are stored in <code>tempdb<\/code> on the same instance as the database that created them.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-3-create-a-local-temporary-table\"><span class=\"ez-toc-section\" id=\"3-create-a-local-temporary-table\"><\/span>3. Create a local temporary table<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>All temp tables always live in <code>tempdb.dbo<\/code>, the schema is fixed and cannot be specified in the CREATE statement. To create a local temporary table, simply execute a query like this one:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">-- Create a sales local temporary table\n-- with two columns\nCREATE TABLE #Sales_Temp (\n   [MonthName]   nvarchar(20),\n   [Amount]      numeric(8)\n);\nGO\n\n-- Insert sales data for the first\n-- three month of the year\nINSERT INTO #Sales_Temp (MonthName, Amount)\nVALUES ( N'January', 1000);\nINSERT INTO #Sales_Temp (MonthName, Amount)\nVALUES ( N'February', 2000);\nINSERT INTO #Sales_Temp (MonthName, Amount)\nVALUES ( N'March', 3000);\nGO\n\n-- script provided by https:\/\/expert-only.com <\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"680\" src=\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/create-local-temporary-table-sql-server.jpg\" alt=\"T-SQL CREATE TABLE statement creating a local temp table named #Sales_Temp with MonthName and Amount columns in SSMS\" class=\"wp-image-10185\" srcset=\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/create-local-temporary-table-sql-server.jpg 640w, https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/create-local-temporary-table-sql-server-282x300.jpg 282w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><figcaption class=\"wp-element-caption\"><strong><em>Creating a local temporary table #Sales_Temp with two columns (MonthName, Amount) using T-SQL in SSMS.<\/em><\/strong><\/figcaption><\/figure>\n<\/div>\n\n\n<p>However, it is also possible to create a temporary table outside a stored procedure, like for example in a simple T-SQL statement. This is also a way to avoid errors if a stored procedure has the exact same name inside a procedure.<\/p>\n\n\n\n<p>It is recommended to check and drop any existing temp table before creating a new one with the same name, even if they are not permanent objects. The official Microsoft reference is the <a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/t-sql\/statements\/create-table-transact-sql\" target=\"_blank\" rel=\"noreferrer noopener\">CREATE TABLE (Transact-SQL)<\/a> documentation.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-4-drop-a-local-temporary-table\"><span class=\"ez-toc-section\" id=\"4-drop-a-local-temporary-table\"><\/span>4. Drop a local temporary table<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>To drop a local temporary table on SQL Server 2016 or later, use this syntax:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">DROP TABLE IF EXISTS #Sales_Temp; \nGO<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-4-1-drop-a-local-temp-table-with-sql-server-versions-before-2016\"><span class=\"ez-toc-section\" id=\"41-drop-a-local-temp-table-with-sql-server-versions-before-2016\"><\/span>4.1 Drop a local temp table with SQL Server versions before 2016<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>For SQL Server versions before the 2016 release, use this statement instead, because <code>DROP TABLE IF EXISTS<\/code> was only introduced in MS SQL Server 2016:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">IF OBJECT_ID('tempdb..#Sales_Temp', 'U') IS NOT NULL\n   DROP TABLE #Sales_Temp;\nGO<\/pre>\n\n\n\n<p>Here is another <a href=\"https:\/\/expert-only.com\/en\/manage-sql-server-tables\/\">IT tutorial for managing classic SQL Server tables<\/a> this time, i.e. permanent tables.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-sql-and-it-tutorials wp-block-embed-sql-and-it-tutorials\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"wv2qTVlsRB\"><a href=\"https:\/\/expert-only.com\/en\/manage-sql-server-tables\/\">Manage SQL Server tables<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;Manage SQL Server tables&#8221; &#8212; SQL and IT Tutorials\" src=\"https:\/\/expert-only.com\/en\/manage-sql-server-tables\/embed\/#?secret=O0Rt0xAneI#?secret=wv2qTVlsRB\" data-secret=\"wv2qTVlsRB\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-5-global-temporary-tables-overview\"><span class=\"ez-toc-section\" id=\"5-global-temporary-tables-overview\"><\/span>5. Global temporary tables overview<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>On the other hand, global temporary tables (with the <code>##<\/code> prefix) are visible to every session on the instance and are only dropped after all tasks on the table are finished. In other words, the global temp table will be deleted from the system after the session that created it has disconnected and the last query referencing it from any other session has finished executing.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-6-create-a-global-temporary-table\"><span class=\"ez-toc-section\" id=\"6-create-a-global-temporary-table\"><\/span>6. Create a global temporary table<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>This script allows you to create a simple global temporary table:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">-- Create a sales global temporary table\n-- with two columns\nCREATE TABLE ##Sales_Global (\n   [MonthName]   nvarchar(20),\n   [Amount]      numeric(8)\n);\nGO\n\n-- Insert sales data for the first\n-- three month of the year\nINSERT INTO ##Sales_Global (MonthName, Amount)\nVALUES ( N'January', 1000);\nINSERT INTO ##Sales_Global (MonthName, Amount)\nVALUES ( N'February', 2000);\nINSERT INTO ##Sales_Global (MonthName, Amount)\nVALUES ( N'March', 3000);\nGO\n\n-- script provided by https:\/\/expert-only.com <\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"680\" src=\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/create-global-temporary-table-sql-server.jpg\" alt=\"T-SQL CREATE TABLE statement creating a global temp table named ##Sales_Global with MonthName and Amount columns in SSMS\" class=\"wp-image-10191\" srcset=\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/create-global-temporary-table-sql-server.jpg 640w, https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/create-global-temporary-table-sql-server-282x300.jpg 282w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><figcaption class=\"wp-element-caption\">Creating a global temporary table <code>##Sales_Global<\/code> with the double-hash prefix using T-SQL.<\/figcaption><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-7-drop-a-global-temporary-table\"><span class=\"ez-toc-section\" id=\"7-drop-a-global-temporary-table\"><\/span>7. Drop a global temporary table<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>To check if a temp table exists and drop it at the same time without error, use a query like this one (SQL Server 2016 and later):<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">DROP TABLE IF EXISTS ##Sales_Global;\nGO<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-7-1-drop-a-global-temp-table-with-sql-server-versions-before-2016\"><span class=\"ez-toc-section\" id=\"71-drop-a-global-temp-table-with-sql-server-versions-before-2016\"><\/span>7.1 Drop a global temp table with SQL Server versions before 2016<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>To check if the table exists and drop it in versions earlier than 2016, use this example. Note the double hash on both the OBJECT_ID check and the DROP statement:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">IF OBJECT_ID('tempdb..##Sales_Global', 'U') IS NOT NULL\n   DROP TABLE ##Sales_Global;\nGO<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-8-list-all-temporary-tables-of-the-instance\"><span class=\"ez-toc-section\" id=\"8-list-all-temporary-tables-of-the-instance\"><\/span>8. List all temporary tables of the instance<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>First, to list all the temporary tables created on the SQL Server instance, use this T-SQL query against the modern <code>sys.tables<\/code> catalog view (recommended over the deprecated <code>sys.sysobjects<\/code>):<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT name, create_date, modify_date \nFROM tempdb.sys.tables\nWHERE name LIKE '#%'\nORDER BY name;<\/pre>\n\n\n\n<p>Second, to list only the local temporary tables created on the SQL Server instance, use this T-SQL statement:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT name, create_date \nFROM tempdb.sys.tables\nWHERE name LIKE '#%' \n  AND name NOT LIKE '##%'\nORDER BY name;<\/pre>\n\n\n\n<p>Third, to list only the global temporary tables created on the current instance, use this T-SQL example:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT name, create_date \nFROM tempdb.sys.tables\nWHERE name LIKE '##%'\nORDER BY name;<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-9-real-world-example-using-4-temp-tables-for-a-complex-sales-transformation\"><span class=\"ez-toc-section\" id=\"9-real-world-example-using-4-temp-tables-for-a-complex-sales-transformation\"><\/span>9. Real-world example: using 4 temp tables for a complex sales transformation<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>For example, <strong>to create a very complex transformation<\/strong> using data from multiple tables and views where you only need to store the final result, temp tables are the right tool. For example, you need to <a href=\"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/\">pivot a table<\/a>, then calculate an average, sum the values, and finally dispatch the data using a ratio across different dates. Then using intermediate temp tables is much easier than writing a very large and complex <a href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedure\/\">stored procedure with T-SQL<\/a> in one shot.<\/p>\n\n\n\n<p>We recommend to split the following code into steps inside one or multiple stored procedures. For example, let&#8217;s use these 4 local temporary tables:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>#temp_1_pivot<\/code> \u2014 the raw sales data by product and year<\/li>\n\n\n\n<li><code>#temp_2_average<\/code> \u2014 the average sales per product<\/li>\n\n\n\n<li><code>#temp_3_group_by_year<\/code> \u2014 the total sales grouped by year<\/li>\n\n\n\n<li><code>#temp_4_ratio<\/code> \u2014 the sales ratio per year compared to the total<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">-- Create temp table #temp_1_pivot\nCREATE TABLE #temp_1_pivot (\n    ProductID INT,\n    Year INT,\n    Sales INT\n);\n\nINSERT INTO #temp_1_pivot (ProductID, Year, Sales)\nVALUES\n    (1, 2020, 110),\n    (1, 2021, 150),\n    (1, 2022, 190),\n    (2, 2020, 50),\n    (2, 2021, 75),\n    (2, 2022, 125),\n    (3, 2020, 75),\n    (3, 2021, 125),\n    (3, 2022, 175),\n    (4, 2020, 60),\n    (4, 2021, 90),\n    (4, 2022, 80);\n\n-- Create temp table #temp_2_average\nCREATE TABLE #temp_2_average (\n    ProductID INT,\n    AverageSales INT\n);\n\n-- Populate #temp_2_average with average sales by product ID\nINSERT INTO #temp_2_average\nSELECT \n    ProductID,\n    AVG(Sales) AS AverageSales\nFROM \n    #temp_1_pivot\nGROUP BY \n    ProductID;\n\n-- Create temp table #temp_3_group_by_year\nCREATE TABLE #temp_3_group_by_year (\n    Year INT,\n    TotalSales INT\n);\n\n-- Populate #temp_3_group_by_year with total sales by year\nINSERT INTO #temp_3_group_by_year\nSELECT \n    Year,\n    SUM(Sales) AS TotalSales\nFROM \n    #temp_1_pivot\nGROUP BY \n    Year;\n\n-- Create temp table #temp_4_ratio\nCREATE TABLE #temp_4_ratio (\n    Year INT,\n    SalesRatio FLOAT\n);\n\n-- Populate #temp_4_ratio with the sales ratio by year\nINSERT INTO #temp_4_ratio\nSELECT \n    t3.Year,\n    (CAST(t3.TotalSales AS FLOAT) \/ (SELECT SUM(TotalSales) FROM #temp_3_group_by_year)) AS SalesRatio\nFROM \n    #temp_3_group_by_year t3;\n\n-- Display the results from the temp tables\nSELECT * FROM #temp_1_pivot;\nSELECT * FROM #temp_2_average;\nSELECT * FROM #temp_3_group_by_year;\nSELECT * FROM #temp_4_ratio;\n\n-- Drop the temp tables\nDROP TABLE #temp_1_pivot;\nDROP TABLE #temp_2_average;\nDROP TABLE #temp_3_group_by_year;\nDROP TABLE #temp_4_ratio;\n\n-- script provided by https:\/\/expert-only.com<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-10-temp-tables-vs-table-variables-vs-cte-when-to-use-what\"><span class=\"ez-toc-section\" id=\"10-temp-tables-vs-table-variables-vs-cte-when-to-use-what\"><\/span>10. Temp tables vs table variables vs CTE: when to use what?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>One of the most common questions in T-SQL projects is when to use a temp table, when to use a table variable (<code>@table<\/code>), and when a CTE (Common Table Expression) is enough. Here is a quick decision matrix based on real-world usage:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Temp table (<code>#<\/code>)<\/th><th>Table variable (<code>@<\/code>)<\/th><th>CTE (<code>WITH<\/code>)<\/th><\/tr><\/thead><tbody><tr><td>Storage<\/td><td><code>tempdb<\/code><\/td><td><code>tempdb<\/code> (memory-first)<\/td><td>Inline, in-memory<\/td><\/tr><tr><td>Indexes supported<\/td><td>Yes (clustered + non-clustered)<\/td><td>Limited (PK and UNIQUE only)<\/td><td>No<\/td><\/tr><tr><td>Statistics<\/td><td>Yes<\/td><td>No<\/td><td>No<\/td><\/tr><tr><td>Best for<\/td><td>Large datasets, multi-step logic<\/td><td>Small datasets (&lt; 100 rows)<\/td><td>Single query, recursive logic<\/td><\/tr><tr><td>Scope<\/td><td>Session (or batch for global)<\/td><td>Batch only<\/td><td>Single statement<\/td><\/tr><tr><td>Transaction support<\/td><td>Full<\/td><td>Limited (no rollback on data)<\/td><td>N\/A<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>In summary: use a CTE for readable single-statement logic, a table variable for tiny lookup sets, and a temp table whenever you are working with thousands of rows or need indexes and statistics for the query optimizer to do its job properly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-11-adding-indexes-to-a-temp-table\"><span class=\"ez-toc-section\" id=\"11-adding-indexes-to-a-temp-table\"><\/span>11. Adding indexes to a temp table<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>One of the biggest performance advantages of temp tables over table variables is that they support indexes. Since SQL Server 2014, you can declare indexes inline in the CREATE TABLE statement. This is very useful in stored procedures where you want to optimize the joins on the temp table:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">-- Create a temp table with a primary key\n-- and a non-clustered index inline\nCREATE TABLE #Sales_Indexed (\n   SaleID    INT NOT NULL PRIMARY KEY CLUSTERED,\n   ProductID INT NOT NULL,\n   Amount    NUMERIC(10,2),\n   INDEX IX_ProductID NONCLUSTERED (ProductID)\n);\nGO\n\n-- script provided by https:\/\/expert-only.com<\/pre>\n\n\n\n<p>For older versions of SQL Server (pre-2014), you have to create the indexes after the CREATE TABLE statement, with regular CREATE INDEX commands.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-12-pros-and-cons-of-using-sql-server-temporary-tables\"><span class=\"ez-toc-section\" id=\"12-pros-and-cons-of-using-sql-server-temporary-tables\"><\/span>12. Pros and cons of using SQL Server temporary tables<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-12-1-benefits-of-temporary-tables-in-t-sql-queries\"><span class=\"ez-toc-section\" id=\"121-benefits-of-temporary-tables-in-t-sql-queries\"><\/span>12.1 Benefits of temporary tables in T-SQL queries<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>This is a short list, not exhaustive, of the temporary table benefits:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Store intermediate results for complex data operations and break down very large stored procedures into readable steps.<\/li>\n\n\n\n<li>Store the results of a repeatedly executed query. Caching data allows for one-time computation and storage and increases performance. It is therefore an ideal workspace for processing large amounts of data.<\/li>\n\n\n\n<li>Local temporary tables are created in the <code>tempdb<\/code> system database and are not visible outside the session in which they were created, which makes them safe for parallel execution.<\/li>\n\n\n\n<li>Temp tables support indexes, statistics, and parallel query plans, unlike table variables.<\/li>\n\n\n\n<li>The database engine automatically manages temporary tables and cleans them up when the session ends.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-12-2-limitations-of-temporary-tables-in-sql-server\"><span class=\"ez-toc-section\" id=\"122-limitations-of-temporary-tables-in-sql-server\"><\/span>12.2 Limitations of temporary tables in SQL Server<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Temp tables are not always the right tool. Here are the main limitations to keep in mind:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Temp tables in SQL Server <strong>do not support foreign keys<\/strong>. If a foreign key is used in the creation script, the execution will not fail, but the key will not be created and the database engine will display a warning message.<\/li>\n\n\n\n<li>Heavy use of temp tables in many concurrent sessions can cause <strong>tempdb contention<\/strong>, especially on PFS, GAM, and SGAM allocation pages. The classic mitigation is to size <code>tempdb<\/code> with multiple data files (one per CPU core, up to 8) on production instances.<\/li>\n\n\n\n<li>Stored procedures using temp tables can suffer from <strong>statement-level recompilations<\/strong> when the row count changes significantly between executions. This is usually a feature, not a bug, but worth knowing for performance tuning.<\/li>\n\n\n\n<li>Global temp tables (<code>##<\/code>) have <strong>no security boundary<\/strong>: any session can read or write to them. Use them sparingly and prefer local temp tables in 99% of cases.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-13-faq-on-sql-server-temp-tables\"><span class=\"ez-toc-section\" id=\"13-faq-on-sql-server-temp-tables\"><\/span>13. FAQ on SQL Server temp tables<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-what-is-the-difference-between-and-in-sql-server\"><span class=\"ez-toc-section\" id=\"what-is-the-difference-between-and-in-sql-server\"><\/span>What is the difference between # and ## in SQL Server?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>A single hash <code>#<\/code> creates a <strong>local temp table<\/strong>, visible only to the session that created it. A double hash <code>##<\/code> creates a <strong>global temp table<\/strong>, visible to every session on the instance until the last referencing session disconnects.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-where-are-sql-server-temp-tables-stored\"><span class=\"ez-toc-section\" id=\"where-are-sql-server-temp-tables-stored\"><\/span>Where are SQL Server temp tables stored?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>All temp tables, local and global, are stored in the <code>tempdb<\/code> system database, in the <code>dbo<\/code> schema. SQL Server appends a unique numeric suffix to local temp tables to avoid collisions between concurrent sessions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-are-temp-tables-faster-than-table-variables\"><span class=\"ez-toc-section\" id=\"are-temp-tables-faster-than-table-variables\"><\/span>Are temp tables faster than table variables?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>For small datasets under about 100 rows, table variables (<code>@table<\/code>) are usually faster due to lower overhead. For larger datasets, temp tables win because they support indexes, statistics, and parallel query plans.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-do-temp-tables-need-to-be-dropped-manually\"><span class=\"ez-toc-section\" id=\"do-temp-tables-need-to-be-dropped-manually\"><\/span>Do temp tables need to be dropped manually?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>No. Local temp tables are dropped automatically when the session ends. Global temp tables are dropped when the last session referencing them disconnects. Manual <code>DROP TABLE<\/code> is only needed inside long-running scripts to free <code>tempdb<\/code> space, or before recreating a temp table with the same name in the same session.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-can-a-temp-table-have-a-primary-key-or-index\"><span class=\"ez-toc-section\" id=\"can-a-temp-table-have-a-primary-key-or-index\"><\/span>Can a temp table have a primary key or index?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Yes. You can define <code>PRIMARY KEY<\/code>, <code>UNIQUE<\/code>, and non-clustered indexes on temp tables exactly like permanent tables. However, <strong>foreign keys are silently ignored<\/strong> by the SQL Server engine.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-what-is-the-maximum-size-of-a-sql-server-temp-table\"><span class=\"ez-toc-section\" id=\"what-is-the-maximum-size-of-a-sql-server-temp-table\"><\/span>What is the maximum size of a SQL Server temp table?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Limited only by available <code>tempdb<\/code> space. There is no row or column limit beyond the standard SQL Server table limits of 1,024 columns and roughly 8 KB per row.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-14-conclusion-on-sql-server-temporary-tables\"><span class=\"ez-toc-section\" id=\"14-conclusion-on-sql-server-temporary-tables\"><\/span>14. Conclusion on SQL Server temporary tables<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In conclusion, temporary tables provide a convenient way to store and manage intermediate data during complex T-SQL operations. By utilizing the <code>CREATE TABLE<\/code> and <code>INSERT INTO<\/code> statements, it is possible to dynamically create and populate temporary tables in SQL Server, with full support for indexes and statistics that table variables and CTEs cannot offer.<\/p>\n\n\n\n<p>The use of temporary tables can improve the efficiency and organization of T-SQL code, making it easier to maintain and debug. With the knowledge and techniques discussed in this blog post, you can now effectively manage temporary tables in your SQL Server projects, choose the right tool between temp tables, table variables and CTEs, and add indexes when performance matters.<\/p>\n\n\n\n<p>This tutorial on how to manage SQL Server temporary tables, whether local or global, explains how to create them, insert data, drop them, and list them from system catalog views. Here is another tutorial on <a href=\"https:\/\/expert-only.com\/en\/t-sql\/how-to-get-the-list-of-all-tables-in-sql-server\/\">how to list all tables in a SQL Server database<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-embed aligncenter is-type-wp-embed is-provider-sql-and-it-tutorials wp-block-embed-sql-and-it-tutorials\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"JqrqgbW2XE\"><a href=\"https:\/\/expert-only.com\/en\/t-sql\/how-to-get-the-list-of-all-tables-in-sql-server\/\">How To Get the List of All Tables in SQL Server ?<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;How To Get the List of All Tables in SQL Server ?&#8221; &#8212; SQL and IT Tutorials\" src=\"https:\/\/expert-only.com\/en\/t-sql\/how-to-get-the-list-of-all-tables-in-sql-server\/embed\/#?secret=IQ2djLeFYd#?secret=JqrqgbW2XE\" data-secret=\"JqrqgbW2XE\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>How to create and manage SQL Server temp tables with T-SQL code? A complete guide to local (#) and global (##) temporary tables. SQL Server temp tables are temporary objects stored in tempdb that hold intermediate result sets for <a class=\"mh-excerpt-more\" href=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/\" title=\"Manage SQL Server temp tables using T-SQL code\">&#8230;<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":5833,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[454],"tags":[],"class_list":{"0":"post-10201","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-t-sql"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.7 (Yoast SEO v27.5) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>SQL Server Temp Table : Create, Drop &amp; Manage - T-SQL<\/title>\n<meta name=\"description\" content=\"Learn how to create, drop and manage SQL Server temp tables (local # and global ##) with T-SQL. Step-by-step use case with multiple temporary tables.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Manage SQL Server temp tables using T-SQL code\" \/>\n<meta property=\"og:description\" content=\"Learn how to create, drop and manage SQL Server temp tables (local # and global ##) with T-SQL. Step-by-step use case with multiple temporary tables.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL and IT Tutorials\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ExpertOnlyCom\/\" \/>\n<meta property=\"article:published_time\" content=\"2026-04-24T04:24:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-27T17:24:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/06\/life_dark_river-432893F7EFD_1920x1080.jpeg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Expert-Only\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@expert_only\" \/>\n<meta name=\"twitter:site\" content=\"@expert_only\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Expert-Only\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/expert-only.com\\\/en\\\/t-sql\\\/manage-sql-server-temporary-tables\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/expert-only.com\\\/en\\\/t-sql\\\/manage-sql-server-temporary-tables\\\/\"},\"author\":{\"name\":\"Expert-Only\",\"@id\":\"https:\\\/\\\/expert-only.com\\\/en\\\/#\\\/schema\\\/person\\\/406a9576b52944f018739a42046873ef\"},\"headline\":\"Manage SQL Server temp tables using T-SQL code\",\"datePublished\":\"2026-04-24T04:24:00+00:00\",\"dateModified\":\"2026-04-27T17:24:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/expert-only.com\\\/en\\\/t-sql\\\/manage-sql-server-temporary-tables\\\/\"},\"wordCount\":2211,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/expert-only.com\\\/en\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/expert-only.com\\\/en\\\/t-sql\\\/manage-sql-server-temporary-tables\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/expert-only.com\\\/wp-content\\\/uploads\\\/2017\\\/06\\\/life_dark_river-432893F7EFD_1920x1080.jpeg\",\"articleSection\":[\"T-SQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/expert-only.com\\\/en\\\/t-sql\\\/manage-sql-server-temporary-tables\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/expert-only.com\\\/en\\\/t-sql\\\/manage-sql-server-temporary-tables\\\/\",\"url\":\"https:\\\/\\\/expert-only.com\\\/en\\\/t-sql\\\/manage-sql-server-temporary-tables\\\/\",\"name\":\"SQL Server Temp Table : Create, Drop & Manage - T-SQL\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/expert-only.com\\\/en\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/expert-only.com\\\/en\\\/t-sql\\\/manage-sql-server-temporary-tables\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/expert-only.com\\\/en\\\/t-sql\\\/manage-sql-server-temporary-tables\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/expert-only.com\\\/wp-content\\\/uploads\\\/2017\\\/06\\\/life_dark_river-432893F7EFD_1920x1080.jpeg\",\"datePublished\":\"2026-04-24T04:24:00+00:00\",\"dateModified\":\"2026-04-27T17:24:46+00:00\",\"description\":\"Learn how to create, drop and manage SQL Server temp tables (local # and global ##) with T-SQL. Step-by-step use case with multiple temporary tables.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/expert-only.com\\\/en\\\/t-sql\\\/manage-sql-server-temporary-tables\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/expert-only.com\\\/en\\\/t-sql\\\/manage-sql-server-temporary-tables\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/expert-only.com\\\/en\\\/t-sql\\\/manage-sql-server-temporary-tables\\\/#primaryimage\",\"url\":\"https:\\\/\\\/expert-only.com\\\/wp-content\\\/uploads\\\/2017\\\/06\\\/life_dark_river-432893F7EFD_1920x1080.jpeg\",\"contentUrl\":\"https:\\\/\\\/expert-only.com\\\/wp-content\\\/uploads\\\/2017\\\/06\\\/life_dark_river-432893F7EFD_1920x1080.jpeg\",\"width\":1920,\"height\":1080},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/expert-only.com\\\/en\\\/t-sql\\\/manage-sql-server-temporary-tables\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"en\",\"item\":\"https:\\\/\\\/expert-only.com\\\/en\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Manage SQL Server temp tables using T-SQL code\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/expert-only.com\\\/en\\\/#website\",\"url\":\"https:\\\/\\\/expert-only.com\\\/en\\\/\",\"name\":\"SQL and IT Tutorials\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/expert-only.com\\\/en\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/expert-only.com\\\/en\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/expert-only.com\\\/en\\\/#organization\",\"name\":\"Expert-Only\",\"url\":\"https:\\\/\\\/expert-only.com\\\/en\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/expert-only.com\\\/en\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/expert-only.com\\\/wp-content\\\/uploads\\\/2017\\\/09\\\/cropped-logo_Expert-Only.jpg\",\"contentUrl\":\"https:\\\/\\\/expert-only.com\\\/wp-content\\\/uploads\\\/2017\\\/09\\\/cropped-logo_Expert-Only.jpg\",\"width\":381,\"height\":174,\"caption\":\"Expert-Only\"},\"image\":{\"@id\":\"https:\\\/\\\/expert-only.com\\\/en\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/ExpertOnlyCom\\\/\",\"https:\\\/\\\/x.com\\\/expert_only\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCMS5sR_FwAetB0FmciNvUaA\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/expert-only.com\\\/en\\\/#\\\/schema\\\/person\\\/406a9576b52944f018739a42046873ef\",\"name\":\"Expert-Only\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/7e711e54a9f31bf0cc5e241d2149474e14ce3995669e683ae9e913aa93cd8da1?s=96&d=identicon&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/7e711e54a9f31bf0cc5e241d2149474e14ce3995669e683ae9e913aa93cd8da1?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/7e711e54a9f31bf0cc5e241d2149474e14ce3995669e683ae9e913aa93cd8da1?s=96&d=identicon&r=g\",\"caption\":\"Expert-Only\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"SQL Server Temp Table : Create, Drop & Manage - T-SQL","description":"Learn how to create, drop and manage SQL Server temp tables (local # and global ##) with T-SQL. Step-by-step use case with multiple temporary tables.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/","og_locale":"en_US","og_type":"article","og_title":"Manage SQL Server temp tables using T-SQL code","og_description":"Learn how to create, drop and manage SQL Server temp tables (local # and global ##) with T-SQL. Step-by-step use case with multiple temporary tables.","og_url":"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/","og_site_name":"SQL and IT Tutorials","article_publisher":"https:\/\/www.facebook.com\/ExpertOnlyCom\/","article_published_time":"2026-04-24T04:24:00+00:00","article_modified_time":"2026-04-27T17:24:46+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/06\/life_dark_river-432893F7EFD_1920x1080.jpeg","type":"image\/jpeg"}],"author":"Expert-Only","twitter_card":"summary_large_image","twitter_creator":"@expert_only","twitter_site":"@expert_only","twitter_misc":{"Written by":"Expert-Only","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#article","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/"},"author":{"name":"Expert-Only","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef"},"headline":"Manage SQL Server temp tables using T-SQL code","datePublished":"2026-04-24T04:24:00+00:00","dateModified":"2026-04-27T17:24:46+00:00","mainEntityOfPage":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/"},"wordCount":2211,"commentCount":0,"publisher":{"@id":"https:\/\/expert-only.com\/en\/#organization"},"image":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/06\/life_dark_river-432893F7EFD_1920x1080.jpeg","articleSection":["T-SQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/","url":"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/","name":"SQL Server Temp Table : Create, Drop & Manage - T-SQL","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#primaryimage"},"image":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/06\/life_dark_river-432893F7EFD_1920x1080.jpeg","datePublished":"2026-04-24T04:24:00+00:00","dateModified":"2026-04-27T17:24:46+00:00","description":"Learn how to create, drop and manage SQL Server temp tables (local # and global ##) with T-SQL. Step-by-step use case with multiple temporary tables.","breadcrumb":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#primaryimage","url":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/06\/life_dark_river-432893F7EFD_1920x1080.jpeg","contentUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/06\/life_dark_river-432893F7EFD_1920x1080.jpeg","width":1920,"height":1080},{"@type":"BreadcrumbList","@id":"https:\/\/expert-only.com\/en\/t-sql\/manage-sql-server-temporary-tables\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"en","item":"https:\/\/expert-only.com\/en\/"},{"@type":"ListItem","position":2,"name":"Manage SQL Server temp tables using T-SQL code"}]},{"@type":"WebSite","@id":"https:\/\/expert-only.com\/en\/#website","url":"https:\/\/expert-only.com\/en\/","name":"SQL and IT Tutorials","description":"","publisher":{"@id":"https:\/\/expert-only.com\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/expert-only.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/expert-only.com\/en\/#organization","name":"Expert-Only","url":"https:\/\/expert-only.com\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/","url":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg","contentUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg","width":381,"height":174,"caption":"Expert-Only"},"image":{"@id":"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/ExpertOnlyCom\/","https:\/\/x.com\/expert_only","https:\/\/www.youtube.com\/channel\/UCMS5sR_FwAetB0FmciNvUaA"]},{"@type":"Person","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef","name":"Expert-Only","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/7e711e54a9f31bf0cc5e241d2149474e14ce3995669e683ae9e913aa93cd8da1?s=96&d=identicon&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/7e711e54a9f31bf0cc5e241d2149474e14ce3995669e683ae9e913aa93cd8da1?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/7e711e54a9f31bf0cc5e241d2149474e14ce3995669e683ae9e913aa93cd8da1?s=96&d=identicon&r=g","caption":"Expert-Only"}}]}},"_links":{"self":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/10201","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/comments?post=10201"}],"version-history":[{"count":5,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/10201\/revisions"}],"predecessor-version":[{"id":31138,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/10201\/revisions\/31138"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media\/5833"}],"wp:attachment":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media?parent=10201"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/categories?post=10201"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/tags?post=10201"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}