|
|
Posted on 9/9/2023 9:36:22 AM
|
|
|
|

Requirements: If there is a field in the project that does not perform where and order queries, it can be stored using nvarchar(max) and varbinary(max) data types, and you need to consider the storage size, query speed, and transmission size.
ntext, text, and image
The ntext, text, and image data types will be removed in future releases. Avoid using these data types in new development efforts, and consider modifying applications that currently use these data types.Use nvarchar(max), varchar(max), and varbinary(max) instead. 。
varbinary [ ( n | max ) ]
Variable-length binary data. n has a value range of 1 to 8,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size is the actual length of the data entered + 2 bytes. The length of the entered data can be 0 bytes. The ANSI SQL synonym for varbinary is binary varying.
Documentation:The hyperlink login is visible.
nvarchar [ ( n | max ) ]
Variable-size string data. n is used to define the string size (in double bytes), and it can be a value between 1 and 4,000. max indicates that the maximum storage size is 2^31-1 character (2 GB). The storage size is twice as large as n bytes + 2 bytes. For UCS-2 encoding, the storage size is twice as many as n bytes + 2 bytes, and the number of characters that can be stored is also n. For UTF-16 encoding, the storage size is still twice as many bytes as n bytes + 2 bytes, but the number of characters that can be stored may be less than n because supplementary characters use two double bytes (also known as proxy item pairs). ISO synonyms for nvarchar are national char varying and national character varying.
Documentation:The hyperlink login is visible.
New table
Database version: Microsoft SQL Server 2019 (RTM) - 15.0.2000.5 (X64) Sep 24 2019 13:48:23 Copyright (C) 2019 Microsoft Corporation Enterprise Edition (64-bit)
Create two new tables, the fields are stored with nvarchar(max) and varbinary(max) data types, and the script is as follows:
Create a new console application based on .NET 6
To create a console application, you need to reference Microsoft.Data.SqlClient, the code is as follows:
Inserted separatelyThe same 300,000 pieces of data, the query is as follows:
Check the occupied storage space as shown in the following figure:
You can see thatnvarchar(max) type32.555 MB, the varbinary(max) type is occupied18.602 MB。
|
Previous:National Bank Xbox Series X unlocking cross-region tutorialNext:SQL Server searches for specified content across all stored procedures, functions, and views
|