Skip to content

Commit 6991f9f

Browse files
20251013 temp table support for time travel (#35555)
* 20251013 temp table support for time travel * Update tables.md * Update hints-transact-sql-query.md --------- Co-authored-by: v-ccolin <72402153+v-ccolin@users.noreply.github.com>
1 parent 5f5f043 commit 6991f9f

2 files changed

Lines changed: 51 additions & 39 deletions

File tree

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,106 @@
11
---
22
title: "Tables"
3-
description: "Tables"
3+
description: "Learn more about tables in the SQL Database Engine."
44
author: WilliamDAssafMSFT
55
ms.author: wiassaf
6-
ms.date: 09/18/2019
6+
ms.date: 10/13/2025
77
ms.service: sql
88
ms.subservice: table-view-index
99
ms.topic: conceptual
1010
helpviewer_keywords:
1111
- "tables [SQL Server]"
1212
- "table components [SQL Server]"
13-
monikerRange: ">=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current||=fabric"
13+
monikerRange: ">=aps-pdw-2016 || =azuresqldb-current || =azure-sqldw-latest || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric"
1414
---
1515
# Tables
16-
[!INCLUDE [sqlserver2016-asdb-asdbmi-asa-pdw-fabricsqldb](../../includes/applies-to-version/sqlserver2016-asdb-asdbmi-asa-pdw-fabricsqldb.md)]
16+
17+
[!INCLUDE [sqlserver2016-asdb-asdbmi-asa-pdw-fabricse-fabricdw-fabricsqldb](../../includes/applies-to-version/sqlserver2016-asdb-asdbmi-asa-pdw-fabricse-fabricdw-fabricsqldb.md)]
1718

1819
Tables are database objects that contain all the data in a database. In tables, data is logically organized in a row-and-column format similar to a spreadsheet. Each row represents a unique record, and each column represents a field in the record. For example, a table that contains employee data for a company might contain a row for each employee and columns representing employee information such as employee number, name, address, job title, and home telephone number.
1920

2021
- The number of tables in a database is limited only by the number of objects allowed in a database (2,147,483,647). A standard user-defined table can have up to 1,024 columns. The number of rows in the table is limited only by the storage capacity of the server.
2122

2223
- You can assign properties to the table and to each column in the table to control the data that is allowed and other properties. For example, you can create constraints on a column to disallow null values or provide a default value if a value is not specified, or you can assign a key constraint on the table that enforces uniqueness or defines a relationship between tables.
2324

24-
- The data in the table can be compressed either by row or by page. Data compression can allow more rows to be stored on a page. For more information, see [Data Compression](../../relational-databases/data-compression/data-compression.md).
25+
- The data in the table can be compressed either by row or by page. Data compression can allow more rows to be stored on a page. For more information, see [Data compression](../data-compression/data-compression.md).
26+
27+
## Types of tables
2528

26-
## Types of Tables
2729
Besides the standard role of basic user-defined tables, [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] provides the following types of tables that serve special purposes in a database.
2830

29-
### Partitioned Tables
31+
### Partitioned tables
32+
33+
Partitioned tables are tables whose data is horizontally divided into units which might be spread across more than one filegroup in a database. Partitioning makes large tables or indexes more manageable by letting you access or manage subsets of data quickly and efficiently, while maintaining the integrity of the overall collection. By default, [!INCLUDE[ssnoversion](../../includes/ssnoversion-md.md)] supports up to 15,000 partitions. For more information, see [Partitioned tables and indexes](../partitions/partitioned-tables-and-indexes.md).
3034

31-
Partitioned tables are tables whose data is horizontally divided into units which may be spread across more than one filegroup in a database. Partitioning makes large tables or indexes more manageable by letting you access or manage subsets of data quickly and efficiently, while maintaining the integrity of the overall collection. By default, [!INCLUDE[ssnoversion](../../includes/ssnoversion-md.md)] supports up to 15,000 partitions. For more information, see [Partitioned Tables and Indexes](../../relational-databases/partitions/partitioned-tables-and-indexes.md).
35+
### Temporary tables
3236

33-
### Temporary Tables
37+
Temporary tables are stored in `tempdb`. There are two types of temporary tables: **local** and **global**. They differ from each other in their names, their visibility, and their availability.
3438

35-
Temporary tables are stored in **tempdb**. There are two types of temporary tables: local and global. They differ from each other in their names, their visibility, and their availability. Local temporary tables have a single number sign (#) as the first character of their names; they are visible only to the current connection for the user, and they are deleted when the user disconnects from the instance of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)]. Global temporary tables have two number signs (##) as the first characters of their names; they are visible to any user after they are created, and they are deleted when all users referencing the table disconnect from the instance of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)].
39+
- Local temporary tables, also known as session-scoped temporary tables, have a single number sign (`#`) as the first character of their names; they are visible only to the current connection for the user, and they are deleted when the user disconnects from the instance of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)].
40+
- Global temporary tables have two number signs (`##`) as the first characters of their names; they are visible to any user after they are created, and they are deleted when all users referencing the table disconnect from the instance of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)].
3641

