How to: Get Started 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.]
This tutorial is an introduction to programming in the Microsoft code name “M” language. It enables you to describe a basic module in “M”, compile it, and view the corresponding T-SQL statements generated by the compiler. In this tutorial, you code your data structure using the Intellipad editor. You can also use the Visual Studio extensions for “M”, but by using code name “Intellipad” tool you can quickly examine the generated TSQL code.
To code the module
Open the Intellipad editor by clicking Start, All Programs, Microsoft Oslo SDK, Tools, and Intellipad. The editor window appears.
Add the following code fragment, which is the smallest possible “M” program, because every “M” statement must be contained inside a module. A module is the unit of compilation in “M”.
module Northwind { }
Now examine the generated SQL by selecting M Mode, and Reach SQL Preview.
The following code is displayed.
/* No extents? No SQL for you! */
This message is generated whenever the “M” code does not yet generate any SQL code. In general, to generate SQL code, the “M” code must declare an extent.
To add an extent
Add the following code fragment inside the braces of the module statement.
Employees : {Text*};
Now examine the generated SQL. The following additional code is displayed.
set xact_abort on; go begin transaction; go set ansi_nulls on; go create schema [Northwind]; go create table [Northwind].[Employees] ( [Item] nvarchar(max) not null ); go commit transaction; go
Adding an extent caused TSQL code to be generated that creates a table.
To initialize the extent
Replace the line of code that contains the
Employees
statement with the following. This code creates anEmployees
extent and initializes it with values.Employees : {Text*} {"Kim Akers", "Dan Park", "Michael Alexander","Junmin Hao"};
Now examine the generated SQL. The following additional code is displayed after the creation of the
Employees
table.insert into [Northwind].[Employees] ([Item]) values (N'Kim Akers') , (N'Dan Park') , (N'Michael Alexander') , (N'Junmin Hao') ;
Initializing the extent caused TSQL code to be generated that populates the
Employees
table with values.
Example
The following is the complete “M” code sample for the Northwind
module.
module Northwind
{
Employees : {Text*} {"Kim Akers", "Dan Park", "Michael Alexander","Junmin Hao"};
}