现在我有两张表,例如:一张A表(int a,int b,date c) 另一张B表(int a,int b,int d,int e),现在我想插入A表(int a,int b,date c)的值是B表中查询出来的(int a,int b,当前时间),想写一个存储过程!insert A(a,b,c) select a,b from B;但是data不知道插入!希望大家能给我写一个存储过程!!

解决方案 »

  1.   


    # mysql> select current_timestamp();  
    # +---------------------+  
    # | current_timestamp() |  
    # +---------------------+  
    # | 2010-01-18 21:24:37 |  
    # +---------------------+  
    # 1 row in set (0.00 sec)  
    #  
    # mysql> select current_date();  
    # +----------------+  
    # | current_date() |  
    # +----------------+  
    # | 2010-01-18     |  
    # +----------------+  
    # 1 row in set (0.00 sec)  
    #  
    # mysql> select current_time();  
    # +----------------+  
    # | current_time() |  
    # +----------------+  
    # | 21:24:46       |  
    # +----------------+  
    # 1 row in set (0.00 sec)mysql常见的时间函数就上面3个,你可以选择一个合适的。
      

  2.   

    insert A(a,b,c) select a,b,current_timestamp() from B
      

  3.   

    date c 只是其中一个字段,还有其它很多字段是B表中没有的!我也想将其它字段插入进去!在线等……求大神帮下忙!我看了用游标,但是速度有点慢……
      

  4.   

    insert A(a,b,c,new1,new2,new3) select a,b,current_timestamp(),其它字段1,其它字段2,其它字段3 from B要插入的其他字段同理,如果是固定值,直接写即可
      

  5.   

    这里是sql server版,mysql<>sql server