2013-04-27 100 views
1

我正在設計一個數據庫,並且需要一次將值插入到兩個表中的語句。我這樣做的問題是,其中一個表需要一個值,而另一個表是自動增加的。我怎樣才能做到這一點?我的主機不幸的是不支持使用外鍵。 (我正在使用mySQL)
我已經把表名和值放在下面。將MySQL INSERT語句放入兩個表中,使用另一箇中的AI值

Task 

+ id (auto incremented value) 
+ dataid (should have been foreign key to data.id- which will be auto incremented when +tatement is xecuted) 
+ priority (task priority 1-100) 
+ statusid (should have been foreign key to status.id - this value is given) 
+ toc (TimeOfCreation - timestamp, will be set automatically) 

Data 

+ id (auto incremented value) 
+ text (the text of the task/privatemsg/statusmsg etc.) 

你們中的一個或有人可以幫我做一個插入statment從而有可能爲我插入這個數據到這些表,其中data.id是自動遞增,並存儲在task.dataid?

text=fix login 
priority=99 
statusid=4 

請諮詢您是否有任何問題。
在此先感謝

Pyracell

回答

0

上第一臺的INSERT查詢後,就立即編寫從第一表中選擇MAX(data.id)查詢並插入該數值到task.dataid。

相關問題