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);
                }
            }
        }
    }
}

执行之后

参考

相关推荐
疯狂学习GIS5 天前
Python的ArcPy基于Excel表格对大量遥感影像批量重分类
python·arcpy·批处理·遥感数据·遥感影像·重分类·栅格重分类
TeamDev7 天前
DotNetBrowser 3.2.0 版本发布啦!
.net·dotnet·chromium·winforms·dotnetbrowser·avalonia ui·user agent
Iotfsd17 天前
.NET写的开源工业物联网网关(IoTGateway)
物联网·c#·.net·dotnet·边缘网关·雾计算·工业物联网智能网关
lindexi17 天前
dotnet 9 通过 AppHostRelativeDotNet 指定自定义的运行时路径
dotnet
宇宙无敌花心大萝卜2 个月前
使用BAT批处理加PYTHON进行WORD批量文字删除
python·word·bat·批处理
lindexi2 个月前
dotnet 源代码生成器分析器入门
dotnet
宇宙无敌花心大萝卜2 个月前
使用bat批量获取WORD中包含对应字符的段落,段落使用回车换行
开发语言·word·bat·批处理·vbs
朝野布告2 个月前
记一次.NET内存居高不下排查解决与启示
.net·dotnet·内存泄露·k8s部署
类人_猿3 个月前
PhotoShop批处理
ui·photoshop·批处理·photoshop批处理
LabVIEW开发3 个月前
LabVIEW 中 dotnet.llb 库功能
labview·dotnet