SQL Server Database Tutorial Three, add, delete, modify, table column

Source: Internet
Author: User

To modify the table design of a database, you can use the SQL ALTER TABLE statement, which is used to add, delete, or modify table columns in an existing table.

  1> add a new column to the database table:

Grammar:

ALTER table name ADD column name data type

For example: Add a new column birthday in the persons table below, with a data type of varchar (50)

Enter the following syntax in the new query:

ALTER TABLE ADD varchar (+)

The results after insertion are as follows:

2> to delete columns from a table in a database table:

Grammar:

ALTER table table name DROP column name

For example:

Delete the table design of the Birthday column in the persons table, and this column of data is also deleted.

ALTER TABLE DROP Birthday

3> Changing the database table data type:

This statement is used to change the data type of a column of data in a database when the database is designed.

Grammar:

Alter TAVLE table name ALTER COLUMN name new data type

For example:

In the previous persons table, the birthday data type is varchar (50), but now to change the data type to the text type, the statement is as follows:

ALTER TABLE ALTER text

SQL Server Database Tutorial Three, add, delete, modify, table column

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.