Basic Concepts in "M"

[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.]

The Microsoft code name “M” modeling language uses a small number of basic concepts. This topic describes these concepts and how they relate to each other. These concepts can be grouped into the following categories:

  1. Values or data.

  2. Types.

  3. Constraints.

  4. Modules for “M” declarations.

  5. Languages.

Values in "M"

The “M” language is fundamentally about values or data. For any system or application, there are many relationships among the values, as well as constraints on the values. When you model a system, you, in essence, are specifying a complex set of values and their possible relationships.

“M” has a set of intrinsic types that are part of the language and all values conform to one or more of these types. The values can be simple (an integer), or complex (a collection of things), and complex values can reference each other. Values in “M” can be ascribed a specific type. If a value is not ascribed a type, “M” can ascribe a type to it based on its context.

In “M”, there are the following kinds of values:

  1. Simple or “scalar”: These are atomic values that cannot be decomposed into smaller values. Examples are Integer32, Text, DateTime, and other values.

  2. Collection: Contains repeated occurrences of an element. A collection can be composed of any type of value, not just simple values.

  3. List: An ordered collection.

  4. Entity: A value that contains one or more named fields, each of which can be any type of value.

Simple values can be represented by literals, and each kind of literal has a specific way of being represented. For example, a Text literal is represented as a Unicode character string enclosed in double quotes. Literals can be combined together with operators into expressions, which themselves yield literals when evaluated. For example, you can perform arithmetic operations on Numeric literals and do concatenation on Text literals.

Collection and entity values also have specific ways to represent them and the operations that affect them.

Extents

A value that exists in storage is called an extent. When compiled, these values cause SQL tables to be created.

An extent is a named piece of storage defined at the module level. Extents can contain collections of entities. When you compile an “M” program, an extent becomes a SQL table.

Computed Values

Computed values do not define storage. Rather, a computed value is an expression that is evaluated at runtime from other values and exists only in memory.

When compiled, computed values generate SQL view or function statements. Computed values may specify parameters, in which case they generate SQL functions; otherwise they generate SQL views.

Types

A type in “M” is the set of values that conform to the type’s definition. For example, the intrinsic type Integer32 consists of the collection of all 32-bit integers that can be represented on a computer.

A type is similar to an interface in C# or VB, or to an XML schema. It defines a data structure, which can be used by extents or by other types. But it does not cause storage to be allocated.

Types in “M” can be system-provided intrinsic types or derived types defined by the user. An example of an intrinsic type is Integer32. An example of a derived type is a collection of integers, or an Integer32 field with a constraint applied.

A derived type is a definition of a new type based on or derived from an already existing type. Derived types are defined using the “M” type keyword and other statements in the “M” language. Derived types are intended for reuse.

Types can be simple, collections, lists, or entities.

Simple derived types can be created by adding a constraint to a type definition.

Constraints

Constraints are logical expressions that place restrictions on the fields in types and extents. Constraints are applied by appending the where operator to a type or extent declaration, followed by one or more logical expressions, which can be joined by logical operators (and, or). With certain named constraints such as unique and identity, the logical criteria are implicit, and not stated explicitly as logical predicates.

Entity

An entity type contains one or more named fields. To reference an entity type, or have it contain fields with collection types, it must contain a field with an identity constraint.

Field

A field is a named value inside an entity. Fields can be assigned a specific type or can be defined without a type.

Containers for "M" Declarations

In modeling a system, many “M” declarations are written. These all must be placed inside modules. One or more modules are placed inside a file and a compilation episode consists of one of more files.

The “M” compiler compiles one or more files into T-SQL code. Each file contains one or more named modules, each of which begins with a module statement. All other “M” statements must be inside a module. A module is the lowest unit of scope and encapsulates everything inside it. Modules can expose the types inside them by using the export statement, and refer to types in other modules that have been exported by using the import statement.

Languages

You can use “M” to create a domain specific language (DSL) by describing the grammar of the language. For more information, see  Creating Custom Languages.

See Also

Other Resources

Values in "M"
Defining Schemas: Types in"M"
Common "M" Constructs
Creating Custom Languages
Queries in "M"