if table2 doesn't exist, tryselect name into table2 from table1otherwiseinset into table2 (name) select name from table1>>>>既给table1中的name加入值,table2中的name也相对应地加入相同的值you can add a trigger on table1CREATE TRIGGER trig1
on table1
FOR INSERT
AS 
   insert into table2 (name) select name from inserted
GO

解决方案 »

  1.   

    既然和table1中的name的值一样,我们删除table1中name里的一条记录,table2中name里也相同地删除一条记录
      

  2.   

    sure, you can create a trigger on DELETE tooCREATE TRIGGER trig2
    on table1
    FOR DELETE
    AS 
       delete from table2 where name in (select name from deleted)
    GO
      

  3.   

    :)
     aucer(思归, MS .NET MVP) 大侠可是 CSDN 的头号啦!>>>>
    对于你的问题,建议你使用 InnoDB 表类型,
    由于目前 MySQL 还不支持触发器,
    所以你只能使用 InnoDB 的事务处理来安全地实现将数据同时插入两张表而对于第二个问题,
    使用 InnoDB 的外键约束就可以啦!!!
     If ON DELETE CASCADE is specified, and a row in the parent table is deleted, then InnoDB automatically deletes also all those rows in the child table whose foreign key values are equal to the referenced key value in the parent row.
    更详细的请查看这里
    http://www.innodb.com/ibman.html#InnoDB_foreign_keys
    ON DELETE CASCADE
      

  4.   

    oh, sorry, I thought it was for SQL Server, :-)
      

  5.   

    TO saucer(思归, MS .NET MVP):)美国那边 MySQL 的应用情况怎么样呀
    他们的授权费用怎么交纳的呢?
      

  6.   

    to shuixin13,谢谢,我E文不是很好,看得不是很明白,能否说得直接些?
      

  7.   

    If ON DELETE CASCADE is specified,
     如果指定了 ON DELETE CASCADE, and a row in the parent table is deleted,
     当父表中的一个记录行被删除时
     
     then InnoDB automatically deletes also all those rows in the child table whose foreign key values are equal to the referenced key value in the parent row.
     InnoDB 将会自动地子表中外键值与父表中记录行中的引用键值相等的所有记录行
      

  8.   

    then InnoDB automatically deletes also all those rows in the child table whose foreign key values are equal to the referenced key value in the parent row.
     InnoDB 将会自动地删除子表中外键值与父表中记录行中的引用键值相等的所有记录行
    :)
    嘻嘻,不好意思少了一个词