Compartir a través de


Default Values (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.]

Fields can have default values in Microsoft code name “M”, for example "MyGuid : Guid => NewGuid()" or "Z : Integer32 => 0." “M”->SQL translates simple constant defaults into the default keyword for a column. Anything more complex (references to columns, sub-queries, math operators) is presently unsupported.

This means that you can do an "insert into" into the table without specifying those values, and they are replaced with their defaults.

Examples

“M” Example SQL Example

Simple Default

module M {
    type Person {
        PersonId : Integer32;
        Name : Text;
        IsAlive : Logical => true;
    } where identity PersonId;
    People : Person*;
}
create table [M].[People]
(
  [PersonId] int not null,
  [IsAlive] bit not null default 1,
  [Name] nvarchar(max) not null,
  constraint [PK_People] primary key clustered ([PersonId])
);

Auto-numbering Identity

module M {
    type Person {
        PersonId : Integer32 => AutoNumber();
        Name : Text;
    } where identity PersonId;
    People : Person*;
}
create table [M].[People]
(
  [PersonId] int not null identity,
  [Name] nvarchar(max) not null,
  constraint [PK_People] primary key clustered ([PersonId])
);

The AutoNumber() default, only allowed to be specified on an integer identity field, causes the field type to be identity.

“M”->SQL cannot presently handle default values for collection or entity columns. Additionally, default values that refer to collection or entity columns in the same extent do not work.