简体   繁体   English

如何在使用内部联接合并两个表时将列设置为PRIMARY KEY(两个联接表中没有主键)

[英]How to set a column to PRIMARY KEY while merging two tables using inner join?(there is no primary key in the two joining tables)

How to set a column to PRIMARY KEY while merging two tables using inner join ?( there is no primary key in the two joining tables ) please help. 如何在使用内部 PRIMARY KEY合并两个表的同时将列设置为PRIMARY KEY两个联接表中没有主键 )请提供帮助。

create table merge_aws AS
select aws.id,aws.date,aws.time,aws.pmer,aws.dd,aws.ff,aws.t,masterfile.station,masterfile.latitude,masterfile.longitude
from aws
inner join masterfile
on aws.id=masterfile.call_sign;

Use alter table after creation like this sample: 像这样的示例在创建后使用alter table:

CREATE TABLE merge_aws AS select 
    aws.id,
    aws.date,
    aws.time,
    aws.pmer,
    aws.dd,
    aws.ff,
    aws.t,
    masterfile.station,
    masterfile.latitude,
    masterfile.longitude
from
    aws
        inner join
    masterfile ON aws.id = masterfile.call_sign;

ALTER TABLE merge_aws ADD COLUMN prim INT NOT NULL AUTO_INCREMENT , ADD PRIMARY KEY (prim) ;

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM