SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Things That Should Be In TSQL

Relation Types

[PREF] create type type_T(i int primary key clustered, j int check (j > 0)) -- relation type. Includes constraints! create table T(type_T) [ENDPREF]

Relvar Assignment

This follows from relation types: [PREF] create table T(type_T) create table U(type_T) = T declare @V table(type_T) = U [ENDPREF] Strong typing could be enforced, which might make this easier to add to the language. For instance, the following could be made illegal even though the attribute sets are identical, since the tables involved were not declared as being of a specific type: [PREF] create table T(i int) create table U(i int) = T -- error: cannot implicitly convert between anonymous relation types [ENDPREF]

Relvar Comparison (Equality and Inequality)

The same thing can be accomplished already using joins and row counts (or "except", etc) for tables that you know to be of the same "type". But why not add this awesome syntactic sugar, since we've already added relation types? [PREF] create type type_T(i int) create table T(type_T) insert T select 1 create table U(type_T) insert U select 1 if (T = U) begin ... if (T > U) begin ... -- error, only equality and inequality allowed [ENDPREF]

Table valued output parameters

This too follows from relation types: [PREF] create type type_T(i int, j int) create procedure dbo.foo (@i int, @T type_T, @j int output, @U type_T output) as .... [ENDPREF]

Delegates (Strongly Typed Function and Procedure Pointers)

This would be clearer if you could refer to procedures using parentheses, but you can imagine it without them too: [PREF] create procedure dbo.foo(@i int, @c char)... create procedure dbo.bar(@dt datetime) ... declare @d delegate(@i int, @c char) = dbo.foo() exec @d(3, 'K') set @d = dbo.bar() -- error, type mismatch [ENDPREF]

I've created a Microsoft connect suggestion for this.

Don Halloran

SQL Server, SSIS, SSAS and maybe even SSRS rants and raves (and, on occasion, useful code or designs).


Posted by Anonymous on 16 June 2011

Pingback from  Dew Drop – June 16, 2011 | Alvin Ashcraft's Morning Dew

Leave a Comment

Please register or log in to leave a comment.