using System.IO; using Microsoft.Data.Schema.ScriptDom; using Microsoft.Data.Schema.ScriptDom.Sql; public List<string> SQLStmtValid(string sql) { TSql100Parser parser = new TSql100Parser(false); IScriptFragment fragment; IList<ParseError> errors; fragment = parser.Parse(new StringReader(sql), out errors); if (errors != null && errors.Count > 0) { List<string> errorList = new List<string>(); foreach (var error in errors) { errorList.Add(error.Message); } return errorList; } return null; }
Reference: http://stackoverflow.com/questions/3276035/code-to-validate-sql-scripts
Last Updated on October 26, 2015