MySQL data insertion, update, and deletion

Source: Internet
Author: User

In the previous section, creating a data table, this article describes the data insertion after the CREATE table:


First, insert INTO ... values ... Insert

INSERT INTO TableName (COLUMN1,COLUMN2,COLUMN3) VALUES (' character type 1 ', ' character 2 ', ' character 3 ');

1. You can omit the column name, but the value after values should correspond to column one by one in the table.

INSERT INTO tablename values (' character 1 ', ' character type 2 ', ' character 3 ');

2, you can add a few column names, and then corresponding to increase the value of these items,

INSERT INTO TableName (COLUMN1,COLUMN3) VALUES (' character type 1 ',, ' character 3 ');

3, can add a few rows of values, separated by commas

INSERT INTO TableName (COLUMN1,COLUMN2,COLUMN3) VALUES (' character type 1 ', ' character 2 ', ' character 3 '),

(' character type 21 ', ' character Type 22 ', ' character 23 ');

4, or use multiple INSERT statements

INSERT INTO TableName (COLUMN1,COLUMN2,COLUMN3) VALUES (' character type 1 ', ' character 2 ', ' character 3 ');

INSERT INTO TableName (COLUMN1,COLUMN2,COLUMN3) VALUES (' character type 21 ', ' character 22 ', ' character 23 ');

Second, by insert INTO ... set ... Syntax insertion

INSERT INTO TableName set column1= ";

Third, ensure the uniqueness of the column values

ALTER TABLE tablename add unique (column);

By adding a unique to the column, ensure that the column values are incremented if repeated, an error is raised.

Iv. Updating column values

Update tablename set column1= "where ... A filter statement that specifies that the column values of a row are modified, not all column values.

V. Delete a row of values

Delete from tablename where colunm1= ...;

Vi. Deleting table contents

Delete from TableName; All column values in the table are removed, and automatically growing columns are not reset.

or TRUNCATE TABLE tablename; Clear table, Reset Auto Add column (auto_increment)

MySQL data insertion, update, and deletion

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.