Create MySQL column with string variable from anot

2019-09-15 19:28发布

What is a way that I could add a column to my table that would include the docID, plus a bunch of static information around it?

For example

docID    |    topic   | docURL
________________________________________________________
1        |   Floods   | http://site.com/downloaddoc.php?docID=1

2        |    Etc..   | http://site.com/downloaddoc.php?docID=2

I know it seems convoluted to do it this way, but we have to have this particular table downloadable into a CSV to import the data into other programs that use Excel as an input.

3条回答
地球回转人心会变
2楼-- · 2019-09-15 20:04

You could try this:

CREATE TRIGGER upd BEFORE INSERT ON table
FOR EACH ROW
BEGIN
 SET NEW.docURL = CONCAT('http://site.com/downloaddoc.php?docID=',NEW.docID);
END;
查看更多
欢心
3楼-- · 2019-09-15 20:05

After every INSERT you could make an

UPDATE table SET docURL = CONCAT('http://site.com/downloaddoc.php?docID=',docID)
查看更多
看我几分像从前
4楼-- · 2019-09-15 20:23

I'm not sure I have understood but I think you could use concat function in order to concatenate strings and then use a select into outfile to export into csv without changing your table structure.

查看更多
登录 后发表回答