0

我有两个表,每个表都有一个名为 email_addr 的列。在将新记录插入数据库之前,我需要它首先检查这两个表中的每个表中的重复项。

         CREATE TRIGGER del_chk AFTER DELETE ON list_no_email
         FOR EACH ROW
         BEGIN
                INSERT INTO list_email(list_name, fname, lname, email_addr)
                VALUES (?,?,?,?,?)
         END;//
         delimiter ;
         LOAD DATA INFILE $_FILES[''userfile']
         REPLACE INTO TABLE list_no_email
         FIELDS
                TERMINATED BY ','
         LINES
                TERMINATED BY '\n' (email_addr,id);




+------------+--------------+------+-----+-------------------+-----------------------------+
| Field      | Type         | Null | Key | Default           | Extra                       |
+------------+--------------+------+-----+-------------------+-----------------------------+
| id         | int(11)      | NO   | PRI | NULL              | auto_increment              |
| date_in    | timestamp    | NO   |     | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
| email_addr | varchar(150) | YES  |     | NULL              |                             |
+------------+--------------+------+-----+-------------------+-----------------------------+
3 rows in set (0.00 sec)

mysql> desc list_email;
+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| id         | int(11)      | NO   | PRI | NULL    | auto_increment |
| list_name  | varchar(55)  | YES  |     | NULL    |                |
| fname      | char(50)     | YES  |     | NULL    |                |
| lname      | char(50)     | YES  |     | NULL    |                |
| email_addr | varchar(150) | YES  |     | NULL    |                |
+------------+--------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
4

0 回答 0