SQL statement exercise-update and delete data

Source: Internet
Author: User

========================================================== ==================================

Title: SQLStatement exercise-Update and delete data

Note: SQL SERVER 2000

Date: 2011.4.17

Name: Zhu minglei

========================================================== ==================================

1Update a row and a column

UPDATE MERs

SET cust_email = 'Kim @ thetoystore.com'

WHERE cust_id = '123'

Verify whether the update is successful:

SELECT cust_id, cust_email

FROM MERs

WHERE cust_id = '123'

2Update a row with multiple columns

UPDATE MERs

SET cust_contact = 'Sam Roberts ',

Cust_email = 'Sam @ toyland.com'

WHERE cust_id = '123'

Verify whether the update is successful:

SELECT cust_id, cust_contact, cust_email

FROM MERs

WHERE cust_id = '123'

 

3Update all rows and columns

UPDATE MERs

SET cust_email = 'Kim @ thetoystore.com'

Verify whether the update is successful:

SELECT cust_email FROM MERs

 

Exercise caution when updating data. If the WHERE clause is missing, all rows in the table are updated.

4Delete a row

Delete from MERs

WHERE cust_id = '123'

Verify whether the update is successful:

 

5Deletes the value of a column.

UPDATE MERs

SET cust_email = NULL

6Delete all rows

Delete from MERs

Note: although all rows of the Customers table are deleted, the Customers table itself is not deleted.

7Delete all rows in the TABLE, with a faster TRUNCATE TABLEStatement.(SQlite does not support this statement)

 

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.