TAILIEUCHUNG - SQL PROGRAMMING STYLE- P16

SQL PROGRAMMING STYLE- P16: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). | 142 CHAPTER 7 HOW TO USE VIEWS ON DELETE CASCADE start_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL end_date TIMESTAMP CHECK start_date end_date job_type INTEGER DEFAULT 99 NOT NULL CHECK job_type 99 CREATE TABLE Job_not99_Assignments store_nbr INTEGER NOT NULL REFERENCES Stores store_nbr ON UPDATE CASCADE ON DELETE CASCADE ssn CHAR 9 NOT NULL PRIMARY KEY REFERENCES Personnel ssn ON UPDATE CASCADE ON DELETE CASCADE start_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL end_date TIMESTAMP CHECK start_date end_date job_type INTEGER DEFAULT 0 NOT NULL CHECK job_type BETWEEN 0 AND 98 -no 99 code Then build a UNION-ed VIEW CREATE VIEW JobAssignments store_nbr ssn start_date end_date job_type AS SELECT store_nbr ssn start_date end_date job_type FROM Job_not99_Assignments UNION ALL SELECT store_nbr ssn start_date end_date job_type FROM Job_99_Assignments The key and job_type constraints in each table working together will guarantee only one manager per store. The next step is to add INSTEAD OF triggers to the VIEW so that the users can insert update and delete from it easily. As an exercise for the reader How would you ensure that no store has more than two assistant managers Updatable VIEWs 143 Updatable VIEWs The SQL-92 standard is actually conservative about which VIEWs are updatable. They have to be based on the following 1. A SELECT statement on one and only one table but the VIEW can be defined on several layers of VIEWs on top of VIEWs. 2. The VIEW must include all of the columns of a UNIQUE or PRIMARY KEY constraint in the base table. This guarantees that all of the rows in the VIEW map back to one and only one row in the base table from which it is derived. 3. All base table columns not shown in the VIEW must have default values or be NULL-able. The reason for that is obvious You have to delete or insert a complete row into the base table so the system must be able to construct such a row. However other VIEWs are updatable and some vendors support .

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.