SqlSugar中如何获取指定数据库的所有表名 返回

SqlSugar 老数据
5 5686

大家好,刚学习SqlSugar两天,我现在有个需求:SqlSugar中如何获取指定数据库下的所有表名?原生的MySQL语句是:

select table_name from information_schema.tables where table_schema='db_name' and table_type='base table';

那么在SqlSugar中如何执行这条语句并返回对应的结果呢?我没找到SqlSugar如何执行原生的MySQL语句的方法。以上是我的问题,谢谢各位大佬指点迷津,谢谢~~

热忱回答5

  • db.DbMaintenance.GetTableInfoList

    0 回复
  • 你是哪个连接字符串就藜取该连接字符串下所有的表

    0 回复
  • @fate stay night:你这个只是得到一张表的详细信息,它等价于desc tb_name;

    0 回复
  • @fate stay night:我不想修改连接字符串以获取所有的表格信息,我是想能不能不修改连接字符串的情况下获取同一个数据库下所有表的表名。

    0 回复
  • 我找到这个:

     var dt = db.Ado.GetDataTable("select table_name from information_schema.tables where table_schema=@table_schema and table_type=@table_type", new List<SugarParameter>(){
                        new SugarParameter("@table_schema","db_instrument"),
                        new SugarParameter("@table_type","base table")});

    可以解决我以上的需求。

    0 回复