public static String GetCreateTableBasicStatement(TableName tableName) { DbTable table = GetTableStructure(tableName); IList <DbField> fields = table.Columns; IList <String> constraints = table.Constraints; StringBuilder sql = new StringBuilder(); sql.Append("CREATE TABLE "); sql.AppendFormat("{0} (", tableName.ToString()); foreach (DbField field in fields) { sql.AppendFormat("{0} {1} NOT NULL, ", field.FieldName, DbTypeMap.GetGFXDType(field.FieldType, field.Length)); } foreach (String constraint in constraints) { sql.AppendFormat("{0}, ", constraint); } sql = sql.Remove(sql.Length - 2, 1).Append(") "); return(sql.ToString()); }
public static void CreateTable(String schemaName, String tableName) { String tableFullName = String.Format("{0}.{1}", schemaName, tableName); if (!DbHelper.TableExists(tableFullName)) { StringBuilder sql = new StringBuilder(); sql.AppendFormat("CREATE TABLE {0} (", tableFullName); foreach (DbField field in randomTable.Columns) { sql.AppendFormat("{0} {1} NOT NULL, ", field.FieldName, DbTypeMap.GetGFXDType(field.FieldType, field.Length)); } sql.AppendFormat(" CONSTRAINT pk_{0} PRIMARY KEY ({1})) ", tableName, randomTable.PKColumns[0]); sql.Append("PARTITION BY PRIMARY KEY "); //sql.Append("REPLICATE "); DbHelper.ExecuteNonQueryStatement(sql.ToString()); } else { throw new Exception( String.Format("Table {0} already exists", tableFullName)); } }