TAILIEUCHUNG - SQL PROGRAMMING STYLE- P7

SQL PROGRAMMING STYLE- P7: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). | Bad Programming in SQL and Procedural Languages 187 but it at least follows the specs that were given without making too many guesses as to what should have been done. But can we do this without a loop and get a pure nonprocedural SQL solution Yes there are several ways Because the purpose of finding this weekday number is to insert a row in the table why not do that in one procedure instead of finding the number in a function and then doing the insertion in another procedural step. Think at the level of a whole process and not in sequential steps. This first answer is ugly looking and difficult to generalize but it is fast if the optimizer factors out the tabular subquery in the WHEN clauses and computes it once. It also uses no local variables. CREATE PROCEDURE InsertNewWeekDay IN new_week_nbr INTEGER LANGUAGE SQL INSERT INTO WeeklyReport week_nbr day_nbr VALUES new_week_nbr CASE WHEN 1 NOT IN SELECT day_nbr FROM WeeklyReport WHERE week_nbr new_week_nbr THEN 1 WHEN 2 NOT IN SELECT day_nbr FROM WeeklyReport WHERE week_nbr new_week_nbr THEN 2 WHEN 3 NOT IN SELECT day_nbr FROM WeeklyReport WHERE week_nbr new_week_nbr THEN 3 WHEN 4 NOT IN SELECT day_nbr FROM WeeklyReport WHERE week_nbr new_week_nbr THEN 4 WHEN 5 NOT IN SELECT day_nbr FROM WeeklyReport WHERE week_nbr new_week_nbr THEN 5 WHEN 6 NOT IN SELECT day_nbr FROM WeeklyReport WHERE week_nbr new_week_nbr THEN 6 WHEN 7 NOT IN 188 CHAPTER 10 THINKING IN SQL SELECT day_nbr FROM WeeklyReport WHERE week_nbr new_week_nbr THEN 7 ELSE NULL END null will violate primary key The thought process was to get the entire set of weekday numbers present in the week and then compare them to each value in an ordered list. The CASE expression is just a way to hide that list. Although it is a step forward it is not yet really a set-oriented solution. Here is another version that uses a table constructor. This is more compact and easy to generalize. Here we are actually using a set-oriented solution We are subtracting the set of

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.