Exporting Schemas from SQL Server Modeling Services
[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 an “M” image is loaded into a SQL Server 2008 database, the “M” module becomes a SQL Server schema. One common task is to export these SQL Server schemas back into “M” image files. You can also create an “M” image file from a SQL Server schema that was not originally created by using “M”.
Exporting a SQL Schema
Mx.exe is used both for loading “M” image files as well as exporting database schemas into “M” image files. Many of the parameters are the same, including those for authentication and database targets. For more information, see Loading Image Files into SQL Server Modeling Services.
There are several options for exporting “M” image files. The Mx.exe utility uses the export command followed by one or more switches that control the export process. The image switch exports a previously installed “M” image file if the proper infrastructure tables are present in the target database. The module parameter specifies the “M” module or SQL Server schema to export. For example, consider the following “M” code:
module Contact
{
type Person
{
Id : Integer32;
Name : Text;
} where identity(Id);
People : { Person* };
}
You can compile the preceding “M” code and load the resulting image file into the database. The Contact
module becomes a Contact SQL Server schema in the database. The People
extent becomes a People table in the database.
The following Mx.exe command exports this schema into a new “M” image file, named Contact2.mx. This command looks for the SQL Server schema in the Repository database on the current machine.
mx.exe export -database:Repository -module:Contact -out:Contact2.mx
The following Mx.exe command exports the People
extent from the Contact schema.
mx.exe export -database:Repository –module:Contact -extent:People -out:People.mx
Using Exported Schemas
Mx.exe exports SQL Serverr database schemas into “M” image files. This has two main benefits. First, you can use the types and extents from these image files in new “M” code. The image files can then be used to resolve the dependencies during compilation and loading steps. For more information, see Loading Image Files into SQL Server Modeling Services. You can also use the image files to load the same data model into a different database.