MySQL's _ additions and deletions to check

Source: Internet
Author: User

Additions and deletions (curd) Curd Explanation: representative creation (create), Updates (update), read (Retrieve), and delete queries basic use
    • Querying all Columns
SELECT * from table name;Example:SELECT * from Classes;
    • Querying a specified column
      Select column 1, column 2,... from table name;
      Example: select Id,name from Classes;
    • Fixed-condition Query
      --Query name for all information of the Li Fei Knife
      SELECT * FROM students where name= "small Li Fei Knife";

      --Query name for all information of the Li Fei Knife
      SELECT * FROM students where id>3;

    • You can use as to specify an alias for a column or table
Select field [As Alias], field [as Alias] from data table where ...;
Example: select name as name, gender as gender from students;
Order of Fields
Select ID as serial number, gender as gender, name as name from students; increase
format: INSERT [into] tb_name [(Col_name,...)] {VALUES | VALUE} ({expr | DEFAULT},...), (...),...
    • Note: The primary key column is autogrow, but requires a placeholder for full column insertion, usually using 0 or default or null to occupy the position, and the actual data will prevail after the insert succeeds
    • Full column Insert: The order of values corresponds to the order of the fields in the table
Insert into table name values (...)Example:INSERT into students values (0, ' Guo Jing ', 1, ' Mongolia ', ' 2016-1-2 ');
    • Partial column insertion: The order of values corresponds to the given column order
Insert into table name (column 1,...) VALUES (value 1,...)Example:INSERT into students (Name,hometown,birthday) VALUES (' Huang Rong ', ' Peach Island ', ' 2016-3-2 ');
    • The above statement can insert a row of data into a table at a time, and you can insert multiple rows of data at once, which can reduce communication with the database
    • Full column multiple row inserts: The order of values corresponds to the given column order
Insert into table name values (...), (...) ...;Example:Insert into classes values (0, ' Python1 '), (0, ' python2 '); Insert into table name (column 1,...) VALUES (value 1,...), (value 1,...) ...;Example:INSERT into students (name) values (' Yang Kang '), (' Yang over '), (' Little Dragon Girl '); modify
format: UPDATE tbname SET col1={expr1| DEFAULT} [, Col2={expr2|default}] ... [Where condition judgment]
Update table name set column 1= value 1, column 2= value 2 ... where conditionExample:Update students set gender=0,hometown= ' Beijing ' where id=5; delete
DELETE from Tbname [where condition judgment]
--Physical deletion
--Delete from table name where condition
Delete from students; --all data in the entire data table is deleted
Delete from students where name= "small Li Fei Knife";

--Logical deletion
--Use a field to indicate whether the message is no longer available.
--Add a is_delete field bit type to the students table
ALTER TABLE students add Is_delete bit default 0;
Update students set is_delete=1 where id=6;

MySQL's _ additions and deletions to check

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.