TAILIEUCHUNG - SQL PROGRAMMING STYLE- P19

SQL PROGRAMMING STYLE- P19:Im mot trying to teach you to program in SQL in this book. You might want to read that again. If that is what you wanted, there are better books. This ought to be the second book you buy, not the first. I assume that you already write SQL at some level and want to get better at it. If you want to learn SQL programming tricks, get a copy of my other book, SQL for Smarties (3rd edition, 2005). | Avoid UNIONs 127 HAVING MAX payment_status F AND MIN payment_status F The self-reference and correlation are complicated for both humans and machines. Most optimizers are not smart enough to flatten the first query like this. Exceptions If you have a problem that is easier to understand with correlated subqueries and your optimizer is good then don t be so afraid of them. Avoid UNIONs Rationale UNIONs are usually not well optimized. Because they require that redundant duplicates be discarded they force most SQL engines to do a sort before presenting the result set to the user. If possible use UNION ALL instead. You should never have to build a chain of UNIONs from the same base table. That code can be written with OR-ed predicates or CASE expressions. As an example of a horrible misuse of SQL Chris White posted a procedure that built dynamic SQL that would then build a report. Aside from the obvious violations of basic software engineering the output was so huge that it exceeded the text size limits of SQL Server. He was attempting to construct an entire report in the database by using UNIONs to get the 12 lines of the report in the right order by assigning them a letter of the alphabet. The whole thing would take several pages to show but it is an extraction of the printout lines that were constructed from just the General Ledger. I have not attempted to clean up much of the code so there are many violations of good coding rules in this snippet. UNION SELECT DISTINCT J AS section NUMBER CHECKS AS description AS branch COUNT DISTINCT AS total1 0 AS total2 FROM GeneralLedger AS GL WHERE start_period AND end_period AND period_yr 128 CHAPTER 6 CODING CHOICES AND IN 3020 AND IN CD UNION SELECT DISTINCT C AS section CASH RECEIPTS AS description AS branch SUM -1 AS totall 0 AS total2 FROM GeneralLedger AS GL WHERE start_period AND end_period AND .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.