VOOZH about

URL: https://thenewstack.io/how-to-document-database-objects-with-annotations/

⇱ How to Document Database Objects with Annotations - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2024-02-19 06:00:51
How to Document Database Objects with Annotations
sponsor-oracle,sponsored-post-contributed,
Data / Software Development

How to Document Database Objects with Annotations

Stop trying to guess why a database column exists by using structured database schema documentation.
Feb 19th, 2024 6:00am by Chris Saxon
👁 Featued image for: How to Document Database Objects with Annotations
Featured image by Arivle One from Pixabay.
Oracle sponsored this post.

Every database has them. A set of columns — or even whole tables — that no one can explain why they exist. Any documentation about them (if it ever existed) is long lost in your corporate wiki.

To help you understand your schema, it would be better to record notes inside the database, ideally right alongside the columns and tables. This would allow you to view these details in your tools or by querying the data dictionary.

Most database systems allow you to do this with object comments. For example, in Oracle Database, you can do this with the COMMENT command:

This information then appears in the corresponding object’s comment dictionary views:

This is a great way to help other developers and database administrators (DBAs) understand your schemas.

But comments are just a string. This makes them awkward to use if you want to store many properties about an object.

For example, it’s common for database tables to include an INSERT_DATETIME column. These columns should all be:

  • System generated: The database should supply the values using column defaults.
  • Mandatory: No nulls allowed.
  • Insert only: These values should never be updated.

This information relates to your intention for using the data: It’s not just about why these columns exist but how to interact with them. Recording these details helps future maintainers understand how to use these data in apps.

You could store these properties alongside other notes in the comments. The question is which format do you use? JSON? XML? Delimited key-value pairs?

Whichever you choose, you need all future maintainers to stick to the same format. This becomes challenging for long-living systems. It would be better if the database itself enforced some structure on the comments.

Oracle Database 23c addressed this by adding usage annotations.

Better Database Documentation with Annotations

Annotations are keys with optional values. You can use them to record any metadata you want about the object in question.

For example, this annotates the INSERT_DATETIME column with the properties listed above:

You may wonder why allowed_writes uses a JSON array, even though there’s only one value. Why not just use the string “insert”?

You’ll likely want to apply this annotation to many columns. These may also support updates or deletes. Making them all arrays makes them easier to process compared to a mix of arrays and plain strings.

Once you’ve added the annotations, you can view them in the *_usage_annotations views:

These views show annotations for all object types. This means they’re all accessible in one location, which makes it simple to access annotations programmatically to generate separate documentation if you want.

The key-value structure of annotations makes them more powerful than comments.

But there’s still a challenge when you’re using them for common values. Most or all the tables in a schema will have an INSERT_DATETIME column. These should all have identical annotations. Trying to keep all these in sync over time is tough!

Instead of copying the annotations to every INSERT_DATETIME column, it would be better to define them once in a shared object. Then apply this object to all the columns that need it. This ensures they all have the same properties.

The question is: how?

Standardize Annotations with Domains

Oracle Database 23c addressed this by adding usage domains. These build on domains in the SQL standard. They extend existing data types with optional properties including:

  • Constraints
  • Defaults
  • Annotations

Use the CREATE DOMAIN statement to make one. This creates an INSERT_DATETIME domain with the annotations above:

You can then apply this domain to columns when creating or altering tables. Do this by specifying the domain either instead of the data type or using the domain clause after the data type. This copies the annotations from the domain to the table columns:

To link a domain to a column, both must have the same base data type. You can only associate the INSERT_DATETIME domain with timestamp columns, not date, number, varchar2, etc.

With this centralized definition, you can be confident all columns using a domain have the same annotations. This applies even if you want to change them in the future.

For example, you may want to specify that you allow filtering and sorting operations on insert timestamps, meaning it’s safe to use these columns in the WHERE and ORDER BY clauses.

You can alter the domain to add these annotations:

The database automatically applies these to the corresponding database columns:

Document Data Intention

Database schemas can be complex. Understanding the purpose of every part can be tricky. By documenting this in the schema itself, you help everyone know the how and why of each bit.

Comments are a widely used way to record these details. Their unstructured nature limits their usefulness. The key-value structure of annotations in Oracle Database 23c gives you more power.

In Oracle Database 23c, you can also define domains. These give you a single point of definition for common data values, such as insert timestamps.

Combining domains and annotations gives you a simple way to describe data. Together they form a new class of SQL statement: data intention language (DIL).

As schemas grow, using these DIL statements will be key to helping other developers understand both why and how to use it.

Help your fellow developers and DBAs: Document your database with domains and annotations!

Oracle offers a wide range of technologies for building, testing, and maintaining applications in the cloud and in your data center. Find free tools and learning resources at oracle.com/developer
Learn More
The latest from Oracle
TRENDING STORIES
Chris is a developer advocate for Oracle Database, where his job is to help you get the best out of it and have fun with SQL. You can find him on Twitter, @ChrisRSaxon, and on his blog, All Things SQL.
Read more from Chris Saxon
Oracle sponsored this post.
SHARE THIS STORY
TRENDING STORIES
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.