public static string GenerateAlterModifySQL(string tableName, CSQLColumn colFrom, CSQLColumn colTo) { string type = colFrom._02_Type; string notNull = ""; string autoIncrement = ""; string deflt = ""; string prKey = ""; //if (colTo._02_Type != colFrom._02_Type) if (colTo._03_Null != colFrom._03_Null) { notNull = colFrom.SQLNull; } if (colTo._04_Key != colFrom._04_Key) { prKey = colFrom.SQLPrimaryKey; } if (colFrom._05_Default != colTo._05_Default) { deflt = colFrom.SQLDefault; } if (colFrom._06_Extra.Contains("auto_increment") && !colTo._06_Extra.Contains("auto_increment")) { autoIncrement = colTo.SQLAutoIncrement; } string alterTable = String.Format("ALTER TABLE {0} MODIFY COLUMN {1} {2} {3} {4} {5} {6}", tableName, // 0 colFrom._01_Field.ToString(), // 1 colFrom._02_Type.ToString(), //2 colFrom.SQLNull, //3 colFrom.SQLPrimaryKey, //4 colFrom.SQLAutoIncrement, //5 colFrom.SQLAutoIncrement ); return(alterTable); }
public string GenerateAddColumnSQL(string tableName, CSQLColumn col) { string sql = String.Format("ALTER TABLE {0} ADD COLUMN {1} {2} {3} {4} {5}", tableName, //0 col._01_Field, //1 col._02_Type, //2 col.SQLNull, //3 col.SQLDefault, //4 col.SQLPrimaryKey //5 ); return(sql); }
public static string GenertateAlterAddColSQL(string tableName, CSQLColumn col) { string sql = ""; string notNull = ""; string prKey = ""; string autoIncrement = ""; if (col._03_Null == "NO") { notNull = "NOT NULL"; } if (col._04_Key == "PRI") { prKey = "PRIMARY KEY"; } if (col._06_Extra.Contains("auto_increment") ) { autoIncrement = " auto_increment"; } string alterTable = String.Format("ALTER TABLE {0} MODIFY COLUMN {1} {2} {3} {4} {5}", tableName, // 0 col._01_Field.ToString(), // 1 col._02_Type.ToString(), //2 notNull, //3 prKey, //4 autoIncrement //5 ); return(sql); }