如何创建列数超过 1024 列的 Table 类型
How to create a Table Type with columns more than 1024 columns
我想创建一个 table 类型,它应该有超过 1024 列。因此,我尝试通过创建 - SpecialPurposeColumns XML COLUMN_SET 来使用稀疏列,如下所示。那没有用。它给了我一个错误:Incorrect syntax near 'COLUMN_SET'
CREATE TYPE dbo.TempTable AS TABLE (
ID INT IDENTITY(1,1),
SpecialPurposeColumns XML COLUMN_SET FOR ALL_SPARSE_COLUMNS,
col1 VARCHAR(10) SPARSE NULL,
col2 VARCHAR(10) SPARSE NULL,
.
.
col1025 VARCHAR(10) SPARSE NULL);
有什么方法可以创建一个 table 类型,它可以包含超过 1024 列?
来自Restrictions for Using Sparse Columns:
Restrictions for Using Sparse Columns
Sparse columns can be of any SQL Server data type and behave like any other column with the following restrictions:
- ...
- A sparse column cannot be part of a user-defined table type, which are used in table variables and table-valued parameters.
因此您不能在 table 类型对象中使用 SPARSE
列。
至于拥有超过 1,024 列,不,你不能。来自 Maximum capacity specifications for SQL Server:
Database Engine objects
Maximum sizes and numbers of various objects defined in SQL Server databases or referenced in Transact-SQL statements.
SQL Server Database Engine object
Maximum sizes/numbers SQL Server (64-bit)
Additional Information
Columns per table
1,024
Tables that include sparse column sets include up to 30,000 columns. See sparse column sets.
显然,“查看稀疏列集”在这里不相关,因为它们不受支持(如上所述)。
但是,如果您“需要”这么多列,那么您很可能确实存在设计缺陷;可能遭受严重的反规范化。
我想创建一个 table 类型,它应该有超过 1024 列。因此,我尝试通过创建 - SpecialPurposeColumns XML COLUMN_SET 来使用稀疏列,如下所示。那没有用。它给了我一个错误:Incorrect syntax near 'COLUMN_SET'
CREATE TYPE dbo.TempTable AS TABLE (
ID INT IDENTITY(1,1),
SpecialPurposeColumns XML COLUMN_SET FOR ALL_SPARSE_COLUMNS,
col1 VARCHAR(10) SPARSE NULL,
col2 VARCHAR(10) SPARSE NULL,
.
.
col1025 VARCHAR(10) SPARSE NULL);
有什么方法可以创建一个 table 类型,它可以包含超过 1024 列?
来自Restrictions for Using Sparse Columns:
Restrictions for Using Sparse Columns
Sparse columns can be of any SQL Server data type and behave like any other column with the following restrictions:
- ...
- A sparse column cannot be part of a user-defined table type, which are used in table variables and table-valued parameters.
因此您不能在 table 类型对象中使用 SPARSE
列。
至于拥有超过 1,024 列,不,你不能。来自 Maximum capacity specifications for SQL Server:
Database Engine objects
Maximum sizes and numbers of various objects defined in SQL Server databases or referenced in Transact-SQL statements.
SQL Server Database Engine object Maximum sizes/numbers SQL Server (64-bit) Additional Information Columns per table 1,024 Tables that include sparse column sets include up to 30,000 columns. See sparse column sets.
显然,“查看稀疏列集”在这里不相关,因为它们不受支持(如上所述)。
但是,如果您“需要”这么多列,那么您很可能确实存在设计缺陷;可能遭受严重的反规范化。