MySQL Table logging operations

Source: Internet
Author: User
Tags logical operators

1. Add Table record

<1> Insert a record: Insert [into] tab_name (field1,filed2,.......) VALUES (value1,value2,.......);                            <2> Insert multiple records: Insert [into] tab_name (field1,filed2,.......) VALUES (value1,value2,.......),            (value1,value2,.......), ...                               ; <3>Set insert: Insert [into] tab_name set field name

2. Modify Table Records

Update Tab_name set Field1=value1,field2=value2,...... [WHERE statement]

3. Delete Table records

 from Tab_name [where ....] Way 2:truncate table emp_new;             /*                 If you do not follow the WHERE statement delete data from the entire table delete            can only be used to delete a row of records delete            statement can only remove the contents of the table, cannot delete the table itself, want to delete the table, with drop            TRUNCATE Table can also delete all the data in the table, the word sentence first destroys the table, and then creates a new table. Data that is deleted in this manner cannot be recovered in a            transaction.            */

4. Querying table Records

-- query syntax   :*| field1,filed2   ... From Tab_name                  WHERE condition                  GROUP by field have                  filter                  ORDER by field limit                  number of bars --  The order in which MySQL executes the SQL statement:                from  where  select  GROUP by has  order by

5.where words

(1) Filter Query

--the WHERE clause can be used:--comparison operators:> < >= <= <>! =between80 and100values from 10 to 20inch(80,90,100) value is 10 or 20 or'yuan%'/*the pattern can be%or _, if it is%It means any number of characters, such as Tang's monk, Tang Guoqiang If _ is a word 唐 _, only the Tang priest in accordance with. Two _ means two characters: __*/         --Logical operators can use logical operators directly in multiple conditions and or  not

Example

--* from emp WHERE age>24; --* from emp WHERE dep=" Teaching Department " and gender="male" ;

(2) Order order

- -from Tab_name order by field [asc|  DESC]         --ASC Ascending, desc Descending, where ASC is the default value the ORDER BY clause should be at the end of the SELECT statement.

Example

--* from emp ORDER by age DESC; --* from emp ORDER by salary;

(3) Group by group query

The GROUP BY statement groups The result set based on a column. On the grouped columns we can use COUNT, SUM, AVG and other functions to make related queries.

-- syntax:  SELECT column_name, function (column_name) from  table_name  WHERE column_name operator Value  GROUP by column_name;

(4) Limit record Bar number limits

 from Examresult Limit 1 from Examresult limit 2,5;        -  -from Examresult limit 2, 2;

(5) Regular expressions

' ^yu '  'yun$'m{2}';

MySQL table logging operations

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.