sqlsugar查询数据库下的所有表,批量修改表名字

查询数据库中的所有表

cs 复制代码
using SqlSugar;

namespace 批量修改数据库表名
{
    internal class Program
    {
        static void Main(string[] args)
        {
            SqlSugarClient sqlSugarClient = new SqlSugarClient(new ConnectionConfig()
            {
                ConnectionString = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=testchangetablename;Integrated Security=True;Connect Timeout=30;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;Multi Subnet Failover=False",
                DbType = DbType.SqlServer,
                IsAutoCloseConnection = true
            });
            //创建四个表
            /*
            use testchangetablename;
            create table test01_001(
	            Id bigint primary key not null
            )
            create table test01_002(
	            Id bigint primary key not null
            )
            create table test01_003(
	            Id bigint primary key not null
            )
            create table test01_004(
	            Id bigint primary key not null
            )
             */
            var tables = sqlSugarClient.DbMaintenance.GetTableInfoList(false);//true 走缓存 false不走缓存
            foreach (DbTableInfo item in tables)
            {
                //表名字
                Console.WriteLine(item.Name);
                //描述
                Console.WriteLine(item.Description);
            }
        }
    }
}

批量修改表名字

cs 复制代码
using SqlSugar;

namespace 批量修改数据库表名
{
    internal class Program
    {
        static void Main(string[] args)
        {
            SqlSugarClient sqlSugarClient = new SqlSugarClient(new ConnectionConfig()
            {
                ConnectionString = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=testchangetablename;Integrated Security=True;Connect Timeout=30;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;Multi Subnet Failover=False",
                DbType = DbType.SqlServer,
                IsAutoCloseConnection = true
            });
            var tables = sqlSugarClient.DbMaintenance.GetTableInfoList(false);//true 走缓存 false不走缓存
            foreach (DbTableInfo item in tables)
            {
                if (item.Name.StartsWith("test01_"))
                {
                    var newName = item.Name.Replace("test01_", "test02_");
                    sqlSugarClient.DbMaintenance.RenameTable(item.Name, newName);
                }
            }
        }
    }
}

执行之后

参考

相关推荐
課代表10 天前
bat 批处理文件重命名加时间戳
时间·重命名·bat·时间戳·命令·批处理·字符串截取
課代表17 天前
批处理的应用与价值
系统·脚本·dos·变量·批处理·管道·办公
CS创新实验室22 天前
从穿孔卡片到云原生:批处理系统的不朽演进与核心思想
云原生·操作系统·批处理
任风雨24 天前
15.6.Bat脚本编写
bat·批处理
赵庆明老师25 天前
ASP.NET Core 9 Web Api 启用 Swagger
swagger·dotnet
励志成为糕手3 个月前
大数据MapReduce架构:分布式计算的经典范式
大数据·hadoop·mapreduce·分布式计算·批处理
问道飞鱼6 个月前
Flink 高可用集群部署指南
flink·部署·批处理·流式批处理
vfvfb6 个月前
bat批量去掉本文件夹中的文件扩展名
服务器·windows·批处理·删除扩展名·bat技巧
疯狂学习GIS7 个月前
Python的ArcPy基于Excel表格对大量遥感影像批量重分类
python·arcpy·批处理·遥感数据·遥感影像·重分类·栅格重分类
TeamDev7 个月前
DotNetBrowser 3.2.0 版本发布啦!
.net·dotnet·chromium·winforms·dotnetbrowser·avalonia ui·user agent