TAILIEUCHUNG - Beginning Databases with Postgre SQL phần 5

tạo ra cơ sở dữ liệu mẫu được thảo luận trong Chương 2. Đặc biệt, chương này sẽ bao gồm các chủ đề sau: • Cài đặt PostgreSQL từ những chương trình Linux • Cài đặt Trong chương này, chúng ta nhìn vào cách thức mà chúng ta có thể mở rộng các chức năng của các truy vấn PostgreSQL. | CHAPTER 8 DATA DEFINITION AND MANIPULATION 241 Note Alternatively you can just use the keyword DEFERRED in which case you also need to use the command SET CONSTRAINTS ALL DEFERRED so that PostgreSQL defaults to checking DEFERRED constraints only at the end of transactions. See the online documentation for more details of the SET CONSTRAINTS option. ON UPDATE and ON DELETE An alternative solution is to specify rules in the foreign key constraint about how to handle violation in two circumstances UPDATE and DELETE operations. Two actions are possible We could CASCADE the change from the table with the primary key. We could SET NULL to make the column NULL since it no longer references the primary table. Here is an example CREATE TABLE orderinfo orderinfo_id serial customer_id integer NOT NULL date_placed date NOT NULL date_shipped date shipping numeric 7 2 CONSTRAINT orderinfo_pk PRIMARY KEY orderinfo_id CONSTRAINT orderinfo_customer_id_fk FOREIGN KEY customer_id REFERENCES customer customer_id ON DELETE Cascade This example tells PostgreSQL that if we delete a row in customer with a customer_id that is being used in the orderinfo table it should automatically delete the related rows in orderinfo. This might be what we intended but it is normally a dangerous choice. It is usually much better to ensure applications delete rows in the correct order so we make sure there are no orders for a customer before deleting the customer entry. The SET NULL option is usually used with UPDATE or DELETE statements. It looks like this CREATE TABLE orderinfo orderinfo_id customer_id date_placed date_shipped serial integer NOT NULL date NOT NULL date shipping numeric 7 2 CONSTRAINT orderinfo_pk PRIMARY KEY orderinfo_id CONSTRAINT orderinfo customer_id_fk FOREIGN KEY customer_id REFERENCES customer customer_id ON UPDATE SET NULL u . 242 CHAPTER 8 DATA DEFINITION AND MANIPULATION This says that if the row being referred to by customer_id is deleted from the customer table set the column

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.