SQL Server 2025 — Cơ sở dữ liệu AI-ready với Vector Search, JSON gốc và RegEx
Posted on: 4/26/2026 6:13:08 PM
Table of contents
- 1. Vector Data Type — SQL Server trở thành Vector Database
- 2. Native JSON — Không còn là text, đã là first-class citizen
- 3. Regular Expressions trong T-SQL
- 4. Change Event Streaming — CDC thế hệ mới
- 5. REST API tích hợp sẵn
- 6. Fuzzy String Matching — So khớp chuỗi mờ
- 7. Bảo mật Zero Trust
- 8. Hiệu năng — Intelligent Query Processing thế hệ mới
- 9. Edition Changes đáng chú ý
- 10. T-SQL Enhancements khác
- 11. Fabric Mirroring — Cầu nối on-premises và cloud
- 12. MCP Server cho SQL Server
- Kết luận
SQL Server 2025 (phiên bản 17.x) chính thức phát hành vào tháng 11/2025, đánh dấu bước nhảy lớn nhất của nền tảng cơ sở dữ liệu quan hệ của Microsoft trong thập kỷ qua. Không chỉ đơn thuần nâng cấp hiệu năng, phiên bản này mang đến hàng loạt tính năng hoàn toàn mới: vector data type cho AI/ML, native JSON column, Regular Expressions trong T-SQL, Change Event Streaming thời gian thực, và khả năng gọi trực tiếp các mô hình AI từ trong engine. Bài viết này sẽ phân tích sâu từng tính năng quan trọng nhất.
1. Vector Data Type — SQL Server trở thành Vector Database
Tính năng nổi bật nhất của SQL Server 2025 là kiểu dữ liệu vector gốc, cho phép lưu trữ và truy vấn vector embeddings trực tiếp trong database mà không cần dịch vụ bên ngoài.
1.1 Cách sử dụng Vector
-- Tạo bảng với cột vector
CREATE TABLE Products (
Id INT IDENTITY(1,1) PRIMARY KEY,
Name NVARCHAR(200),
Description NVARCHAR(MAX),
Embedding vector(1536) -- 1536 dimensions, tương thích OpenAI text-embedding-3-small
);
-- Insert vector dưới dạng JSON array
INSERT INTO Products (Name, Description, Embedding)
VALUES (
N'Laptop Gaming',
N'Laptop hiệu năng cao cho game thủ',
'[0.0123, -0.0456, 0.0789, ...]' -- 1536 giá trị float
);
Vector được lưu ở định dạng nhị phân tối ưu nhưng hiển thị dưới dạng JSON array. Mỗi phần tử có thể là single-precision (4 byte) hoặc half-precision (2 byte) floating-point.
1.2 Vector Search với DiskANN Index
SQL Server 2025 sử dụng thuật toán DiskANN (Disk-based Approximate Nearest Neighbor) — cùng công nghệ mà Microsoft Research phát triển cho Bing Search — để tìm kiếm vector tương tự với tốc độ cực nhanh.
-- Bật preview features
ALTER DATABASE SCOPED CONFIGURATION SET PREVIEW_FEATURES = ON;
-- Tạo vector index
CREATE VECTOR INDEX IX_Products_Embedding
ON Products(Embedding)
WITH (metric = 'cosine', type = 'diskann');
-- Tìm kiếm 10 sản phẩm tương tự nhất
SELECT TOP 10 p.Name, p.Description,
VECTOR_DISTANCE('cosine', p.Embedding, @queryVector) AS distance
FROM VECTOR_SEARCH(Products, 'IX_Products_Embedding', @queryVector, 10) AS vs
INNER JOIN Products p ON p.Id = vs.Id
ORDER BY distance;
Các hàm vector mới
VECTOR_DISTANCE — tính khoảng cách giữa 2 vector (cosine, euclidean, dot product). VECTOR_NORM — trả về độ dài vector. VECTOR_NORMALIZE — chuẩn hóa vector. VECTORPROPERTY — lấy thuộc tính (số chiều, kiểu dữ liệu).
1.3 Tích hợp AI Models trực tiếp
SQL Server 2025 cho phép định nghĩa external AI models ngay trong database, sau đó gọi trực tiếp để tạo embeddings hoặc generate text:
-- Định nghĩa model AI
CREATE EXTERNAL MODEL EmbeddingModel
WITH (
MODEL_TYPE = EMBEDDINGS,
LOCATION = 'https://your-openai.openai.azure.com/',
API_KEY = 'your-api-key',
DEPLOYMENT = 'text-embedding-3-small'
);
-- Tạo embeddings trực tiếp trong T-SQL
SELECT AI_GENERATE_EMBEDDINGS(EmbeddingModel, Description)
FROM Products
WHERE Embedding IS NULL;
-- Chunk text lớn trước khi tạo embedding
SELECT * FROM AI_GENERATE_CHUNKS(
'sentence', -- chunk type
512, -- chunk size
LongDescription
) AS chunks;
graph LR
A[Dữ liệu văn bản] --> B[AI_GENERATE_CHUNKS]
B --> C[Text Chunks]
C --> D[AI_GENERATE_EMBEDDINGS]
D --> E[Vector Embeddings]
E --> F[Vector Index - DiskANN]
F --> G[VECTOR_SEARCH]
G --> H[Kết quả tương tự]
style A fill:#f8f9fa,stroke:#e94560,color:#2c3e50
style F fill:#e94560,stroke:#fff,color:#fff
style H fill:#4CAF50,stroke:#fff,color:#fff
2. Native JSON — Không còn là text, đã là first-class citizen
SQL Server 2025 giới thiệu kiểu dữ liệu json gốc, lưu trữ ở định dạng nhị phân tối ưu thay vì text thuần như các phiên bản trước. Dung lượng tối đa lên đến 2GB mỗi row.
-- Sử dụng kiểu JSON gốc
CREATE TABLE Orders (
Id INT IDENTITY(1,1) PRIMARY KEY,
OrderData json, -- kiểu JSON native, không còn NVARCHAR(MAX)
CreatedAt DATETIME2 DEFAULT GETUTCDATE()
);
-- Insert JSON
INSERT INTO Orders (OrderData)
VALUES ('{"customer":"Anh Tu","items":[{"sku":"LAP001","qty":1,"price":25000000}],"total":25000000}');
-- Truy vấn JSON với path expressions
SELECT
JSON_VALUE(OrderData, '$.customer') AS Customer,
JSON_VALUE(OrderData, '$.total') AS Total,
JSON_QUERY(OrderData, '$.items') AS Items
FROM Orders;
2.1 JSON Aggregation Functions
Hai hàm aggregate mới cho phép xây dựng JSON trực tiếp từ kết quả truy vấn:
-- JSON_OBJECTAGG — tạo JSON object từ aggregation
SELECT JSON_OBJECTAGG(CategoryName : ProductCount)
FROM (
SELECT c.Name AS CategoryName, COUNT(*) AS ProductCount
FROM Products p
JOIN Categories c ON p.CategoryId = c.Id
GROUP BY c.Name
) sub;
-- Kết quả: {"Electronics":42,"Clothing":28,"Books":15}
-- JSON_ARRAYAGG — tạo JSON array từ aggregation
SELECT JSON_ARRAYAGG(Name ORDER BY Price DESC)
FROM Products
WHERE CategoryId = 1;
-- Kết quả: ["MacBook Pro","ThinkPad X1","Dell XPS 15"]
Hiệu năng JSON gốc
Kiểu json native lưu ở định dạng nhị phân, giúp truy vấn nhanh hơn đáng kể so với NVARCHAR(MAX) + JSON_VALUE() truyền thống. Không cần parse text mỗi lần truy vấn — engine đọc trực tiếp từ binary representation.
3. Regular Expressions trong T-SQL
Sau hàng thập kỷ được cộng đồng yêu cầu, SQL Server 2025 cuối cùng đã tích hợp 7 hàm RegEx trực tiếp vào T-SQL, loại bỏ nhu cầu dùng CLR functions hoặc xử lý ngoài database.
| Hàm | Mô tả | Ví dụ |
|---|---|---|
REGEXP_LIKE | Kiểm tra pattern có match không | REGEXP_LIKE(Email, '^[a-z]+@[a-z]+\.[a-z]{2,}$') |
REGEXP_REPLACE | Thay thế theo pattern | REGEXP_REPLACE(Phone, '[^0-9]', '') |
REGEXP_SUBSTR | Trích xuất chuỗi con | REGEXP_SUBSTR(Log, '\d{4}-\d{2}-\d{2}') |
REGEXP_INSTR | Vị trí của match | REGEXP_INSTR(Text, 'error|warning', 1, 1) |
REGEXP_COUNT | Đếm số lần match | REGEXP_COUNT(Content, '\bhttps?://\S+') |
REGEXP_MATCHES | Trả về bảng các captured groups | REGEXP_MATCHES(Html, '<a href="([^"]+)">') |
REGEXP_SPLIT_TO_TABLE | Tách chuỗi theo pattern thành bảng | REGEXP_SPLIT_TO_TABLE(CSV, ',\s*') |
-- Validate email format
SELECT * FROM Users
WHERE REGEXP_LIKE(Email, '^[\w.+-]+@[\w-]+\.[\w.]+$');
-- Trích xuất tất cả số điện thoại từ văn bản
SELECT value AS PhoneNumber
FROM Contacts
CROSS APPLY REGEXP_MATCHES(Notes, '(\+?\d{1,3}[-.\s]?\(?\d{1,4}\)?[-.\s]?\d{1,4}[-.\s]?\d{1,9})');
-- Làm sạch dữ liệu — loại bỏ HTML tags
UPDATE Articles
SET PlainText = REGEXP_REPLACE(HtmlContent, '<[^>]+>', '');
4. Change Event Streaming — CDC thế hệ mới
Change Event Streaming (CES) là tính năng hoàn toàn mới, cho phép stream thay đổi dữ liệu (DML) theo thời gian thực đến Azure Event Hubs ở dạng CloudEvent (JSON hoặc Avro Binary). Đây là bước tiến lớn so với Change Data Capture (CDC) truyền thống.
sequenceDiagram
participant App as Ứng dụng
participant SQL as SQL Server 2025
participant CES as Change Event Streaming
participant EH as Azure Event Hubs
participant Consumer as Downstream Services
App->>SQL: INSERT/UPDATE/DELETE
SQL->>CES: Capture change events
CES->>EH: Publish CloudEvent (JSON/Avro)
EH->>Consumer: Stream to consumers
Note over CES,EH: Near real-time, có cả old + new values
So sánh CES vs CDC truyền thống
CDC lưu thay đổi vào bảng nội bộ, consumer phải poll để đọc. CES push trực tiếp đến Event Hubs, bao gồm cả giá trị trước và sau thay đổi, dạng CloudEvent chuẩn. CES phù hợp cho kiến trúc event-driven, real-time analytics, và đồng bộ cross-system.
5. REST API tích hợp sẵn
SQL Server 2025 có thể gọi REST endpoints từ bên trong engine thông qua sp_invoke_external_rest_endpoint, mở ra khả năng tích hợp trực tiếp với các dịch vụ bên ngoài mà không cần middleware:
-- Gọi Azure OpenAI từ SQL Server
DECLARE @response NVARCHAR(MAX);
EXEC sp_invoke_external_rest_endpoint
@url = 'https://your-resource.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2024-02-15-preview',
@method = 'POST',
@headers = '{"api-key":"your-api-key"}',
@payload = '{"messages":[{"role":"user","content":"Phân loại sản phẩm này: Laptop Dell XPS 15"}]}',
@response = @response OUTPUT;
-- Gọi Azure Function để xử lý logic
EXEC sp_invoke_external_rest_endpoint
@url = 'https://your-func.azurewebsites.net/api/ProcessOrder',
@method = 'POST',
@payload = '{"orderId": 12345}';
6. Fuzzy String Matching — So khớp chuỗi mờ
Bốn hàm mới cho phép tìm kiếm gần đúng, đặc biệt hữu ích cho việc deduplicate dữ liệu và tìm kiếm linh hoạt:
-- Tìm tên khách hàng tương tự (typo tolerance)
SELECT c1.Name, c2.Name,
EDIT_DISTANCE(c1.Name, c2.Name) AS EditDist,
JARO_WINKLER_SIMILARITY(c1.Name, c2.Name) AS Similarity
FROM Customers c1
CROSS JOIN Customers c2
WHERE c1.Id < c2.Id
AND JARO_WINKLER_SIMILARITY(c1.Name, c2.Name) > 85;
-- Kết quả: "Nguyen Van A" vs "Nguyên Văn A" → Similarity = 92
7. Bảo mật Zero Trust
SQL Server 2025 nâng cấp đáng kể về bảo mật với triết lý Zero Trust:
- PBKDF2 mặc định — Password hash dùng PBKDF2 thay vì SHA-512, tuân thủ NIST SP 800-63b
- TLS 1.3 + TDS 8.0 — Mã hóa kết nối mạnh nhất, áp dụng cho tất cả: replication, linked servers, log shipping, PolyBase, Always On
- Microsoft Entra ID — Managed identity cho kết nối outbound (đến Azure Blob, Key Vault) và inbound (external users)
- OAEP Padding — RSA encryption dùng OAEP thay vì PKCS#1 v1.5 cũ
- Custom password policy trên Linux — Enforce policy cho SQL auth logins trên Linux
8. Hiệu năng — Intelligent Query Processing thế hệ mới
graph TD
A[Intelligent Query Processing] --> B[CE Feedback cho Expressions]
A --> C[Optional Parameter Plan - OPPO]
A --> D[DOP Feedback - mặc định ON]
A --> E[Query Store trên Secondary]
A --> F[ABORT_QUERY_EXECUTION hint]
B --> B1[Học từ lần chạy trước
Tự chọn CE model phù hợp]
C --> C1[Multi-plan cho cùng query
Chọn plan theo parameter value]
D --> D1[Tự điều chỉnh parallelism
Dựa trên workload thực tế]
style A fill:#e94560,stroke:#fff,color:#fff
style B fill:#f8f9fa,stroke:#e94560,color:#2c3e50
style C fill:#f8f9fa,stroke:#e94560,color:#2c3e50
style D fill:#f8f9fa,stroke:#e94560,color:#2c3e50
style E fill:#f8f9fa,stroke:#e94560,color:#2c3e50
style F fill:#f8f9fa,stroke:#e94560,color:#2c3e50
8.1 Các cải tiến Engine khác
| Tính năng | Chi tiết | Lợi ích |
|---|---|---|
| Optimized Locking | Giảm blocking và lock memory | Tránh lock escalation, throughput cao hơn |
| ZSTD Backup Compression | Thuật toán nén ZSTD thay vì LZ77 | Nhanh hơn, tỉ lệ nén tốt hơn |
| Tempdb Governance | Resource Governor quản lý tempdb space | Tránh workload chạy tràn tempdb gây outage |
| Optimized sp_executesql | Serialize compilation cho dynamic SQL | Giảm compilation storms |
| Columnstore Improvements | Ordered nonclustered, online build | Queries analytics nhanh hơn đáng kể |
| ADR in Tempdb | Accelerated Database Recovery cho tempdb | Recovery nhanh cho temp table transactions |
9. Edition Changes đáng chú ý
Express Edition — 50GB, gấp 5 lần
SQL Server Express 2025 nâng giới hạn database từ 10GB lên 50GB, đồng thời bao gồm tất cả features trước đây chỉ có trong Express with Advanced Services. Phiên bản Web Edition bị khai tử. Standard Edition nâng lên tối đa 32 cores và 256GB buffer pool.
10. T-SQL Enhancements khác
-- String concatenation với || (ANSI standard)
SELECT FirstName || ' ' || LastName AS FullName FROM Users;
-- SUBSTRING không cần length (mặc định đến hết chuỗi)
SELECT SUBSTRING(Email, CHARINDEX('@', Email) + 1) AS Domain FROM Users;
-- DATEADD hỗ trợ bigint
SELECT DATEADD(MILLISECOND, CAST(9999999999 AS BIGINT), '2020-01-01');
-- UNISTR cho Unicode encoding
SELECT UNISTR('Xin ch\00E0o Vi\1EC7t Nam'); -- "Xin chào Việt Nam"
-- PRODUCT aggregate
SELECT CategoryId, PRODUCT(Multiplier) AS CumulativeMultiplier
FROM Adjustments
GROUP BY CategoryId;
-- BASE64 encoding/decoding
SELECT BASE64_ENCODE(CAST('Hello SQL Server 2025' AS VARBINARY(MAX)));
SELECT CAST(BASE64_DECODE('SGVsbG8gU1FMIFNlcnZlciAyMDI1') AS VARCHAR(MAX));
-- CURRENT_DATE (ANSI standard)
SELECT CURRENT_DATE;
11. Fabric Mirroring — Cầu nối on-premises và cloud
SQL Server 2025 hỗ trợ mirroring liên tục đến Microsoft Fabric, cho phép replicate dữ liệu từ on-premises lên Fabric để phân tích với Power BI, Data Engineering, và AI workloads mà không cần ETL phức tạp.
graph LR
A[SQL Server 2025
On-premises] -->|Continuous Mirroring| B[Microsoft Fabric]
B --> C[Power BI
Reports]
B --> D[Data Engineering
Notebooks]
B --> E[AI/ML
Workloads]
A -->|Resource Governor| F[Kiểm soát tài nguyên
cho Mirroring]
style A fill:#2c3e50,stroke:#fff,color:#fff
style B fill:#e94560,stroke:#fff,color:#fff
style C fill:#f8f9fa,stroke:#e0e0e0,color:#2c3e50
style D fill:#f8f9fa,stroke:#e0e0e0,color:#2c3e50
style E fill:#f8f9fa,stroke:#e0e0e0,color:#2c3e50
12. MCP Server cho SQL Server
SQL Server 2025 tích hợp SQL MCP Server thông qua Data API Builder, cho phép các AI agent (bao gồm Azure AI Foundry agents) kết nối trực tiếp đến database qua giao thức MCP. Đây là bước tiến quan trọng trong việc biến SQL Server thành "data source" an toàn cho hệ thống Agentic AI.
Kết luận
SQL Server 2025 không chỉ là một bản nâng cấp — đó là sự tái định nghĩa vai trò của relational database trong kỷ nguyên AI. Với vector search tích hợp, native JSON, RegEx trong T-SQL, và khả năng gọi AI models trực tiếp, SQL Server 2025 cho phép developer xây dựng ứng dụng AI-powered mà không cần rời khỏi hệ sinh thái quen thuộc. Đặc biệt, Express Edition 50GB miễn phí làm cho các tính năng này có thể tiếp cận được với mọi quy mô dự án.
Tham khảo:
Node.js 24 — TypeScript Native, Permission Model và V8 13.6 thay đổi cách xây dựng Backend
Thiết kế hệ thống News Feed — Fan-out, Caching & Ranking cho hàng triệu người dùng
Disclaimer: The opinions expressed in this blog are solely my own and do not reflect the views or opinions of my employer or any affiliated organizations. The content provided is for informational and educational purposes only and should not be taken as professional advice. While I strive to provide accurate and up-to-date information, I make no warranties or guarantees about the completeness, reliability, or accuracy of the content. Readers are encouraged to verify the information and seek independent advice as needed. I disclaim any liability for decisions or actions taken based on the content of this blog.