MySQL inserts data, mysql inserts data

Source: Internet
Author: User

MySQL inserts data, mysql inserts data

INSERT data

  • Insert complete rows
  • Insert Part of a row
  • Insert multiple rows
  • Insert query results
Insert the complete row and check the original customer list first:

INSERT a row: insert into customersVALUES (NULL, 'pep E. laPew ', '2014 Main Street', 'Los Angeles ', 'CA', '000000', 'USA', NULL, NULL );


Another way is to specify the column name. In this way, when the table structure changes, its SQL statement can still be used, and this assignment does not need to be the same as the original table structure.

INSERT multiple rows you can combine multiple INSERT statements:
INSERT... VALUES (,,,,);
INSERT... VALUES (,); in this way, you can INSERT two records. If the column names to be inserted are the same, you can merge the INSERT statements as follows:
Insert into name (,) // the same column name values (,) will be used for subsequent inserts of multiple records (,,,,,,,,,), (.........), (.........); // In this way, three records are inserted.
Insert the retrieved data is to use the SELECT statement to retrieve the data and insert it into the table as the value of VALUES. The following SQL statement combines the custnew table into the customer table:
Insert into MERs (cust_id, cust_contact, cust_email, cust_name, cust_address, region, cust_state, region) SELECT cust_id, cust_contact, upper, cust_name, cust_address, lower, cust_state, lower, cust_countryFROM custnew;






Insert mysql Data

Enter

Mysql-u root-p and press enter to prompt you to enter the password

This prompt will appear after you enter mysql after entering the password.

Mysql-> enter the database where your test table is located. -- Do not forget the seal.

Then execute insert into test (a, B, c) VALUES (, 3)

The premise is that your test table contains column a, column B, and column c.
Insert a value of 1, 2, 3 for column a B and column c.

Of course you can.
Insert test (a, B, c) select 1, 2, 3

How to add data to the mysql table

How can this problem be solved? Pay attention to the consistency between the data type added and the table creation.

Example:

// Create a table
Create table tab_nam (
Age int,
Name char (10)
)

// Insert data
Insert into tab_nam (age, name) values (11, 'aaa ')
Insert into tab_nam (age, name) values (22, 'bbb ')
......

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.