INFORMATION_SCHEMA.TABLES like 'value'

本文关键字:value like SCHEMA TABLES INFORMATION | 更新日期: 2023-09-27 18:10:04

我对SQL查询感到困惑。我有一个.sdf数据库,其中已经创建了表。我有一个表单,检查是否存在一个表,创建一个新表,并从DataGridView填充它的数据。我可以使用SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES查询在DataGridView中显示所有数据库表,这是有效的,但我只想显示以'_quote'结尾的某些表。我如何"过滤"这显示在_quote结束的所有表?(例如一个名为random_table_name_quote的表)。我到目前为止填充DataGridView的代码:

private void getTables()
    {            
        dataGridView1.DataSource = dt;
        string strConnect = "Data Source=|DataDirectory|''LWADataBase.sdf";
        using (SqlCeConnection con = new SqlCeConnection(strConnect))
        {
            con.Open();
            using (SqlCeCommand com = new SqlCeCommand("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES", con))
            {
                using (SqlCeDataAdapter da = new SqlCeDataAdapter())
                {
                    da.SelectCommand = com;
                    da.Fill(dt);
                    dataGridView1.Columns[0].HeaderCell.Value = "Quotation Name";
                }
            }
        }
    }

INFORMATION_SCHEMA.TABLES like 'value'

SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE '%__quote' 

只需更改sql查询以过滤结果!

检查下面的行!

using (SqlCeCommand com = new SqlCeCommand("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME Like '%_quote'", con))

致以最亲切的问候!