简体   繁体   English

如何在MySQL中将默认值从一个表插入到另一个表

[英]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. employeesdocuments具有关系,并且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.

相关问题 如何从一个表中获取值并在另一表中插入相同的值 - How to fetch values from one table and insert the same values in other table 如何更新 MySQL 表,其值在一个插入语句中相互依赖 - How do I update a MySQL table with values dependent of each other in one Insert Statement 如何从两个表中插入一个表中的值等于另一个表中的值的值? - how to insert values from two tables with value in one table is equal to value in the other? 从一个表插入到另一个表(具有附加值)(MySQL) - Insert from one table into another (with extra values) (MySQL) PHP MySQL 将多个复选框中的值插入表中的一列 - PHP MySQL insert values from multiple checkboxes into one column in table 如何从一个表中选择ID并插入到另一个表中 - how to select id from one table and insert into other table 从一个表动态获取行并从其他表获取值将其汇总并插入到目标表中 - fetch rows dynamically from one table and get values from other table sum it up and insert into target table 如何从两个源表单和另一个表插入mysql数据 - How to insert mysql data from two source form and other table 如何从其他表插入外键约束的值? - how to insert values of foreign key constraint from other table? 从一个表中获取值,然后将其插入另一个表中。 如何? - Get value from one table, insert it in query of other. How to?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM