I have a table in SQL server. I am trying to append a spark dataframe from databricks to the SQL table. I am able to append the new rows but the problem is that it appends randomly to the SQL table. I want to append the new rows to the end of the SQL table. How do I do that?
SQL table
╔═════════════════════════════╗
║ Name a b c d ║
╠═════════════════════════════╣
║1 Lisa 5 4 1 3 ║
║2 Timmy 3 2 7 2 ║
║3 Rann 2 3 1 5 ║
║4 Bob 1 6 3 4 ║
╚═════════════════════════════╝
Spark dataframe
╔═════════════════════════════╗
║ Name a b c d ║
╠═════════════════════════════╣
║1 Mark 10 3 2 4 ║
║2 Rudy 5 6 7 8 ║
╚═════════════════════════════╝
What I want
╔═════════════════════════════╗
║ Name a b c d ║
╠═════════════════════════════╣
║1 Lisa 5 4 1 3 ║
║2 Timmy 3 2 7 2 ║
║3 Rann 2 3 1 5 ║
║4 Bob 1 6 3 4 ║
║5 Mark 10 3 2 4 ║
║6 Rudy 5 6 7 8 ║
╚═════════════════════════════╝
When I append using this code
df.write.mode("append").jdbc(url=jdbcurl, table="employee")
I get this result in the SQL server. Mark and Rudy should be at the bottom but it appends randomly. Is there a parameter that I am suppose to add?
╔═════════════════════════════╗
║ Name a b c d ║
╠═════════════════════════════╣
║1 Lisa 5 4 1 3 ║
║2 Rudy 5 6 7 8 ║
║3 Timmy 3 2 7 2 ║
║4 Mark 10 3 2 4 ║
║5 Rann 2 3 1 5 ║
║6 Bob 1 6 3 4 ║
╚═════════════════════════════╝