CREATE TABLE ' comment ' (
' c_id ' int (one) not NULL auto_increment COMMENT ' Comment ID ',
' u_id ' int (one) not NULL COMMENT ' user ID ',
' Name ' varchar (not NULL default ' COMMENT ' user name '),
' Content ' varchar (+) not NULL default ' COMMENT ' comment ',
PRIMARY KEY (' c_id ')
) Engine=myisam DEFAULT Charset=utf8;
INSERT into ' comment ' (' c_id ', ' u_id ', ' name ', ' content ') VALUES
(1, 1, ' Zhang Ying ', ' trigger test '),
(2, 1, ' Zhang Ying ', ' solve field redundancy '),
(3, 2, ' tank ', ' make the Code simpler ');
Here is a redundant field name, we can use federated search to find the name of the user table in the read comment, why should have redundant fields, because the simple SQL statement execution is more efficient, but not redundant field more the better, redundant fields are more, also increase the database burden.
What I want to do is, when I update the name of the user table, the trigger updates the comment table at the same time, do not write PHP code to update, when the user is deleted, the comment table, the data about the user will be deleted
Proper redundancy of the MySQL field can help improve query speed