批量执行sql语句的一个方法

该方法主要是用于多个中间以go隔开的多个语句,通常在用sql语句批量创建表或者试图或者存储过程时。具体代码如下:/// <summary> /// 批量执行sql语句 /// 唐军平 2009-9-17 /// </summary> /// <param name="sql">执行的sql语句</param> public static void ExecuteSqlNoneQueryForGO(string sql) { int startIndex = 0; string str = "/r/nGO/r/n"; do { int num = sql.IndexOf(str, startIndex); int length = ((num > startIndex) ? num : sql.Length) - startIndex; string cmdText = sql.Substring(startIndex, length); if (cmdText.Trim().Length > 0) { ExecuteNonQuery(cmdText); } if (num == -1) { break; } startIndex = num + str.Length; } while (startIndex < sql.Length); }

你可能感兴趣的:(sql,String,存储,Go)