[英]How to fetch values from one table and insert the same values in other table
[英]How to insert default values from one table to other in mysql
我有3個表,一個命名employees
,一個Documents
和一個Doctemplates
employees
和documents
具有關系,並且doctemplates
包含多個document
名稱。
我需要的是當我在文檔下添加新employee
,系統在表格doctemplates
添加默認文檔模板,因此我不必一一鍵入。
有什么辦法做到這一點,在mysql查詢或php中?
INSERT INTO documents (employeeId, col1, col2, col3)
SELECT $employeeId, c1, c2, c3 FROM doctemplates;
您可以手動執行,也可以從觸發器執行。
更多信息: https : //dev.mysql.com/doc/refman/5.7/en/insert-select.html
您想從DOCTEMPLETS插入數據到文檔中。為此,當您從DOCTEMPLETS定義文檔表中的外鍵時,必須創建員工和DOCTEMPLETS之間的關系。 如果您想進一步了解外鍵定義,請詢問下一個。 ANS
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.