在临时表创建中定义键

时间:2012-06-27 15:02:28

标签: mysql temp-tables

如何定义从SELECT语句创建的临时表的键?

我有:

CREATE temporary TABLE _temp_unique_parts_trading 
engine=memory AS 
  (SELECT parts_trading.enquiryref, 
          sellingcurrency, 
          jobs.id AS jobID 
   FROM   parts_trading, 
          jobs 
   WHERE  jobs.enquiryref = parts_trading.enquiryref 
   GROUP  BY parts_trading.enquiryref) 

但我在哪里定义键?

1 个答案:

答案 0 :(得分:7)

你可以这样做

CREATE temporary TABLE _temp_unique_parts_trading 
(
  enquiryref varchar(255),
  sellingcurrency varchar(255),
  jobID int(10),
  key(jobId)
)
engine=memory AS 
  (SELECT parts_trading.enquiryref, 
          sellingcurrency, 
          jobs.id AS jobID 
   FROM   parts_trading, 
          jobs 
   WHERE  jobs.enquiryref = parts_trading.enquiryref 
   GROUP  BY parts_trading.enquiryref) 

基本上在TABLE_NAME

之后附加表模式(索引,列数据类型)