SQL Server deletes data columns

Source: Internet
Author: User

Delete data columns

The data columns that are built, wrong, or duplicated in the development or production process need to be deleted.

Use the SSMS database management tool to delete data column mode one

1. Open database--Select data Table-"Expand Data Sheet-" Expand Data Column-"Select the data column to delete-" Right click-"SELECT Delete-" in the Pop-up box click OK.

Way Two

1. Open Database-"Open data Sheet-" Right click-"SELECT Design.

2, in the Design view window-"Select the data column to delete-" Right click-"SELECT Delete-" Click the Save button (or Ctrl+s).

Delete a single data column by using a T-SQL script to delete a data column

Syntax: ALTER TABLE data name. dbo. Table name drop column name;

Example: ALTER TABLE [TESTSS].DBO. [Test1] Drop column height3;

Delete multiple data columns

Syntax: ALTER TABLE data name. dbo. Table name drop column name 1, column name 2;

Example: ALTER TABLE [TESTSS].DBO. [Test1] Drop column height1,height2;

Delete a data column with default values

Grammar:

BEGIN TRANSACTION
Go
ALTER TABLE data name. dbo. Table name drop constraint constraint name;
Go
ALTER TABLE data name. dbo. Table name drop column name;

Example:

BEGIN TRANSACTION
Go
ALTER TABLE [TESTSS].DBO. [Test1] drop constraint df__test1__testid__151b244e;
Go
ALTER TABLE [TESTSS].DBO. [Test1] Drop column testid;

Summarize

In the development or testing process, the modification of the column is arbitrary operation, once to the production environment, no matter what the data column problems, do not easily modify and delete, if you have to modify and delete, you must first back up and operation.

SQL Server deletes data columns

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.