Updated table generation sql