SQL coding specifications and SQL coding specifications

Source: Internet
Author: User

SQL coding specifications and SQL coding specifications

1. aliases must be created for tables to facilitate the use of columns in the questionnaire.


For example, select owner, object_id, name from a, B where a. id = B. id;

If you do not use an alias for a table, how can I know which table the accessed column belongs. If there are hundreds of rows of SQL, if there are many SQL tables associated, let's go.


2. database object naming


Table prefix/suffix T_XXX

View prefix/suffix V_XXX

Materialized View prefix/suffix MV_XXX

Index IDX _ column name


Special table

Data Warehouse FACT table _ FACT

Data Warehouse dimension table _ DIM

Business intermediate table _ TMP

LOG table _ LOG


This naming convention makes it easier for developers to get started with DBAs who are not familiar with the business.



3. Standard Quantum queries are strictly prohibited (paging can be written)


Select (select... from a where a. id = B. id) from B; --- this is called scalar query.


If B returns 100 w, a may be scanned times and you know it is dead.


All scalar queries are rewritten to select... from a left join B .....



4. SQL nested udfs, packages, and stored procedures are prohibited


The principle is the same as that of scalar queries.


5. It is strictly prohibited to select a view that contains ROWNUM create or replace view... select rownum


Influence on predicate push + view merge


6. order by is not allowed in the view.


Interference execution plan


7. It is strictly prohibited to apply more than two views, because changing the innermost view may affect the outermost High Cohesion and low coupling.


If there is a problem with the innermost view, all the SQL statements that call this view will go wrong, and all the rewrite code will die for you.


8. in exists, not in not exists is rewritten as with as (subquery)


Leave this blank. register now.


9. The pages cannot contain distinct, group by, union/union all, and order by can only be one table.


Come sign up, don't say why?


10. Associate update, which can be changed to merge or rowid update


11. Do not use a function for the join column, such as where trunc (time) = B. Time


12. Note implicit conversion.


13. omitted... registration is available

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.