Compartir a través de


Global References (M to SQL Mapping)

[This content is no longer valid. For the latest information on "M", "Quadrant", SQL Server Modeling Services, and the Repository, see the Model Citizen blog.]

Microsoft code name “M”->SQL translates computed values and extents into functions, views, and tables. Expressions are capable of referencing them as well. When an extent is used as an expression, the expression always means "get all the data out of this expression."

Type “M” Example SQL Example

Table

module M {
    type Var {
        i : Integer32;
        j : Integer32;
    }
    Vars : Var*;
    VarExpression() : Var* { Vars }
}
create table [M].[Vars]
(
  [i] int not null,
  [j] int not null
);
create view [M].[VarExpression]
(
  [i],
  [j]
)
as
  select [i] as [i], [j] as [j]from [M].[Vars];

module M {
    type Var {
        i : Integer32;
        j : Integer32;
    }
    Vars : Var*;
    VarView() : Var* { Vars }
    VarExpression() : Var* { VarView }
}
create table [M].[Vars]
(
  [i] int not null,
  [j] int not null
);
create view [M].[VarView]
(
  [i],
  [j]
)
as
  select [i] as [i], [j] as [j]
  from [M].[Vars];
create view [M].[VarExpression]
(
  [i],
  [j]
)
as
  select [i] as [i], [j] as [j]from [M].[VarView];

Table Valued Function

module M {
    type Var {
        i : Integer32;
        j : Integer32;
    }
    Vars : Var*;
    VarFunction(x : Integer32) : Var* { Vars where value.i > 10 }
    VarExpression() : Var* { VarFunction(10) }
}
create table [M].[Vars]
(
  [i] int not null,
  [j] int not null
);
go
create function [M].[VarFunction]
(
  @x as int
)
returns table
  as return (
    select [$value].[i] as [i], [$value].[j] as [j]
    from [M].[Vars] as [$value]
    where [$value].[i] > 10
  )
go
create view [M].[VarExpression]
(
  [i],
  [j]
)
as
  select [i] as [i], [j] as [j]from [M].[VarFunction]( 10);

Scalar Function

module M {
    Square(x : Integer32) : Integer32 { x * x }
    Cube(x : Integer32) : Integer32 { Square(x) * x }
}
create function [M].[Square]
(
  @x as int
)
returns int  as
  begin
    return @x * @x
  end
 
create function [M].[Cube]
(
  @x as int
)
returns int  as
  begin
    return [M].[Square](@x) * @x
  end