This rhetorical question is used to rebuke David. This can be written as a statement. Alternate translation: "You should not have despised ... Yahweh and should not have done what is evil in his sight!" (See: [[rc://en/ta/man/translate/figs-rquestion]])
Here "sight" refers to Yahweh's thoughts or opinion. Alternate translation: "what he considers to be evil" or "what is evil in Yahweh's judgement" (See: [[rc://en/ta/man/translate/figs-metaphor]])
David did not kill Uriah himself, rather he arranged for him to be killed in battle. The phrase "with the sword" represents how Uriah died in battle. Alternate translation: "You have arranged for Uriah the Hittite to die in battle" (See: [[rc://en/ta/man/translate/figs-metonymy]])
David did not kill Uriah himself, rather he arranged for him to be killed in battle when Israel was fighting against Ammon. The phrase "with the sword" refers to how he died in battle. Alternate translation: "You arranged for him to die in battle against the army of Ammon" (See: [[rc://en/ta/man/translate/figs-metonymy]])