As I try to drag my team (sometimes with resistance, sometimes with pleasure) into the world of relational principles, I find myself struggling for a good answer as to why type constraints were deprecated in SQL 2005. And further, why we can't derive user types from other user types.
Consider, if you will a contrived example in which we have orders with at most 10 order lines, and invoices with at most 20 invoice lines...
create type T_index from int not null check (value >= 1) create type T_order_line_index from T_index check (value between 1 and 10) create type T_invoice_line_index from T_index check (value between 1 and 20)
I think this kind of language enhancement would be super. Particularly if we could change the type definition even if it was already referenced, and had the definition be updated in all referencing entities. Seems like a pretty good general programming principle that applies just as much to the database world as any other. I mean, it must have been the third day of programming class that you learned to declare a variable and reuse it in your functions rather than using a literal value everywhere, yeah? Not sure how this kind of thing has slipped past the database world (or at least SQL Server).
Doing it with relation types might also (arguably) have some use....
create type T_row_audit (created_date datetime default getdate(), updated_date datetime) create table orders (order_id int, order_date datetime, T_row_audit)
I suppose CLR integration handles most of this, but I just feel like it belongs in the language.