Add extra column of data when using LOAD DATA LOCAL INFILE

前端 未结 2 1931
自闭症患者
自闭症患者 2021-01-19 00:56

I\'m using the following LOAD DATA LOCAL INFILE query to read data from a file and insert it into a table. Everything works great as is. However I need to modify the query

相关标签:
2条回答
  • 2021-01-19 01:22

    You can add a SET clause to the end of the query, e.g.

    LOAD DATA LOCAL INFILE 'C:/mydata.csv' 
    INSERT INTO TABLE myTable
    FIELDS TERMINATED BY ',' 
    OPTIONALLY ENCLOSED BY '"' 
    LINES TERMINATED BY '\r\n' 
    IGNORE 1 LINES 
    (Column1,Column2,Column3,Column4)
    SET datetime = NOW();
    
    0 讨论(0)
  • 2021-01-19 01:27

    Rather than add this field to the query, it would be easier to add it to the table:

    ALTER TABLE myTable
        ADD COLUMN datetime_entered TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
    

    Any insertion will then automatically have a timestamp of when the record was entered.

    0 讨论(0)
提交回复
热议问题