删除 MS SQL Server 中的列 [英] Deleting columns in MS SQL Server

查看:31
本文介绍了删除 MS SQL Server 中的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从现有表中删除列?

How do I delete a column from an existing table?

推荐答案

您要查找的命令是:

alter table tblName drop column columnName

其中 tblName 是表的名称,columnName 是列的名称,但您可能需要先做一些事情.

where tblName is the name of the table and columnName is the name of the column, but there's a few things you may need to do first.

  • 如果该列有任何外键引用,您需要先删除它们.
  • 如果有使用该列的索引,您需要删除它或将其调整为不使用该列.

请记住,此命令的性能不一定很好.一种选择是等待停机时间,当您可以确定没有人会访问数据库时,重命名当前表,然后使用 create tableinsert into ...选择从转移你不想删除的列.

Keep in mind that the performance of this command may not necessarily be good. One option is to wait for a down-time period when you can be certain no-one will be accessing the database, rename the current table, then use create table and insert into ... select from to transfer the columns you don't want deleted.

Oracle 的最新版本之一实际上具有软删除功能,它可以仅将列标记为未使用,而无需物理删除它.它具有相同的效果,因为您无法再引用它,并且有一个与 alter table ... drop unused columns 类似的命令,该命令旨在在安静时间运行,从而完成艰苦的工作实际删除它.

One of the later releases of Oracle actually has a soft delete which can just marks a column as unused without removing it physically. It has the same effect since you can no longer reference it and there's a command along the lines of alter table ... drop unused columns which is meant to be run in quiet time, which does the hard work of actually removing it physically.

这样做的好处是可以立即消失"列,而不会在繁忙时期拖累数据库性能.

This has the advantage of "disappearing" the columns immediately without dragging down database performance during busy times.

这篇关于删除 MS SQL Server 中的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