[英]How to insert default values from one table to other in mysql
I have 3 tables, one named employees
, one Documents
, and one Doctemplates
我有3个表,一个命名
employees
,一个Documents
和一个Doctemplates
employees
and documents
have relationship, and doctemplates
contain several document
names. employees
和documents
具有关系,并且doctemplates
包含多个document
名称。
What I need is when i add a new employee
, under documents, system add the defaults documents templates form table doctemplates
, so i don't have to type one by one. 我需要的是当我在文档下添加新
employee
,系统在表格doctemplates
添加默认文档模板,因此我不必一一键入。
Is there any way to do this, in a mysql query or php? 有什么办法做到这一点,在mysql查询或php中?
INSERT INTO documents (employeeId, col1, col2, col3)
SELECT $employeeId, c1, c2, c3 FROM doctemplates;
You can do it manually or from trigger. 您可以手动执行,也可以从触发器执行。
More info: https://dev.mysql.com/doc/refman/5.7/en/insert-select.html 更多信息: https : //dev.mysql.com/doc/refman/5.7/en/insert-select.html
WHAT YOU WANT IS TO INSERT DATA FROM DOCTEMPLETS TO DOCUMENTS.FOR THIS YOU HAVE TO CREATE A RELATION BETWEEN EMPLOYEE AND DOCTEMPLETS,THEN DEFINE A FOREIGN KEY IN DOCUMENTS TABLE FROM DOCTEMPLETS. 您想从DOCTEMPLETS插入数据到文档中。为此,当您从DOCTEMPLETS定义文档表中的外键时,必须创建员工和DOCTEMPLETS之间的关系。 IF YOU WANT MORE ABOUT FOREIGN KEY DEFINING.PLZ ASK NEXT.
如果您想进一步了解外键定义,请询问下一个。 THANS
ANS
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.