当前位置:Gxlcms > 数据库问题 > 分析sql语句所有表名及其别名的正则表达式

分析sql语句所有表名及其别名的正则表达式

时间:2021-07-01 10:21:17 帮助过:3人阅读

 

为了测试方便我使用了Combox来保存整理出来的表达式,于是取所有表和别名的代码是这样的

            DataTable table = new DataTable();
            table.Columns.Add("tableName");
            table.Columns.Add("aliasName");
            foreach (string str in this.comboBox1.Items)
            {
                Regex reg = new Regex(str);
                MatchCollection mces = reg.Matches(this.richTextBox1.Text);
                foreach (Match mc in mces)
                {
                    DataRow row = table.NewRow();
                    row["tableName"] = mc.Groups[1].Value;
                    row["aliasName"] = mc.Groups[2].Value;
                    table.Rows.Add(row);
                }
            }
            this.dataGridView1.DataSource = table.DefaultView;

以下是我用于测试的sql

select * from Outvisit l
left join patient p on l.patid=p.patientid
join patstatic c on   l.patid=c.patid inner join patphone  ph  on l.patid=ph.patid
where l.name=kevin and exsits(select 1 from pharmacywestpas p where p.outvisitid=l.outvisitid)
unit all
select * from invisit v where

最后是我测试的小程序的截图

技术分享

 

分析sql语句所有表名及其别名的正则表达式

标签:

人气教程排行