Can we copy the records of one data extension into another data extension using ampscript/SSJS? If yes, kindly let me know the approach.


I would create one script to duplicate your data extension, you can use WSProxy to do this (Retrieve DE info call, Retrieve Fields call then Create DE call) and then create and perform query activities via SSJS to fill in the newly created data extension.

Simple example of the create then execute script for Query:

<script runat="server">
Platform.Load("Core","1.1") ;

var deName = {{yourTargetDEName}}

var queryName = {{yourQueryName}}

var queryDef = { Name : queryName,

CustomerKey : queryName,
TargetUpdateType : "Overwrite",
TargetType : "DE",

Name: deName,
CustomerKey : deName
QueryText : "SELECT {{myField}} FROM {{mySourceDE}}"

var status = QueryDefinition.Add(queryDef);

sleep(3000); //Wait for 3 seconds
//This helps ensure creation is complete before attempting to execute

var qd = QueryDefinition.Init("myQueryDef");
var status = qd.Perform();

function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
  • This is what i was looking for.
    – Ranjan
    Dec 13 '19 at 12:34

I would never use neither Ampscript nor SSJS to copy data across data extensions. Both from performance and from configuration perspective, Query Activities in Automation Studio are far superior.

The only case, where I use SSJS for updating data, is when I need to update a list (e.g. All Subscribers) based on data in a data extension.

  • I understand we can use the Query activity in automation studio. But as per our requirement, As a part of deployment process we need to create 5 new data extension and then move all the records to new data extension. Sometimes its a time consuming process. So thought like to leverage the SSJS functionality to perform this activity.
    – Ranjan
    Dec 12 '19 at 10:49
  • This is indeed a very broad question, a number of examples have been provided here: salesforce.stackexchange.com/questions/227239/… and salesforce.stackexchange.com/questions/279552/… Dec 12 '19 at 11:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.