mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-01 10:10:16 +08:00
Add RenameTable
This commit is contained in:
parent
ad222950ea
commit
80c8e8b8c2
@ -281,6 +281,13 @@ namespace SqlSugar
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual bool RenameTable(string oldTableName, string newTableName)
|
||||
{
|
||||
string sql = string.Format(this.RenameTableSql, oldTableName,newTableName);
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Private
|
||||
|
@ -49,6 +49,7 @@ namespace SqlSugar
|
||||
protected abstract string AddTableRemarkSql { get; }
|
||||
protected abstract string DeleteTableRemarkSql { get; }
|
||||
protected abstract string IsAnyTableRemarkSql { get; }
|
||||
protected abstract string RenameTableSql { get; }
|
||||
#endregion
|
||||
|
||||
#region Check
|
||||
|
@ -44,6 +44,7 @@ namespace SqlSugar
|
||||
bool AddTableRemark( string tableName, string description);
|
||||
bool DeleteTableRemark(string tableName);
|
||||
bool IsAnyTableRemark(string tableName);
|
||||
bool RenameTable(string oldTableName,string newTableName);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -224,6 +224,13 @@ namespace SqlSugar
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
protected override string RenameTableSql {
|
||||
get
|
||||
{
|
||||
return "alter table {0} rename {1}";
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
@ -217,6 +217,13 @@ namespace SqlSugar
|
||||
return "select * from user_tab_comments where Table_Name='{0}'order by Table_Name";
|
||||
}
|
||||
}
|
||||
|
||||
protected override string RenameTableSql {
|
||||
get
|
||||
{
|
||||
return "alter table {0} rename to {1}";
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
@ -229,9 +229,9 @@ namespace SqlSugar
|
||||
" FROM sys.tables A" +
|
||||
" LEFT JOIN sys.extended_properties C ON C.major_id = A.object_id" +
|
||||
" LEFT JOIN sys.columns B ON B.object_id = A.object_id AND C.minor_id = B.column_id" +
|
||||
" INNER JOIN sys.schemas SC ON SC.schema_id = A.schema_id AND SC.name = 'dbo'"+
|
||||
" INNER JOIN sys.schemas SC ON SC.schema_id = A.schema_id AND SC.name = 'dbo'" +
|
||||
" WHERE A.name = '{1}' and b.name = '{0}'";
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -264,6 +264,14 @@ namespace SqlSugar
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected override string RenameTableSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "EXEC sp_rename '{0}','{1}'";
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
public override bool CreateTable(string tableName, List<DbColumnInfo> columns, bool isCreatePrimaryKey = true)
|
||||
@ -271,7 +279,8 @@ namespace SqlSugar
|
||||
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
||||
string sql = GetCreateTableSql(tableName, columns);
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
if (isCreatePrimaryKey) {
|
||||
if (isCreatePrimaryKey)
|
||||
{
|
||||
var pkColumns = columns.Where(it => it.IsPrimarykey).ToList();
|
||||
foreach (var item in pkColumns)
|
||||
{
|
||||
|
@ -209,6 +209,14 @@ namespace SqlSugar
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
protected override string RenameTableSql
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
Loading…
Reference in New Issue
Block a user