} // getSQLCrete // getSQLCrete /** * Get SQL Create * @param requery refresh columns * @return create table DDL */ public String GetSQLCreate(bool requery) { StringBuilder sb = new StringBuilder("CREATE TABLE ") .Append(GetTableName()).Append(" ("); // bool hasPK = false; bool hasParents = false; bool firstColumn = true; StringBuilder constraints = new StringBuilder(); StringBuilder unqConstraints = new StringBuilder(); GetColumns(requery); for (int i = 0; i < m_columns.Length; i++) { MColumn column = m_columns[i]; if (column.IsVirtualColumn()) { continue; } if (firstColumn) { firstColumn = false; } else { sb.Append(", "); } sb.Append(column.GetSQLDDL()); // if (column.IsKey()) { constraints.Append(", CONSTRAINT PK").Append(GetAD_Table_ID()) .Append(" PRIMARY KEY (").Append(column.GetColumnName()).Append(")"); hasPK = true; } if (column.IsParent()) { hasParents = true; } if (column.IsUnique()) { if (unqConstraints.Length == 0) { unqConstraints.Append(", CONSTRAINT UK").Append(GetAD_Table_ID()) .Append(" UNIQUE (").Append(column.GetColumnName()); } else { unqConstraints.Append(",").Append(column.GetColumnName()); } } } // Multi Column PK if (!hasPK && hasParents) { StringBuilder cols = new StringBuilder(); for (int i = 0; i < m_columns.Length; i++) { MColumn column = m_columns[i]; if (!column.IsParent()) { continue; } if (cols.Length > 0) { cols.Append(", "); } cols.Append(column.GetColumnName()); } sb.Append(", CONSTRAINT PK").Append(GetAD_Table_ID()) .Append(" PRIMARY KEY (").Append(cols).Append(")"); } if (unqConstraints.Length > 0) { unqConstraints.Append(")"); } sb.Append(constraints); sb.Append(unqConstraints); sb.Append(")"); return(sb.ToString()); } // getSQLCreate