SQL Essentials----DELETE and UPDATE

Source: Internet
Author: User

Knowledge point 1

Delete----Remove values from a single row or all rows

DELETE  from my_foods--my_foods is the table that contains the row to be deleted WHERE  ='bread';

Delete differs from SELECT: Delete does not need to specify the deleted object, because he is cruel and will delete all columns of the entire row.

Therefore, delete cannot delete the values in a column or all the values of a column in a single row, but you can delete one or more rows (as determined by the where statement). The collocation keyword in the WHERE clause, similar to the use of select, such as like, in, between, can be used here, and all conditions will more accurately require the RDBMS to delete specific rows.

If you want to modify a column value for a row, you can use delete and insert mates to do this: first make sure the value you want to change is the value you really need (because it's hard to recover), then insert the data, delete the original data

SELECT * fromMy_foodsWHEREBreakfast= 'Milk';
INSERT intoMy_foodsVALUES('Bread+milk');
DELETE fromMy_foodsWHEREBreakfast= 'Milk';

The disadvantage of this is that you need to re-enter the same data for all the rows once and reduce the efficiency! Update can simplify this problem!

Knowledge Point 2

UPDATE---Change the value of a single column or all columns (without the where it will modify all the data in that column to the new value)

UPDATE My_foods SET = ' Bread '

If you need to update a single row or multiple rows, everything needs to be given to where to decide

UPDATE my_foods   ---Select the updated table set='bread' --set the value of the column why     breakfast = ' milk ';  --Positioning

...

Of course, SET can not only assign values to various data types, but can also apply some basic operations, functions, and so on.

UPDATE My_foods SET = + 1 WHERE inch ('bread','milk');

SQL Essentials----DELETE and UPDATE

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.