[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.]
When inserting instances, you can label the instances and refer to them in other insert statements or in expressions. Labeled scalars are translated as constants wherever they are seen.
Examples
“M” Example
SQL Example
Labeled Scalar
module M {
Ints : Integer32* { A { 10 }, B { 20 } };
MoreInts : Integer32* { Ints.B, Ints.A };
F() { Ints.A + Ints.B }
}
create table [M].[Ints]
(
[Item] int not null
);
create table [M].[MoreInts]
(
[Item] int not null
);
create function [M].[F]
(
)
returns int as
begin
return 10 + 20
end
insert into [M].[Ints] ([Item])
values (10)
;
insert into [M].[Ints] ([Item])
values (20)
;
insert into [M].[MoreInts] ([Item])
values (20)
;
insert into [M].[MoreInts] ([Item])
values (10);
Labeled Entity
module M {
type Person {
Id : Integer32 => AutoNumber();
Name : Text;
Mother : People?;
} where identity(Id);
People : Person* {Jack { Name => "Jack", Mother => Jane },Jane { Name => "Jane" },John { Name => "John", Mother => Jane },Manfred { Name => "Manfred", Mother => Martha },Martha { Name => "Martha" },};
}
create table [M].[People]
(
[Id] int not null identity,
[Mother] int null,
[Name] nvarchar(max) not null,
constraint [PK_People] primary key clustered ([Id]),
constraint [FK_People_Mother_M_People] foreign key ([Mother]) references [M].[People] ([Id])
);
insert into [M].[People] ([Name])values (N'Jane');declare @M_People_Id1 bigint = @@identity;insert into [M].[People] ([Name], [Mother])values (N'Jack', @M_People_Id1);insert into [M].[People] ([Name], [Mother])values (N'John', @M_People_Id1);insert into [M].[People] ([Name])values (N'Martha');declare @M_People_Id4 bigint = @@identity;insert into [M].[People] ([Name], [Mother])values (N'Manfred', @M_People_Id4);
References to labeled entities are not currently supported in computed values or constraints. References to labeled entities with multiple identity fields are presently unsupported.