sql delete删除列
In this article, we will explore the process of SQL Delete column from an existing table. We will also understand the impact of removing a column with defined constraints and objects on it.
在本文中,我们将探讨从现有表中删除SQL列的过程。 我们还将理解删除具有定义的约束和对象的列的影响。
介绍 (Introduction)
In a relational database, we use the schema design technique Normalizations and split the large tables into smaller tables. It helps to reduce the redundancy and dependency of data. We have multiple normalization forms specified in the following image.
在关系数据库中,我们使用模式设计技术Normalizations并将大型表拆分为较小的表。 它有助于减少数据的冗余性和依赖性。 下图中指定了多种规范化形式。
We do not cover normalization techniques in this article. You can refer to article – What is Database Normalization in SQL Server?
本文不介绍标准化技术。 您可以参考文章– 什么是SQL Server中的数据库规范化?
Suppose you have an existing table with multiple columns. There are specific columns in this table that are not relevant now. You do not require these columns. For example, consider a product table, and in this table, you have a column []. We implemented a separate mechanism to capture product feedback, and this column is not relevant now.
假设您有一个包含多列的现有表。 该表中的某些特定列现在不相关。 您不需要这些列。 例如,考虑一个产品表,在此表中,您有一列[]。 我们实施了一种单独的机制来捕获产品反馈,因此本专栏现在不再相关。
Let’s understand why it is essential to remove unwanted columns from the SQL table. Below is my table structure and we need to remove column having data type varchar(2000).
让我们了解为什么从SQL表中删除不需要的列很重要。 下面是我的表结构,我们需要删除数据类型为varchar(2000)的列。
This table contains 4 million rows, and the user executed the command to select all records from this table.
该表包含400万行,用户执行命令以从该表中选择所有记录。
SELECT * FROM Products;
Capture the actual execution plan (press CTRL + M) of this query along with client statistics (press Shift + Alt + S).
捕获此查询的实际执行计划(按CTRL + M)以及客户端统计信息(按Shift + Alt + S)。
In another query window, execute the query without the [Productfeedback] column and capture the similar statistics.
在另一个查询窗口中,执行不带[Productfeedback]列的查询并捕获类似的统计信息。
SELECT [ProductID]
,[ProductName]
,[ProductLaunchDate]
FROM [SQLShackDemo].[dbo].[Products]
Let’s compare the actual exe