sql2mco
sql2mcoutility
是一个简单的命令行实用工具,可将 SQL-89 DDL 语句转换为等效的 SmartEDB DDL。该实用工具从命令行的调用方式如下:
sql2mco <input-sql-file> <output-mco-file>
对于C、C++和Python应用程序,可以通过调用mcocomp模式编译器来实现。该编译器确保模式语法正确,然后生成应用程序编程接口(API)头文件(.h)和实现文件(.c)。当应用程序编译时,从实现文件中生成数据库字典。数据库字典只是运行时使用的模式的二进制形式。模式编译器还可以生成适当注释的Java和/或C#类定义。
形式语法
sql2mco
识别的形式语法如下:
<create table statement> ::=
CREATE TABLE <table name>
( <table element> [ { , <table element> } ... ] )
<table element> ::=
<column definition> | <table constraint>
<column definition> ::=
<column name> <data type> [ DEFAULT <default value> ] [ <column constraint> [ { , <column constraint > } ... ]
<column constraint> ::= [ CONSTRAINT <constraint name> ] [ <constraint implementation> ]
{ <unique column constraint> | <primary key column constraint> |
<foreign key column constraint> | <not null constraint> }
<unique column constraint> ::= UNIQUE
<primary key column constraint> ::= PRIMARY KEY
<foreign key column constraint> ::= REFERENCES <table name> [ ( <column name> ) ]
<not null constraint> ::= NOT NULL
<table constraint> ::= CONSTRAINT <constraint name> ] [ <constraint implementation> ]
{ <unique table constraint> | <primary key table constraint> | <foreign key table constraint> }
<unique table constraint> ::= UNIQUE ( <column name> [ { , <column name> } ... ] )
<primary key table constraint> ::= PRIMARY KEY ( <column name> [ { , <column name> } ... ] )
<foreign key table constraint> ::= FOREIGN KEY ( <column name> [ { , <column name> } ... ] )
REFERENCES <table name> [ ( <column name> [ { , <column name> } ... ] ) ]
<constraint implementation> ::={ HASH ( <capacity> ) | TREE } INDEX
实例
如下展示了一个 SQL DDL 的示例以及它生成的等效 MCO DDL。
