I think that the ability of some reflective managed environments (e.g. .NET) to add custom metadata to code entities in the form of attributes is very powerful. Is there any mechanism for doing something similar for databases?
Databases obviously already have a fair amount of metadata available; for example, you can get a list of all tables, columns, and foreign key references, which is enough to put together a schema diagram. However, I could imagine plenty of uses for something more generic, such as something along the lines of this imaginary fusion of C# and DDL:
[Obsolete("Being replaced by the ClientInteraction table")]
create table CustomerOrder (
[SurrogateKey]
MyTableId int identity(1,1) primary key
[NaturalKey]
[ForeignKey("Customer", "CustomerId")] /* Actual constraint left out for speed */
,CustomerId int not null
[NaturalKey]
[ConsiderAsNull(0)]
[ConsiderAsNull(-1)]
,OrderId int not null
[Conditional("DEBUG")]
,InsertDateTime datetime
)
The example is a little contrived but hopefully makes my question clearer. I think that the ability to reflect over this kind of metadata could make many tasks much more easily automated. Is there anything like this out there? I'm working with SQL Server but if there's something for another DBMS then I'd still be interested in hearing about it.