简体   繁体   中英

SQL Insert from a source table to another table

Not sure how to google this... Here's what I need to do but I'm not sure how to do the insert and generate the NewID at the same time.

I have 2 tables one (pcx_candidate_to_pcx_vacancyId) is empty and only has 3 fields candidateid, vacancyId and its primary key, all 3 fields are guids. I need to get the data from a second table that has the matching fields but I also have to create and insert a guid at the same time. The source table (pcx_vacancyassociationExtensionBase) has 2 matching fields. Finally I will use NewID() to generate the new guid for the primary key.

You can insert directly from one table to another via an insert into ... select ... query:

insert into pcx_candidate_to_pcx_vacancyId (id, candidateid, vacancyId)
select NewID(), candidateid, vacancyId
from pcx_vacancyassociationExtensionBase

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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