TAILIEUCHUNG - Hướng dẫn học Microsoft SQL Server 2008 part 42

Phần đầu của câu truy vấn kết hợp xác định các bảng mục tiêu và nguồn và cách chúng liên quan. Sau khi định nghĩa bảng, có một điều khoản bắt buộc đối với mỗi sự kết hợp phù hợp, như trong cú pháp này đơn giản: | Part II Manipulating Data With Select The first section of the merge query identifies the target and source tables and how they relate. Following the table definition there s an optional clause for each match combination as shown in this simplified syntax MERGE TargetTable USING SourceTable ON join conditions WHEN Matched THEN DML WHEN NOT MATCHED BY TARGET THEN DML WHEN NOT MATCHED BY SOURCE THEN DML Applying the MERGE command to the airline check-in scenario there s an appropriate action for each match combination If the row is in both FlightPassengers the target and CheckIn the source then the target is updated with the CheckIn table s seat column. If the row is present in CheckIn the source but there s no match in FlightPassenger the target then the row from CheckIn is inserted into FlightPassenger. Note that the data from the source table is gathered by the INSERT command using INSERT. .VALUES. If the row is present in FlightPassenger the target but there s no match in CheckIn the source then the row is deleted from FlightPassenger. Note that the DELETE command deletes from the target and does not require a WHERE clause because the rows are filtered by the MERGE command. Here s the complete working MERGE command for the scenario MERGE FlightPassengers F USING CheckIn C ON AND AND AND WHEN Matched THEN UPDATE SET WHEN NOT MATCHED BY TARGET THEN INSERT FirstName LastName FlightCode FlightDate Seat VALUES FirstName LastName FlightCode FlightDate Seat WHEN NOT MATCHED BY SOURCE THEN DELETE The next query looks at the results of the MERGE command returning the finalized passenger list for SQL Server Airlines flight 2008 SELECT FlightID FirstName LastName FlightCode FlightDate Seat FROM FlightPassengers 372 Modifying Data 15 Result FlightID FirstName LastName FlightCode FlightDate Seat 1 Paul Nielsen SS2008 2009-03-01 9F 2 Sue Jenkins

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.