Differences between using Table aliases in delete and update in sqlserver and oracle

Source: Internet
Author: User

Yesterday, we found that the data analysis results in the program were incorrect. After the analysis was performed again, the original data was still there and the fields with values were accumulated. The heart said, No, It was analyzed only after record generation. Forgot to DELETE? Check the code and find a delete statement. Therefore, the query analyzer executes the statement and reports an error. I have tried it several times. Now, Delete From does not recognize the table name alias! Looking back, after the program was changed, it was mainly tested in Oracle. SQLServer has not been tested in detail.

The alias is used because the where condition requires the use of subqueries to write some conditions. The following statements are not as complex as they are described below.

Conclusion:

(Applicable to ORACLE) delete from tablea a where a. FIELD1 = 10
(For SQLSERVER) delete tablea from tablea a where a. FIELD1 = 10
(Ora \ SQL applies) DELETE FROM TABLEA WHERE TABLEA. FIELD1 = 10

Two points of experience:

1. the test should be comprehensive;
2. Be confident and take into account all the situations when writing a program.

Update Status

Update T_report
Set a. status = '1'
Where a. report_Seq = 1234

Execution failed

Update
Set a. status = '1'
From T_report
Where a. report_Seq = 1234

Execution successful

So do a general program and do not use aliases.

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.