ntext (Transact‑SQL)
ntext
data type is deprecated and will be removed in a future version of SQL Server. Use nvarchar(max)
instead.
Overview
The ntext
data type stores large Unicode text data up to 2^30‑1 (1,073,741,823) characters. It was originally intended for storing massive blocks of text such as articles, comments, or HTML markup.
Syntax
column_name ntext [NULL | NOT NULL]
Storage
- Stored as out‑of‑row data when size exceeds 8 KB.
- Maximum storage size: 1 GB.
- Cannot be indexed directly; use full‑text indexes.
Example: Creating a Table
CREATE TABLE Articles
(
ArticleID INT IDENTITY PRIMARY KEY,
Title NVARCHAR(200) NOT NULL,
Content ntext NULL
);
Example: Inserting Data
INSERT INTO Articles (Title, Content)
VALUES (N'Azure Migration',
N'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ...');
Example: Selecting Data
SELECT ArticleID, Title, CAST(Content AS NVARCHAR(MAX)) AS Content
FROM Articles
WHERE ArticleID = 1;
ntext
to other string types, use CAST(... AS NVARCHAR(MAX))
or CONVERT(..., 1)
.