42+
In Fabric Data Warehouse, only session-scoped temp tables are supported, and are not affected by [Time travel hints](/fabric/data-warehouse/time-travel).
3743

38-
#### <a name="ctp23"></a> Reduced recompilations for workloads using temporary tables across multiple scopes
44+
<a id="ctp23"></a>
3945

40-
[!INCLUDE[ss2019](../../includes/sssql19-md.md)] under all database compatibility levels reduces recompilations for workloads using temporary tables across multiple scopes. This feature is also enabled in Azure SQL Database under database compatibility level 150 for all deployment models. Prior to this feature, when referencing a temporary table with a data manipulation language (DML) statement (`SELECT`, `INSERT`, `UPDATE`, `DELETE`), if the temporary table was created by an outer scope batch, this would result in a recompile of the DML statement each time it is executed. With this improvement, SQL Server performs additional lightweight checks to avoid unnecessary recompilations:
46+
#### Reduced recompilations for workloads using temporary tables across multiple scopes
47+
48+
[!INCLUDE[ss2019](../../includes/sssql19-md.md)] under all database compatibility levels reduces recompilations for workloads using temporary tables across multiple scopes. This feature is also enabled in Azure SQL Database under database compatibility level 150 for all deployment models. Prior to this feature, when referencing a temporary table with a data manipulation language (DML) statement (`SELECT`, `INSERT`, `UPDATE`, `DELETE`), if the temporary table was created by an outer scope batch, this would result in a recompile of the DML statement each time it is executed. With this improvement, SQL Server performs additional lightweight checks to avoid unnecessary recompilations:
4149

4250
- Check if the outer-scope module used for creating the temporary table at compile time is the same one used for consecutive executions.
4351
- Keep track of any data definition language (DDL) changes made at initial compilation and compare them with DDL operations for consecutive executions.
4452

4553
The end result is a reduction in extraneous recompilations and CPU-overhead.
4654

47-
### System Tables
55+
### System tables
56+
57+
[!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] stores the data that defines the configuration of the server and all its tables in a special set of tables known as system tables. Users cannot directly query or update the system tables. The information in the system tables is made available through the system views. For a list, see [System Tables (Transact-SQL)](../system-tables/system-tables-transact-sql.md).
4858

