SQL ALTER TABLE Syntax and instance tutorial

Source: Internet
Author: User

SQL ALTER TABLE Syntax and instance tutorial

The ALTER TABLE statement allows you to change the structure of a table after it has been created. New column can be added to the address clause. Existing columns may be deleted from the list of drop clauses used.

The syntax for 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 part of the Ansi/iso standard. This means that all SQL implements different terms and commands syntax for commercial dialects.

Example #

ALTER TABLE Orders
ADD Quantity SMALLINT

This example adds a column to the order table by specifying the name and data type of the new column.

Sample case
ALTER TABLE employeeaddresstable
ADD Description VARCHAR DEFAULT ' USA ' not NULL

This example adds a column named "description" to the Employeeaddresstable table. We also add reserved words that are NOT NULL, require valid data to be added to the column, and specify a default value.

such as #3

ALTER TABLE antiqueowners DROP COLUMN State

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.