[英]Create new records based on primary key of different table mysql
假設我有兩個表,分別稱為users
和user_profiles
user_profiles
為空,沒有任何行,而users
表中有大約10-20k條記錄。
我想根據users
主鍵為user_profiles
創建空記錄
出於疑問,
讓我們假設
我的users
表有
id
name
email
我的user_profiles
表有
id
user_id
data
是否可以通過SQL嚴格執行而不涉及任何服務器端腳本?
最終結果,無論我有多少用戶,都應該有與之匹配的user_profiles行。
如果您的表使用user_profiles
屬性的ALLOW NULL和auto_increment
進行了正確的構造,請嘗試以下操作。
INSERT INTO user_profiles (user_id)
SELECT id FROM users
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.