none
如何在database 检查多个Tool_Name RRS feed

  • 问题

  • 我想篇写在database 检查多个Tool_Name 是否存在,如果该Tool_Name 不存在的话,就将不存在Tool_Name insert into 进 database 里。

    database 叫 A

    Tool_Name 有 A1,B1,C1

    如果检查到database A 没有 C2 的Tool_Name 就将 C2 Tool_Name  insert 进 database A 里

    请求指点 感恩



    2022年3月25日 5:49

全部回复

  • 你好 christing:

    我看你之前使用的是mysql数据库。那我就假设你是Mysql。

    以下是MYSQL INSERT 插入条件判断:如果不存在则插入

    INSERT INTO table(field1, field2, fieldn)
    
    SELECT 'field1', 'field2', 'fieldn'
    
    FROM DUAL
    
    WHERE NOT EXISTS(SELECT field FROM table WHERE field = ?)

    例如:

    Insert into A (Tool_Name)
    
    Select ’C2‘ as TooL_Name
    
    From Dual
    
    Where Not EXists(
    
    Select *
    
    From A
    
    Where Tool_Name = 'C2'
    
    )

    Best Regards,

    Jiale



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2022年3月25日 9:18