fixed #4235 Copy table causes SQL error

Also fixed some coding styles

Signed-off-by: Viduranga Wijesooriya <vpowerrc@gmail.com>