tailieunhanh - Giải pháp thiết kế web động với PHP - p 46

Chapter 16 Managing Multiple Database Tables The previous chapter showed you how to use INNER JOIN and LEFT JOIN to retrieve information stored in multiple tables. You also learned how to link existing tables by adding an extra column to the child table and updating each record individually to insert a foreign key. However, most of the time, you ll want to insert data simultaneously in both tables. That presents a problem, because INSERT commands can operate on only one table at a time. You need to get around this restriction by constructing scripts that handle the INSERT operations in the correct. | Chapter 16 Managing Multiple Database Tables The previous chapter showed you how to use INNER JOIN and LEFT JOIN to retrieve information stored in multiple tables. You also learned how to link existing tables by adding an extra column to the child table and updating each record individually to insert a foreign key. However most of the time you ll want to insert data simultaneously in both tables. That presents a problem because INSERT commands can operate on only one table at a time. You need to get around this restriction by constructing scripts that handle the INSERT operations in the correct sequence starting with the parent table so that you can get the new record s primary key and insert it in the child table at the same time as other details. Similar considerations also need to be taken into account when updating and deleting records. The code involved isn t difficult but you need to keep the sequence of events clearly in mind as you build the scripts. This chapter guides you through the process of inserting new articles in the blog table optionally selecting a related image or uploading a new one and assigning the article to one or more categories all in a single operation. Then you ll build the scripts to update and delete articles without destroying the referential integrity of related tables. You ll also learn about foreign key constraints which control what happens if you try to delete records that still have a foreign key relationship in another table. The widely used MyISAM storage engine doesn t currently support foreign key constraints but they are supported by InnoDB the default storage engine in MySQL and later. This chapter describes how to work with both storage engines. In particular you ll learn about the following Inserting updating and deleting records in related tables Finding the primary key of a record immediately after it has been created Converting a table s storage engine Establishing foreign key constraints between InnoDB tables .

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã 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.