Design choices - JSON, graph tables and partitioning

DP-800 · Design SQL database solutions for AI · Updated

AI features sit on top of normal schema design. The exam checks whether you pick the right structure for the data shape and the query pattern.

JSON in the database

SQL Server 2025 and Azure SQL support a native json data type, in addition to JSON stored in nvarchar. Useful functions:

FunctionPurpose
JSON_VALUEExtract a scalar value from a path
JSON_QUERYExtract an object or array
OPENJSONTurn JSON into rows and columns
JSON_OBJECT / JSON_ARRAYBuild JSON from columns
ISJSON / JSON_MODIFYValidate or change JSON

To filter on a property quickly, add a computed column on JSON_VALUE(Payload, '$.customer_id') and index it. Newer versions also support a JSON index on the column.

Use JSON for variable or nested data. Use normal columns for data you join, constrain or filter all the time.

Graph tables

Graph features store many-to-many relationships as node and edge tables.

CREATE TABLE Person (PersonID int, DisplayName nvarchar(100)) AS NODE;
CREATE TABLE Knows AS EDGE;

SELECT p3.PersonID, p3.DisplayName
FROM Person p1, Knows k1, Person p2, Knows k2, Person p3
WHERE MATCH(p1-(k1)->p2-(k2)->p3)
  AND p1.PersonID = @StartPersonId;

The arrow direction in MATCH matters. SHORTEST_PATH finds shortest routes with repeated patterns. Choose graph over recursive CTEs when relationship depth varies and traversal is the main workload.

Partitioning

A partition function defines boundaries and a partition scheme maps them to filegroups. Partition large tables by a date column that queries filter on.

Benefits:

  • Switch a partition in or out almost instantly (ALTER TABLE ... SWITCH).
  • Rebuild or compress one partition (ALTER INDEX ... REBUILD PARTITION = n) instead of the whole table.
  • Partition elimination reduces reads when the query filters on the partition key.

The partition column must be part of a unique key or clustered index key on a partitioned table.

Choosing index types

NeedIndex
Point lookups, rangesRowstore B-tree (clustered or nonclustered)
Large scans and aggregatesClustered or nonclustered columnstore
Nearest-neighbour on embeddingsVector index
Word and phrase searchFull-text index

Exam traps

  • Partitioning is a maintenance and manageability tool first. It does not always speed up queries.
  • JSON path queries are not indexed automatically. Add a computed column or JSON index.
  • A vector index is not a replacement for full-text. Hybrid search uses both.
  • Columnstore is poor for single-row lookups.

Practice questions

Choose an answer, then review the explanation to check your understanding.

1. Semi-structured event payloads vary by source and you want to index one property for fast filtering. What is a good design?

Show answer

Answer: B.Keep the payload in a JSON column and expose hot properties through a computed column (JSON_VALUE) or a JSON index so filters can use an index.

2. You must find people reachable through exactly two Knows relationships. Which feature models this most naturally?

Show answer

Answer: A.Graph tables (AS NODE and AS EDGE) with MATCH express multi-hop relationships, including fixed or variable length paths.

3. A table of orders keeps growing by year, and old years must be switched out quickly with little rebuild time. What do you use?

Show answer

Answer: A.Partitioning lets you switch, rebuild or compress one partition at a time, which keeps maintenance windows short.

4. Which index type suits analytic scans and aggregations over a large fact table?

Show answer

Answer: A.Columnstore indexes compress data by column and are built for scans and aggregates. Rowstore B-tree indexes suit point lookups.

DP-800 course outline

All 7 lessons · Course overview
  1. The vector data type and similarity searchDesign SQL database solutions for AI Free
  2. Design choices - JSON, graph tables and partitioningDesign SQL database solutions for AI Free
  3. Generating embeddings with external modelsDevelop with SQL and AI features Full access
  4. Keeping embeddings in sync with change trackingDevelop with SQL and AI features Full access
  5. Hybrid search and RAG over SQL dataDevelop with SQL and AI features Full access
  6. Securing SQL AI solutionsSecure, optimize and maintain SQL AI solutions Full access
  7. Performance, blocking and CI/CD for SQL AISecure, optimize and maintain SQL AI solutions Full access