SQL ALTER TABLE syntax and example tutorial

Source: Internet
Author: User

SQL ALTER TABLE syntax and example tutorial

After the alter table statement allows you to change the structure of a TABLE, it is created. Address terms that can be added to a new column. Existing columns may be deleted from the Drop clause table.

The syntax of the alter table statement is as follows:

Alter table table_name
ADD column_name data_type

Alter table table_name
Drop column column_name
Note: The alter table statement is not in the ANSI/ISO standard. This means that all SQL statements implement different terms and command syntax in business dialects.

Example #1

Alter table Orders
ADD Quantity SMALLINT

In this example, add a column to the order table by specifying the name and Data Type of the new column.

Example #2
Alter table EmployeeAddressTable
ADD Description VARCHAR (20) DEFAULT 'usa' NOT NULL

In this example, a column named "Description" is added to the "EmployeeAddressTable" table. We also add a reserved word that is not NULL. valid data is required to be added to this column and a default value is specified.

Example #3

Alter table AntiqueOwners drop column State

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.