Skip to content

Commit 1baf093

Browse files
committed
Edit pass
1 parent e9fa154 commit 1baf093

File tree

1 file changed

+41
-70
lines changed

1 file changed

+41
-70
lines changed
Lines changed: 41 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
---
22
title: "SET TEXTSIZE (Transact-SQL)"
3-
description: SET TEXTSIZE (Transact-SQL)
3+
description: Specifies the size, in bytes, of various data types returned to the client by a SELECT statement.
44
author: WilliamDAssafMSFT
55
ms.author: wiassaf
6-
ms.date: "04/12/2016"
6+
ms.reviewer: randolphwest
7+
ms.date: 04/17/2025
78
ms.service: sql
89
ms.subservice: t-sql
910
ms.topic: reference
@@ -20,77 +21,47 @@ helpviewer_keywords:
2021
- "text size returned [SQL Server]"
2122
dev_langs:
2223
- "TSQL"
23-
monikerRange: ">=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current"
24+
monikerRange: ">=aps-pdw-2016 || =azuresqldb-current || =azure-sqldw-latest || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current"
2425
---
2526
# SET TEXTSIZE (Transact-SQL)
27+
2628
[!INCLUDE [sql-asdb-asdbmi-asa-pdw](../../includes/applies-to-version/sql-asdb-asdbmi-asa-pdw.md)]
2729

28-
Specifies the size, in bytes, of **varchar(max)**, **nvarchar(max)**, **varbinary(max)**, **text**, **ntext**, and **image** data returned to the client by a SELECT statement.
29-
30-
> [!IMPORTANT]
31-
> **ntext**, **text**, and **image** data types will be removed in a future version of [!INCLUDE[msCoName](../../includes/msconame-md.md)] [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)]. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use **nvarchar(max)**, **varchar(max)**, and **varbinary(max)** instead.
32-
33-
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: [Transact-SQL syntax conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md)
34-
35-
## Syntax
36-
30+
Specifies the size, in bytes, of **varchar(max)**, **nvarchar(max)**, **varbinary(max)**, **text**, **ntext**, and **image** data returned to the client by a `SELECT` statement.
31+
32+
> [!IMPORTANT]
33+
> **ntext**, **text**, and **image** data types will be removed in a future version of [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)]. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use **nvarchar(max)**, **varchar(max)**, and **varbinary(max)** instead.
34+
35+
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: [Transact-SQL syntax conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md)
36+
37+
## Syntax
38+
3739
```syntaxsql
38-
SET TEXTSIZE { number }
39-
```
40-
40+
SET TEXTSIZE { number }
41+
```
42+
4143
## Arguments
42-
*number*
43-
Is the length of **varchar(max)**, **nvarchar(max)**, **varbinary(max)**, **text**, **ntext**, or **image** data, in bytes. *number* is an integer with a maximum value of 2147483647 (2 GB). A value of -1 indicates unlimited size. A value of 0 resets the size to the default value of 4 KB.
44-
45-
The [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] Native Client (10.0 and higher) and ODBC Driver for [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] automatically specify `-1` (unlimited) when connecting.
46-
47-
**Drivers older than [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] 2008:** The [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] Native Client ODBC driver and [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] Native Client OLE DB Provider (version 9) for [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] automatically set TEXTSIZE to 2147483647 when connecting.
48-
49-
## Remarks
50-
Setting SET TEXTSIZE affects the @@TEXTSIZE function.
51-
52-
The setting of set TEXTSIZE is set at execute or run time and not at parse time.
53-
54-
### Impacts on `sp_executesql` and `EXECUTE` Statements
55-
The `TEXTSIZE` setting affects the result of dynamic statements executed by [sp_executesql (Transact-SQL)](../../relational-databases/system-stored-procedures/sp-executesql-transact-sql.md) or [EXECUTE (Transact-SQL)](../../t-sql/language-elements/execute-transact-sql.md), especially when the result is inserted into a table.
56-
57-
Consider the following example:
58-
59-
```sql
60-
SET TEXTSIZE -1;
61-
62-
DROP TABLE IF EXISTS #TestTextSize;
63-
CREATE TABLE #TestTextSize(txt varchar(5))
64-
65-
SET TEXTSIZE 2;
66-
67-
INSERT INTO #TestTextSize
68-
SELECT CONVERT(text,'12345')
69-
70-
INSERT INTO #TestTextSize
71-
EXEC('SELECT CONVERT(text,''12345'')')
72-
73-
SELECT * FROM #TestTextSize
74-
```
75-
76-
[!INCLUDE[ssResult](../../includes/ssresult-md.md)]
77-
78-
```
79-
txt
80-
-------
81-
12345
82-
12
83-
```
84-
85-
Note that regardless of the target table's correct data type, SQL truncates the text before insertion due to the `TEXTSIZE` setting. When using SQL Server Agent Jobs that runs `EXEC` or `sp_executesql`, you must be cautious. SQL Server Agent modifies the default value of `TEXTSIZE`, which could lead to unexpected behavior. For example, queries may work fine in SQL Server Management Studio but fail when executed through SQL Agent, especially when working with certain text columns that exceed the size. To prevent this issue, ensure you add `SET TEXTSIZE` to the query that the job runs, explicitly defining the desired text size to avoid truncation
86-
87-
88-
## Permissions
89-
Requires membership in the **public** role.
90-
91-
## See Also
92-
[@@TEXTSIZE (Transact-SQL)](../../t-sql/functions/textsize-transact-sql.md)
93-
[Data Types (Transact-SQL)](../../t-sql/data-types/data-types-transact-sql.md)
94-
[SET Statements (Transact-SQL)](../../t-sql/statements/set-statements-transact-sql.md)
95-
96-
44+
45+
#### *number*
46+
47+
The length of **varchar(max)**, **nvarchar(max)**, **varbinary(max)**, **text**, **ntext**, or **image** data, in bytes. *number* is an integer with a maximum value of `2147483647` (2 GB). A value of `-1` indicates unlimited size. A value of `0` resets the size to the default value of 4 KB.
48+
49+
The [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] Native Client (10.0 and higher) and ODBC Driver for [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] automatically specify `-1` (unlimited) when connecting.
50+
51+
## Remarks
52+
53+
Setting `SET TEXTSIZE` affects the `@@TEXTSIZE` function.
54+
55+
The setting of set `TEXTSIZE` is set at execute or run time and not at parse time.
56+
57+
For more information, see [Manage Transact-SQL job steps](/ssms/agent/manage-job-steps#transact-sql-job-steps).
58+
59+
## Permissions
60+
61+
Requires membership in the **public** role.
62+
63+
## Related content
64+
65+
- [@@TEXTSIZE (Transact-SQL)](../functions/textsize-transact-sql.md)
66+
- [Data types (Transact-SQL)](../data-types/data-types-transact-sql.md)
67+
- [SET Statements (Transact-SQL)](set-statements-transact-sql.md)

0 commit comments

Comments
 (0)