About the endangerment of select * (asterisk) in SQL

Source: Internet
Author: User

I heard that there are many people who prohibit developers from using SELECT * in SQL, which translates a stackoverflow question, which is personally considered to be quite objective

The "SELECT *" Hazard mainly includes the following points:

  • Inefficient data transmission to consumers. When you select * often you will query from the database more than your application function actually need too many columns, which may also lead to redundant data from the data to the server to the client, resulting in increased machine burden, the same network transmission will increase the burden. Especially when a new column is added to the data table, but the feature implementation is not needed at all.
  • Index issues. Imagine such a scenario: you need to tune a query to a certain high performance. If you use a SELECT * and then return all columns that exceed the columns you need, the server often needs to consume more of the cost of your data than it would otherwise have. For example, you can't simply create an index that overrides all of the columns you select, even if you do (including all columns, it's scary), the next dig deceptive and add new columns to the datasheet, causing the index you already covered to not be optimized. Then you'll be amazed to see that your query performance pops down without obvious reasons.
  • Binding issues. When you select *, it is possible to query for columns from two tables but with the same name. This may cause the data binding end or function point to crash, think back to have two columns of data is ID, who TM know which column? SELECT * may also disrupt views (partial databases, versions)--when the underlying data table structure changes and the view is not new, the view's data may return meaningless data (the name is poorly maintained?). )。 Worst of all, you can toss the column that you named, but the new dig deceptive to join the column, don't know how he should name the column name will not conflict with the column name you have buried well.

About the endangerment of select * (asterisk) in SQL

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.