Insert, update, and delete tables in the database.

Source: Internet
Author: User

Insert, update, and delete tables in the database.

The most common operations in database tables are insert, update, and delete. Next we will introduce them one by one:

1. insert

When the template statement is used, insert into indicates values.
For example:

Note the following points for insert:
1) insert into-select can insert the search result to another table;
2) The inserted data must be of the same type as the field in the table or can be implicitly converted;

2. update

Update updates existing data.
Example:

Note the following when updating:
1) if there is no where restriction, all data will be updated by default;
2) consistency between the modification operation and the database. If several tables have the same field, after updating a table, check whether the field in other tables needs to be updated. If the table is to be updated but not updated, the table is inconsistent. At this time, the database system introduces the transaction concept to solve this problem.

3. delete

Use the delete from-where statement.
Example:

Delete has the following features:
1) even if all rows are deleted, the table structure is still in;
2) if there is no where clause, delete will delete all rows;
3) before deletion, it is best to first select-where to display some, confirm that these display needs to be deleted, and then execute the delete statement;
4) truncate: It is faster than delete to delete all rows in the table. The cost of using truncate is that errors cannot be restored before changes (rollback ).

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.