MySQL Operations Data Sheet Records

Source: Internet
Author: User

1 The number of selected columns to the front

ALTER TABCE table name MODIFY column name and column number name type first;

2 modifying column number name types

ALTERTABCE Table name MODIFY Name of column name of new column;

3 Modifying a data table name

First Kind ALTERTABCE the original table name RENAME the new table name;

The second Kind renametable New table name to the original table name;

4 Inserting records

First Kind the INSERT table name requires the copied column values (the value to be copied ); This is the use of copying only one field

The second Kind INSERT table name VALUES (NULL or DEFAULT, such as ' name ', ' Password ', ' age ', serial number);

The third type of INSERT Table name SET User name = name, user password = password; (only one bar can be inserted)

5 Viewing Records

SELECT * from table name;

6 inserting more than one record

The first INSERT table name VALUES (null or DEFAULT, such as ' name ', ' Password ',' age ', ordinal), (null, as ' Name ', ' Password ', ' age ', serial number);

The second Kind INSERT table name SET user name =' name ', password =' password you want to fill ';

7 Single-Table updates

7.1 Update a field

UPDATE table name set Age = Age + The number you want to add, (Add the value you fill in your original value)

7.2 Updating multiple fields

UPDATE table name SET Age = Age - such as ID, such as sex=0; (minus or set in your original value)

7.3 Adding conditions to the update

UPDATE table name SET Age = age +10 where is id%2=0; (Add the value you filled in your original value plus the criteria such as ID is an even number to be updated)

8 Single Table Delete record

Delete from table name where id=6,(delete information with ID 6 ) and then insert ID will only go back to the rear, not the number of deletions

9 Query The column you want to check

SELECT column name, column name from;

10 Aliases for query columns

SELECT such as id as userid,username as uname from table name ;

11 Query Result grouping

SELECT column name from table name GROUP by column name ;

12 Grouping conditions

SELECT column name from table name GROUP by 1 have cound (ID) >=2; ( the ID of the list name when grouping is greater than or equal to 2)

13 Sorting the results of a query

First SELECT * from table name ORDER by column name DESC; ( descending )

Second SELECT * from table name ORDER by column name; ( Ascending)

The third SELECT * from table name ORDER by column name, such as ID DESC; (sort The ID of the column name in descending order)

14 Restricting query Results

SELECT * from table name LIMIT 2; ( query the first two information in the list )

15 placing the query results in the specified list

INSERTNew list namecolumn names, such asusername)SELECTcolumn name (as in previous) fromOriginal table nameWHEREcolumn names, such as Age)>=30; (will beusernameand theAGgreater than or equal to -values into the specified list)










MySQL Operations Data Sheet Records

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.