public override void DropTable(DbConnection connection, DiscoveredTable tableToDrop) { SqlCommand cmd; switch (tableToDrop.TableType) { case TableType.View: if (connection.Database != tableToDrop.Database.GetRuntimeName()) { connection.ChangeDatabase(tableToDrop.GetRuntimeName()); } if (!connection.Database.ToLower().Equals(tableToDrop.Database.GetRuntimeName().ToLower())) { throw new NotSupportedException("Cannot drop view " + tableToDrop + " because it exists in database " + tableToDrop.Database.GetRuntimeName() + " while the current current database connection is pointed at database:" + connection.Database + " (use .ChangeDatabase on the connection first) - SQL Server does not support cross database view dropping"); } cmd = new SqlCommand("DROP VIEW " + tableToDrop.GetWrappedName(), (SqlConnection)connection); break; case TableType.Table: cmd = new SqlCommand("DROP TABLE " + tableToDrop.GetFullyQualifiedName(), (SqlConnection)connection); break; case TableType.TableValuedFunction: DropFunction(connection, (DiscoveredTableValuedFunction)tableToDrop); return; default: throw new ArgumentOutOfRangeException(); } using (cmd) cmd.ExecuteNonQuery(); }
protected override string GetRenameTableSql(DiscoveredTable discoveredTable, string newName) { string oldName = discoveredTable.GetWrappedName(); var syntax = discoveredTable.GetQuerySyntaxHelper(); if (!string.IsNullOrWhiteSpace(discoveredTable.Schema)) { oldName = syntax.EnsureWrapped(discoveredTable.Schema) + "." + oldName; } return(string.Format("exec sp_rename '{0}', '{1}'", syntax.Escape(oldName), syntax.Escape(newName))); }
protected override string GetRenameTableSql(DiscoveredTable discoveredTable, string newName) { var syntax = discoveredTable.GetQuerySyntaxHelper(); return(string.Format("RENAME TABLE {0} TO {1};", discoveredTable.GetWrappedName(), syntax.EnsureWrapped(newName))); }