First, the program will create a new table copy frame to set up for the prototype.A pane is then added to the frame with the mock up
 image and button for users to press.
 When the 
"Copy Table" button is pressed, it will generate a pop up menu with preinitialized test
 log in information so that all the user has to enter are the table names that they woud want copied.
 When the information is entered it
 will take in the entered text as variables storing everything except the passwords as strings, and storing the passwords as char arrays.
 Due to the use
 of linked servers in sql server management studio, the source username and passwords are not required, just the name
 of the linked server. The table field will be stored as a string and
 then turned into an array of strings seperating where the user 
 entered a comma. The table names now stored in a string array will be trimmed to remove any trailing white space after 
checking for an
 empty table field. The table array is iterated through and copied one at a time by a for loop that runs through the sql scripts. The
 variables recieved from the text 
fields are used to parameterize sqlcmd calls. The calls are made from the Java Runtime class and 
 stored in a process to read the logs from. If the process causes sqlcmd to output a 
message( which would only happen in this case if an 
 error had occured, denoted by the Msg keyword), the process is stopped and the prototype is returned to the state before clicking 
the
 "Copy Table" button. Errors are checked for in every call to sqlcmd. If there are no errors the user is notified that the copy of that
 table has successfully been copied from the 
source server to the destination server. If there are multiple tables it will start the for
 loop again, if there is not then the user is notified that all their tables have been 
sucessfully copied.


Here are the sql scripts for table copy:

 Inserting a column in a management table for new entry:
    
     $tb = Table name

     INSERT INTO [MANAGEMENT].[dbo].[Management_table] (ReqID,DatabaseName, Table_Name, dateandtime) 
     VALUES ((SELECT (max(ReqID)+1) from [MANAGEMENT].[dbo].[Management_table]),'vinci100295', '$(tb)', CURRENT_TIMESTAMP );

 Number of rows before copy:
    
    $ip: Server name
    $tb: Table name

  update [MANAGEMENT].[dbo].[Management_table] set rowcount_before_copy= (select count(*) from [$(ip)].[vinci100295].[dbo].[$(tb)]) 
 where ReqID = (select MAX(ReqID) from [MANAGEMENT].[dbo].[Management_table])


 Number of rows after copy:
    
     $tb = Table name

     update [MANAGEMENT].[dbo].[Management_table] set rowcount_after_copy= (select count(*) from [vinci100295].[dbo].[$(tb)]) 
     where ReqID = (select MAX(ReqID) from [MANAGEMENT].[dbo].[Management_table])

 Checksum Before copy:
    
    $tb = Table name

   update Management_table set checksum_before_copy = (select  SUM( CAST( checksum(*) AS BIGINT )) from [$(ip)].[vinci100295].[dbo].[$(tb)]) 
   where ReqID = (select MAX(ReqID) from [MANAGEMENT].[dbo].[Management_table])

 Checksum after copy:
    
     $tb = Table name

    update Management_table set checksum_after_copy = (select  SUM( CAST( checksum(*) AS BIGINT )) from [vinci100295].[dbo].[$(tb)])
    where ReqID = (select MAX(ReqID) from [MANAGEMENT].[dbo].[Management_table])


 Status before copy if process completed:
    
   update [MANAGEMENT].[dbo].[Management_table] set status_before_copy = 'Completed' 
   where ReqID = (select MAX(ReqID) from [MANAGEMENT].[dbo].[Management_table])

 Status before copy if process failed:
 
     update [MANAGEMENT].[dbo].[Management_table] SET status_before_copy = 'Copy Failed'
     WHERE ReqID = (select MAX(ReqID) from [MANAGEMENT].[dbo].[Management_table])

 Table copy:
    $ip: Server Name
    $tb = Table name

    SELECT * INTO [vinci100295].[dbo].[$(tb)]
    FROM [$(ip)].[vinci100295].[dbo].[$(tb)]

 Status after copy  if process completed:
    
    update [MANAGEMENT].[dbo].[Management_table] set status_after_copy = 'Completed' 
    where ReqID = (select MAX(ReqID) from [MANAGEMENT].[dbo].[Management_table]);

 Status after copy  if process failed:
    
    update [MANAGEMENT].[dbo].[Management_table] SET status_after_copy = 'Copy Failed' 
    WHERE ReqID = (select MAX(ReqID) from [MANAGEMENT].[dbo].[Management_table])


 Copy Status to check copy successful or copy corrupted
    
  UPDATE [MANAGEMENT].[dbo].[Management_table] 
  SET CopyStatus =
      CASE
         (select checksum_before_copy - checksum_after_copy
            from [MANAGEMENT].[dbo].[Management_table]
             where ReqID = (select MAX(ReqID) from [MANAGEMENT].[dbo].[Management_table])
          )
              when 0 THEN 'Copy Successful'
               ELSE 'Copy Corrupted'
      END
      WHERE ReqID = (select MAX(ReqID) from [MANAGEMENT].[dbo].[Management_table])


 Drop table if table copy is corrupted:
    
     $tb = Table name

   IF EXISTS
      (SELECT Table_Name FROM [MANAGEMENT].[dbo].[Management_table] where CopyStatus = 'Copy Corrupted' and ReqID = (select max(ReqID) from  [MANAGEMENT].[dbo].[Management_table])) 
       drop table [vinci100295].[dbo].[$(tb)]


 Copy Status if copy successful
 
      update [MANAGEMENT].[dbo].[Management_table] set CopyStatus = 'Copy Successful' 
      where ReqID = (select MAX(ReqID) from [MANAGEMENT].[dbo].[Management_table])