49-
[!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] stores the data that defines the configuration of the server and all its tables in a special set of tables known as system tables. Users cannot directly query or update the system tables. The information in the system tables is made available through the system views. For more information, see [System Views &#40;Transact-SQL&#41;](../../t-sql/language-reference.md).
50-
51-
### Wide Tables
59+
### Wide tables
5260

53-
Wide tables use [sparse columns](../../relational-databases/tables/use-sparse-columns.md) to increase the total of columns that a table can have to 30,000. Sparse columns are ordinary columns that have an optimized storage for null values. Sparse columns reduce the space requirements for null values at the cost of more overhead to retrieve nonnull values. A wide table has defined a [column set](../../relational-databases/tables/use-column-sets.md), which is an untyped XML representation that combines all the sparse columns of a table into a structured output. The number of indexes and statistics is also increased to 1,000 and 30,000, respectively. The maximum size of a wide table row is 8,019 bytes. Therefore, most of the data in any particular row should be NULL. The maximum number of nonsparse columns plus computed columns in a wide table remains 1,024.
61+
Wide tables use [sparse columns](use-sparse-columns.md) to increase the total of columns that a table can have to 30,000. Sparse columns are ordinary columns that have an optimized storage for null values. Sparse columns reduce the space requirements for null values at the cost of more overhead to retrieve nonnull values. A wide table has defined a [column set](use-column-sets.md), which is an untyped XML representation that combines all the sparse columns of a table into a structured output. The number of indexes and statistics is also increased to 1,000 and 30,000, respectively. The maximum size of a wide table row is 8,019 bytes. Therefore, most of the data in any particular row should be `NULL`. The maximum number of nonsparse columns plus computed columns in a wide table remains 1,024.
5462

5563
Wide tables have the following performance implications.
5664

57-
- Wide tables can increase the cost to maintain indexes on the table. We recommend that the number of indexes on a wide table be limited to the indexes that are required by the business logic. As the number of indexes increases, so does the DML compile-time and memory requirement. Nonclustered indexes should be filtered indexes that are applied to data subsets. For more information, see [Create Filtered Indexes](../../relational-databases/indexes/create-filtered-indexes.md).
65+
- Wide tables can increase the cost to maintain indexes on the table. We recommend that the number of indexes on a wide table be limited to the indexes that are required by the business logic. As the number of indexes increases, so does the DML compile-time and memory requirement. Nonclustered indexes should be filtered indexes that are applied to data subsets. For more information, see [Create filtered indexes](../indexes/create-filtered-indexes.md).
5866

5967
- Applications can dynamically add and remove columns from wide tables. When columns are added or removed, compiled query plans are also invalidated. We recommend that you design an application to match the projected workload so that schema changes are minimized.
6068

61-
- When data is added and removed from a wide table, performance can be affected. Applications must be designed for the projected workload so that changes to the table data is minimized.
69+
- When data is added and removed from a wide table, performance can be affected. Applications must be designed for the projected workload so that changes to the table data are minimized.
6270

6371
- Limit the execution of DML statements on a wide table that update multiple rows of a clustering key. These statements can require significant memory resources to compile and execute.
6472

6573
- Switch partition operations on wide tables can be slow and might require large amounts of memory to process. The performance and memory requirements are proportional to the total number of columns in both the source and target partitions.
6674

6775
- Update cursors that update specific columns in a wide table should list the columns explicitly in the FOR UPDATE clause. This will help optimize performance when you use cursors.
6876

69-
## Common Table Tasks
77+
## Common table tasks
78+
7079
The following table provides links to common tasks associated with creating or modifying a table.
7180

7281
|Table Tasks|Topic|
7382
|-----------------|-----------|
74-
|Describes how to create a table.|[Create Tables &#40;Database Engine&#41;](../../relational-databases/tables/create-tables-database-engine.md)|
75-
|Describes how to delete a table.|[Delete Tables &#40;Database Engine&#41;](../../relational-databases/tables/delete-tables-database-engine.md)|
76-
|Describes how to create a new table that contains some or all of the columns in an existing table.|[Duplicate Tables](../../relational-databases/tables/duplicate-tables.md)|
77-
|Describes how to rename a table.|[Rename Tables &#40;Database Engine&#41;](../../relational-databases/tables/rename-tables-database-engine.md)|
78-
|Describes how to view the properties of the table.|[View the Table Definition](../../relational-databases/tables/view-the-table-definition.md)|
79-
|Describes how to determine whether other objects such as a view or stored procedure depend on a table.|[View the Dependencies of a Table](../../relational-databases/tables/view-the-dependencies-of-a-table.md)|
83+
| Describes how to create a table. |[Create tables (Database Engine)](create-tables-database-engine.md)|
84+
| Describes how to delete a table. |[Delete Tables (Database Engine)](delete-tables-database-engine.md)|
85+
| Describes how to create a new table that contains some or all of the columns in an existing table. |[Duplicate tables](duplicate-tables.md)|
86+
| Describes how to rename a table. |[Rename tables (Database Engine)](rename-tables-database-engine.md)|
87+
| Describes how to view the properties of the table. |[View the Table Definition](view-the-table-definition.md)|
88+
| Describes how to determine whether other objects such as a view or stored procedure depend on a table. |[View the dependencies of a table](view-the-dependencies-of-a-table.md)|
8089

8190
The following table provides links to common tasks associated with creating or modifying columns in a table.
8291

8392
|Column Tasks|Topic|
8493
|------------------|-----------|
85-
|Describes how to add columns to an existing table.|[Add Columns to a Table &#40;Database Engine&#41;](../../relational-databases/tables/add-columns-to-a-table-database-engine.md)|
86-
|Describes how to delete columns from a table.|[Delete Columns from a Table](../../relational-databases/tables/delete-columns-from-a-table.md)|
87-
|Describes how to change the name of a column.|[Rename Columns &#40;Database Engine&#41;](../../relational-databases/tables/rename-columns-database-engine.md)|
88-
|Describes how to copy columns from one table to another, copying either just the column definition, or the definition and data.|[Copy Columns from One Table to Another &#40;Database Engine&#41;](../../relational-databases/tables/copy-columns-from-one-table-to-another-database-engine.md)|
89-
|Describes how to modify a column definition, by changing the data type or other property.|[Modify Columns &#40;Database Engine&#41;](../../relational-databases/tables/modify-columns-database-engine.md)|
90-
|Describes how to change the order in which the columns appear.|[Change Column Order in a Table](../../relational-databases/tables/change-column-order-in-a-table.md)|
91-
|Describes how to create a computed column in a table.|[Specify Computed Columns in a Table](../../relational-databases/tables/specify-computed-columns-in-a-table.md)|
92-
|Describes how to specify a default value for a column. This value is used if another value is not supplied.|[Specify Default Values for Columns](../../relational-databases/tables/specify-default-values-for-columns.md)|
93-
94-
## See Also
95-
[Primary and Foreign Key Constraints](../../relational-databases/tables/primary-and-foreign-key-constraints.md)
96-
[Unique Constraints and Check Constraints](../../relational-databases/tables/unique-constraints-and-check-constraints.md)
94+
| Describes how to add columns to an existing table. |[Add Columns to a Table (Database Engine)](add-columns-to-a-table-database-engine.md)|
95+
| Describes how to delete columns from a table. |[Delete columns from a table](delete-columns-from-a-table.md)|
96+
| Describes how to change the name of a column. |[Rename columns (Database Engine)](rename-columns-database-engine.md)|
97+
| Describes how to copy columns from one table to another, copying either just the column definition, or the definition and data. |[Copy Columns from One Table to Another (Database Engine)](copy-columns-from-one-table-to-another-database-engine.md)|
98+
| Describes how to modify a column definition, by changing the data type or other property. |[Modify columns](modify-columns-database-engine.md)|
99+
| Describes how to change the order in which the columns appear. |[Change Column Order in a Table](change-column-order-in-a-table.md)|
100+
| Describes how to create a computed column in a table. |[Specify computed columns in a table](specify-computed-columns-in-a-table.md)|
101+
| Describes how to specify a default value for a column. This value is used if another value is not supplied. |[Specify default values for columns](specify-default-values-for-columns.md)|
102+
103+
## Related content
104+
105+
- [Primary and foreign key constraints](primary-and-foreign-key-constraints.md)
106+
- [Unique constraints and check constraints](unique-constraints-and-check-constraints.md)

0 commit comments

Comments
 (0)